Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
ShapeRoot.ccGo to the documentation of this file.00001 #include "SketchSpace.h" 00002 #include "ShapeSpace.h" 00003 00004 #include "Macrodefs.h" 00005 00006 #include "ShapeTypes.h" 00007 #include "ShapeRoot.h" 00008 00009 #include "BaseData.h" 00010 00011 using namespace std; 00012 00013 namespace DualCoding { 00014 00015 ShapeRoot::ShapeRoot(BaseData *p) : id(p->getId()), data(p) { 00016 ++data->refcount; 00017 } 00018 00019 ShapeRoot::ShapeRoot(const ShapeRoot &other) 00020 : id(other.id), data(other.data) { 00021 if ( data != NULL ) 00022 ++data->refcount; 00023 }; 00024 00025 ShapeRoot& ShapeRoot::operator=(const ShapeRoot& src) { 00026 if ( data != NULL && --data->refcount == 0 && data != src.data ) 00027 delete data; 00028 id = src.id; 00029 data = src.data; 00030 if ( data != NULL ) 00031 ++data->refcount; 00032 return *this; 00033 } 00034 00035 ShapeRoot::~ShapeRoot(void) { 00036 if ( data != NULL && --data->refcount == 0 ) 00037 delete data; 00038 } 00039 00040 void ShapeRoot::deleteShape(void) { 00041 if ( isValid() ) 00042 data->space->deleteShape(*this); 00043 } 00044 00045 void ShapeRoot::sanity_check(void) const { 00046 if ( !isValid() ) { 00047 cerr << "ERROR: Reference to invalid shape at " << (const void*)this 00048 << " id=" << id << " data=" << (const void*)data; 00049 if ( data != NULL ) 00050 cout << " data->id=" << data->id; 00051 cout << endl; 00052 } 00053 } 00054 00055 BaseData* ShapeRoot::operator-> (void) { 00056 sanity_check(); 00057 return data; 00058 } 00059 00060 BaseData* ShapeRoot::operator-> (void) const { 00061 sanity_check(); 00062 return data; 00063 } 00064 00065 BaseData& ShapeRoot::getData() const { 00066 sanity_check(); 00067 return *data;; 00068 } 00069 00070 ShapeSpace& ShapeRoot::getSpace() const { 00071 sanity_check(); 00072 return *(data->space); 00073 } 00074 00075 bool ShapeRoot::operator==(const ShapeRoot& other) const { 00076 if ( isValid() ) 00077 if ( other.isValid() ) 00078 return id == other.id; 00079 else 00080 return false; 00081 else 00082 return !other.isValid(); 00083 } 00084 00085 std::ostream& operator<<(std::ostream &os, const ShapeRoot &r) { 00086 if ( r.isValid() ) { 00087 cout << r.data->getSpace().name << " " << "Shape<" << r->getTypeName() << ">(id=" 00088 << r.id << ", data=" << r.data << ")"; 00089 } 00090 else { 00091 cout << "Shape(id=" << r.getId() << ",data=" << reinterpret_cast<size_t>(r.data) << ")[invalid]"; 00092 } 00093 return os; 00094 } 00095 00096 } // namespace |
DualCoding 4.0 |
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4 |