00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00045 #ifndef CCXX_OBJECT_H_
00046 #define CCXX_OBJECT_H_
00047
00048 #ifndef CCXX_MISSING_H_
00049 #include <cc++/missing.h>
00050 #endif
00051
00052 #ifdef CCXX_NAMESPACES
00053 namespace ost {
00054 #endif
00055
00056 class __EXPORT MapObject;
00057 class __EXPORT MapIndex;
00058
00066 class __EXPORT RefObject
00067 {
00068 protected:
00069 friend class RefPointer;
00070
00071 unsigned refCount;
00072
00076 inline RefObject()
00077 {refCount = 0;};
00078
00083 virtual ~RefObject();
00084
00085 public:
00094 virtual void *getObject(void) = 0;
00095 };
00096
00105 class __EXPORT RefPointer
00106 {
00107 protected:
00108 RefObject *ref;
00109
00113 void detach(void);
00114
00119 virtual void enterLock(void);
00120
00125 virtual void leaveLock(void);
00126
00127 public:
00131 inline RefPointer()
00132 {ref = NULL;};
00133
00139 RefPointer(RefObject *obj);
00140
00146 RefPointer(const RefPointer &ptr);
00147
00148 virtual ~RefPointer();
00149
00150 RefPointer& operator=(const RefObject &ref);
00151
00152 inline void *operator*() const
00153 {return getObject();};
00154
00155 inline void *operator->() const
00156 {return getObject();};
00157
00158 void *getObject(void) const;
00159
00160 bool operator!() const;
00161 };
00162
00170 class __EXPORT LinkedSingle
00171 {
00172 protected:
00173 LinkedSingle *nextObject;
00174
00175 inline LinkedSingle()
00176 {nextObject = NULL;};
00177
00178 virtual ~LinkedSingle();
00179
00180 public:
00190 virtual LinkedSingle *getFirst(void);
00191
00199 virtual LinkedSingle *getLast(void);
00200
00207 inline LinkedSingle *getNext(void)
00208 {return nextObject;};
00209
00217 virtual void insert(LinkedSingle& obj);
00218
00219 LinkedSingle &operator+=(LinkedSingle &obj);
00220 };
00221
00229 class __EXPORT LinkedDouble
00230 {
00231 protected:
00232 LinkedDouble *nextObject, *prevObject;
00233
00234 inline LinkedDouble()
00235 {nextObject = prevObject = NULL;};
00236
00237 virtual ~LinkedDouble();
00238
00239 virtual void enterLock(void);
00240
00241 virtual void leaveLock(void);
00242
00243 public:
00244
00249 enum InsertMode
00250 {
00251 modeAtFirst,
00252 modeAtLast,
00253 modeBefore,
00254 modeAfter
00255 };
00256
00264 virtual LinkedDouble *getFirst(void);
00265
00273 virtual LinkedDouble *getLast(void);
00274
00282 virtual LinkedDouble *getInsert(void);
00283
00290 inline LinkedDouble *getNext(void)
00291 {return nextObject;};
00292
00298 inline LinkedDouble *getPrev(void)
00299 {return prevObject;};
00300
00309 virtual void insert(LinkedDouble& obj, InsertMode position = modeAtLast);
00310
00314 virtual void detach(void);
00315
00316 LinkedDouble &operator+=(LinkedDouble &obj);
00317
00318 LinkedDouble &operator--();
00319 };
00320
00331 class __EXPORT MapTable : public Mutex
00332 {
00333 protected:
00334 friend class MapObject;
00335 friend class MapIndex;
00336 unsigned range;
00337 unsigned count;
00338 MapObject **map;
00339
00340 void cleanup(void);
00341
00342 public:
00348 MapTable(unsigned size);
00349
00353 virtual ~MapTable();
00354
00363 virtual unsigned getIndex(const char *id);
00364
00370 inline unsigned getRange(void)
00371 {return range;};
00372
00378 inline unsigned getSize(void)
00379 {return count;};
00380
00388 void *getObject(const char *id);
00389
00396 void addObject(MapObject &obj);
00403 void *getFirst();
00404
00411 void *getLast();
00412
00419 void *getEnd()
00420 { return NULL; };
00421
00431 void *getFree(void);
00432
00439 void addFree(MapObject *obj);
00440
00447 MapTable &operator+=(MapObject &obj);
00448
00456 virtual MapTable &operator-=(MapObject &obj);
00457 };
00458
00468 class __EXPORT MapIndex
00469 {
00470 MapObject* thisObject;
00471
00472 public :
00473
00477 MapIndex() : thisObject(NULL)
00478 {};
00479
00485 MapIndex(MapObject* theObject) : thisObject(theObject)
00486 {};
00487
00493 MapIndex(const MapIndex& theIndex) : thisObject(theIndex.thisObject)
00494 {};
00495
00502 void* operator*() const
00503 { return (void*)thisObject; }
00504
00510 MapIndex& operator=(MapObject *theObject);
00511
00517 MapIndex& operator++();
00518
00524 MapIndex operator++(int)
00525 { return this->operator++(); }
00526
00532 bool operator==(const MapIndex& theIndex) const
00533 { return thisObject == theIndex.thisObject; };
00534
00535 bool operator!=(const MapIndex& theIndex) const
00536 { return !(*this == theIndex); };
00537
00544 bool operator==(const MapObject* theObject) const
00545 { return thisObject == theObject; };
00546
00547 bool operator!=(const MapObject* theObject) const
00548 { return !(*this == theObject); };
00549 };
00550
00559 class __EXPORT MapObject
00560 {
00561 protected:
00562 friend class MapTable;
00563 friend class MapIndex;
00564 MapObject *nextObject;
00565 const char *idObject;
00566 MapTable *table;
00567
00568 public:
00569
00573 void detach(void);
00574
00580 MapObject(const char *id);
00581 };
00582
00583 #ifdef CCXX_NAMESPACES
00584 }
00585 #endif
00586
00587 #endif
00588