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 virtual LinkedDouble *firstObject();
00244
00245 virtual LinkedDouble *lastObject();
00246
00247 public:
00248
00253 enum InsertMode
00254 {
00255 modeAtFirst,
00256 modeAtLast,
00257 modeBefore,
00258 modeAfter
00259 };
00260
00268 virtual LinkedDouble *getFirst(void);
00269
00277 virtual LinkedDouble *getLast(void);
00278
00286 virtual LinkedDouble *getInsert(void);
00287
00294 inline LinkedDouble *getNext(void)
00295 {return nextObject;};
00296
00302 inline LinkedDouble *getPrev(void)
00303 {return prevObject;};
00304
00313 virtual void insert(LinkedDouble& obj, InsertMode position = modeAtLast);
00314
00318 virtual void detach(void);
00319
00320 LinkedDouble &operator+=(LinkedDouble &obj);
00321
00322 LinkedDouble &operator--();
00323 };
00324
00335 class __EXPORT MapTable : public Mutex
00336 {
00337 protected:
00338 friend class MapObject;
00339 friend class MapIndex;
00340 unsigned range;
00341 unsigned count;
00342 MapObject **map;
00343
00344 void cleanup(void);
00345
00346 public:
00352 MapTable(unsigned size);
00353
00357 virtual ~MapTable();
00358
00367 virtual unsigned getIndex(const char *id);
00368
00374 inline unsigned getRange(void)
00375 {return range;};
00376
00382 inline unsigned getSize(void)
00383 {return count;};
00384
00392 void *getObject(const char *id);
00393
00400 void addObject(MapObject &obj);
00407 void *getFirst();
00408
00415 void *getLast();
00416
00423 void *getEnd()
00424 { return NULL; };
00425
00435 void *getFree(void);
00436
00443 void addFree(MapObject *obj);
00444
00451 MapTable &operator+=(MapObject &obj);
00452
00460 virtual MapTable &operator-=(MapObject &obj);
00461 };
00462
00472 class __EXPORT MapIndex
00473 {
00474 MapObject* thisObject;
00475
00476 public :
00477
00481 MapIndex() : thisObject(NULL)
00482 {};
00483
00489 MapIndex(MapObject* theObject) : thisObject(theObject)
00490 {};
00491
00497 MapIndex(const MapIndex& theIndex) : thisObject(theIndex.thisObject)
00498 {};
00499
00506 void* operator*() const
00507 { return (void*)thisObject; }
00508
00514 MapIndex& operator=(MapObject *theObject);
00515
00521 MapIndex& operator++();
00522
00528 MapIndex operator++(int)
00529 { return this->operator++(); }
00530
00536 bool operator==(const MapIndex& theIndex) const
00537 { return thisObject == theIndex.thisObject; };
00538
00539 bool operator!=(const MapIndex& theIndex) const
00540 { return !(*this == theIndex); };
00541
00548 bool operator==(const MapObject* theObject) const
00549 { return thisObject == theObject; };
00550
00551 bool operator!=(const MapObject* theObject) const
00552 { return !(*this == theObject); };
00553 };
00554
00563 class __EXPORT MapObject
00564 {
00565 protected:
00566 friend class MapTable;
00567 friend class MapIndex;
00568 MapObject *nextObject;
00569 const char *idObject;
00570 MapTable *table;
00571
00572 public:
00573
00577 void detach(void);
00578
00584 MapObject(const char *id);
00585 };
00586
00587 #ifdef CCXX_NAMESPACES
00588 }
00589 #endif
00590
00591 #endif
00592