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
00044 #ifndef COMMONCPP_OBJECT_H_
00045 #define COMMONCPP_OBJECT_H_
00046
00047 #ifndef COMMONCPP_CONFIG_H_
00048 #include <commoncpp/config.h>
00049 #endif
00050
00051 NAMESPACE_COMMONCPP
00052
00053 class MapObject;
00054 class MapIndex;
00055
00063 class __EXPORT RefObject
00064 {
00065 protected:
00066 friend class RefPointer;
00067
00068 unsigned refCount;
00069
00073 inline RefObject()
00074 {refCount = 0;};
00075
00080 virtual ~RefObject();
00081
00082 public:
00091 virtual void *getObject(void) = 0;
00092 };
00093
00102 class __EXPORT RefPointer
00103 {
00104 protected:
00105 RefObject *ref;
00106
00110 void detach(void);
00111
00116 virtual void enterLock(void);
00117
00122 virtual void leaveLock(void);
00123
00124 public:
00128 inline RefPointer()
00129 {ref = NULL;};
00130
00136 RefPointer(RefObject *obj);
00137
00143 RefPointer(const RefPointer &ptr);
00144
00145 virtual ~RefPointer();
00146
00147 RefPointer& operator=(const RefObject &ref);
00148
00149 inline void *operator*() const
00150 {return getObject();};
00151
00152 inline void *operator->() const
00153 {return getObject();};
00154
00155 void *getObject(void) const;
00156
00157 bool operator!() const;
00158 };
00159
00167 class __EXPORT LinkedSingle
00168 {
00169 protected:
00170 LinkedSingle *nextObject;
00171
00172 inline LinkedSingle()
00173 {nextObject = NULL;};
00174
00175 virtual ~LinkedSingle();
00176
00177 public:
00187 virtual LinkedSingle *getFirst(void);
00188
00196 virtual LinkedSingle *getLast(void);
00197
00204 inline LinkedSingle *getNext(void)
00205 {return nextObject;};
00206
00214 virtual void insert(LinkedSingle& obj);
00215
00216 LinkedSingle &operator+=(LinkedSingle &obj);
00217 };
00218
00226 class __EXPORT LinkedDouble
00227 {
00228 protected:
00229 LinkedDouble *nextObject, *prevObject;
00230
00231 inline LinkedDouble()
00232 {nextObject = prevObject = NULL;};
00233
00234 virtual ~LinkedDouble();
00235
00236 virtual void enterLock(void);
00237
00238 virtual void leaveLock(void);
00239
00240 virtual LinkedDouble *firstObject();
00241
00242 virtual LinkedDouble *lastObject();
00243
00244 public:
00245
00250 enum InsertMode
00251 {
00252 modeAtFirst,
00253 modeAtLast,
00254 modeBefore,
00255 modeAfter
00256 };
00257
00265 virtual LinkedDouble *getFirst(void);
00266
00274 virtual LinkedDouble *getLast(void);
00275
00283 virtual LinkedDouble *getInsert(void);
00284
00291 inline LinkedDouble *getNext(void)
00292 {return nextObject;};
00293
00299 inline LinkedDouble *getPrev(void)
00300 {return prevObject;};
00301
00310 virtual void insert(LinkedDouble& obj, InsertMode position = modeAtLast);
00311
00315 virtual void detach(void);
00316
00317 LinkedDouble &operator+=(LinkedDouble &obj);
00318
00319 LinkedDouble &operator--();
00320 };
00321
00332 class __EXPORT MapTable : public Mutex
00333 {
00334 protected:
00335 friend class MapObject;
00336 friend class MapIndex;
00337 unsigned range;
00338 unsigned count;
00339 MapObject **map;
00340
00341 void cleanup(void);
00342
00343 public:
00349 MapTable(unsigned size);
00350
00354 virtual ~MapTable();
00355
00364 virtual unsigned getIndex(const char *id);
00365
00371 inline unsigned getRange(void)
00372 {return range;};
00373
00379 inline unsigned getSize(void)
00380 {return count;};
00381
00389 void *getObject(const char *id);
00390
00397 void addObject(MapObject &obj);
00404 void *getFirst();
00405
00412 void *getLast();
00413
00420 void *getEnd()
00421 { return NULL; };
00422
00432 void *getFree(void);
00433
00440 void addFree(MapObject *obj);
00441
00448 MapTable &operator+=(MapObject &obj);
00449
00457 virtual MapTable &operator-=(MapObject &obj);
00458 };
00459
00469 class __EXPORT MapIndex
00470 {
00471 MapObject* thisObject;
00472
00473 public :
00474
00478 MapIndex() : thisObject(NULL)
00479 {};
00480
00486 MapIndex(MapObject* theObject) : thisObject(theObject)
00487 {};
00488
00494 MapIndex(const MapIndex& theIndex) : thisObject(theIndex.thisObject)
00495 {};
00496
00503 void* operator*() const
00504 { return (void*)thisObject; }
00505
00511 MapIndex& operator=(MapObject *theObject);
00512
00518 MapIndex& operator++();
00519
00525 MapIndex operator++(int)
00526 { return this->operator++(); }
00527
00533 bool operator==(const MapIndex& theIndex) const
00534 { return thisObject == theIndex.thisObject; };
00535
00536 bool operator!=(const MapIndex& theIndex) const
00537 { return !(*this == theIndex); };
00538
00545 bool operator==(const MapObject* theObject) const
00546 { return thisObject == theObject; };
00547
00548 bool operator!=(const MapObject* theObject) const
00549 { return !(*this == theObject); };
00550 };
00551
00560 class __EXPORT MapObject
00561 {
00562 protected:
00563 friend class MapTable;
00564 friend class MapIndex;
00565 MapObject *nextObject;
00566 const char *idObject;
00567 MapTable *table;
00568
00569 public:
00570
00574 void detach(void);
00575
00581 MapObject(const char *id);
00582 };
00583
00584 END_NAMESPACE
00585
00586 #endif