00001
00002 #ifndef _SHAPEROOT_H_
00003 #define _SHAPEROOT_H_
00004
00005 #include <vector>
00006
00007 #include "ShapeSpace.h"
00008 #include "ShapeTypes.h"
00009 #include "BaseData.h"
00010
00011 namespace DualCoding {
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class ShapeRoot {
00027 protected:
00028 int id;
00029 BaseData *data;
00030
00031 friend class ShapeSpace;
00032 friend std::ostream& operator<<(std::ostream &os, const ShapeRoot &r);
00033
00034 public:
00035
00036
00037 ShapeRoot(void): id(-1), data(NULL) {};
00038
00039
00040 ShapeRoot(BaseData *p);
00041
00042
00043 ShapeRoot(const ShapeRoot &other);
00044
00045 virtual ~ShapeRoot(void);
00046
00047 void deleteShape(void);
00048
00049 void sanity_check(void) const;
00050
00051 inline bool isValid() const {
00052 return data != NULL && id > 0 && id == data->id;
00053 }
00054
00055 void setInvalid() {
00056 if ( id > 0 )
00057 id = -id;
00058 }
00059
00060
00061 virtual BaseData* operator-> (void);
00062 virtual BaseData* operator-> (void) const;
00063
00064 int getId() const { return id; }
00065 virtual BaseData& getData() const;
00066 ShapeSpace& getSpace() const;
00067
00068
00069
00070 virtual bool operator==(const ShapeRoot& other) const;
00071
00072 virtual bool operator!=(const ShapeRoot& other) const {
00073 return ! operator==(other);
00074 }
00075
00076
00077 ShapeRoot& operator=(const ShapeRoot&);
00078
00079 protected:
00080 ShapeRoot& addShape(BaseData *p) { return p->space->addShape(p); }
00081
00082 };
00083
00084 std::ostream& operator<<(std::ostream &os, const ShapeRoot &r);
00085
00086
00087
00088
00089 #define ShapeRootTypeConst(_arg,_type) (*reinterpret_cast<const Shape<_type>*>(&_arg))
00090 #define ShapeRootType(_arg,_type) (*reinterpret_cast<Shape<_type>*>(&_arg))
00091
00092 #define SHAPESTUFF_H(T) \
00093 Shape<T>() : ShapeRoot() {} \
00094 Shape<T>(T* newdata) : ShapeRoot(addShape(newdata)) {} \
00095 virtual T* operator->(); \
00096 virtual T* operator->() const; \
00097 virtual T& getData() const;
00098
00099 #define SHAPESTUFF_CC(T) \
00100 T* Shape<T>::operator->() { sanity_check(); return static_cast<T*>(data); }; \
00101 T* Shape<T>::operator->() const { sanity_check(); return static_cast<T*>(data); }; \
00102 T& Shape<T>::getData() const { return *static_cast<T*>(data); };
00103
00104 }
00105
00106 #endif