| Homepage | Demos | Overview | Downloads | Tutorials | 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 namespace DualCoding { 00012 00013 ShapeRoot::ShapeRoot(BaseData *p) : id(p->getId()), data(p) { 00014 ++data->refcount; 00015 } 00016 00017 ShapeRoot::ShapeRoot(const ShapeRoot &other) 00018 : id(other.id), data(other.data) { 00019 if ( data != NULL ) 00020 ++data->refcount; 00021 }; 00022 00023 ShapeRoot& ShapeRoot::operator=(const ShapeRoot& src) { 00024 if ( data != NULL && --data->refcount == 0 && data != src.data ) 00025 delete data; 00026 id = src.id; 00027 data = src.data; 00028 if ( data != NULL ) 00029 ++data->refcount; 00030 return *this; 00031 } 00032 00033 ShapeRoot::~ShapeRoot(void) { 00034 if ( data != NULL && --data->refcount == 0 ) 00035 delete data; 00036 } 00037 00038 void ShapeRoot::deleteShape(void) { 00039 if ( isValid() ) 00040 data->space->deleteShape(*this); 00041 } 00042 00043 void ShapeRoot::sanity_check(void) const { 00044 if ( !isValid() ) { 00045 cerr << "ERROR: Reference to invalid shape at " << (const void*)this 00046 << " id=" << id << " data=" << (const void*)data; 00047 if ( data != NULL ) 00048 cout << " data->id=" << data->id; 00049 cout << endl; 00050 } 00051 } 00052 00053 BaseData* ShapeRoot::operator-> (void) { 00054 sanity_check(); 00055 return data; 00056 } 00057 00058 BaseData* ShapeRoot::operator-> (void) const { 00059 sanity_check(); 00060 return data; 00061 } 00062 00063 BaseData& ShapeRoot::getData() const { 00064 sanity_check(); 00065 return *data;; 00066 } 00067 00068 ShapeSpace& ShapeRoot::getSpace() const { 00069 sanity_check(); 00070 return *(data->space); 00071 } 00072 00073 bool ShapeRoot::operator==(const ShapeRoot& other) const { 00074 if ( isValid() ) 00075 if ( other.isValid() ) 00076 return id == other.id; 00077 else 00078 return false; 00079 else 00080 return !other.isValid(); 00081 } 00082 00083 std::ostream& operator<<(std::ostream &os, const ShapeRoot &r) { 00084 if ( r.isValid() ) { 00085 cout << r.data->getSpace().name << " " << "Shape<" << r->getTypeName() << ">(id=" 00086 << r.id << ", data=" << r.data << ")"; 00087 } 00088 else { 00089 cout << "Shape(id=" << r.getId() << ",data=" << (unsigned int)r.data << ")[invalid]"; 00090 } 00091 return os; 00092 } 00093 00094 } // namespace |
|
DualCoding 3.0beta |
Generated Wed Oct 4 00:01:54 2006 by Doxygen 1.4.7 |