00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the GNU General Public License. 00025 // 00026 // This exception applies only to the code released under the name GNU 00027 // Common C++. If you copy code from other releases into a copy of GNU 00028 // Common C++, as the General Public License permits, the exception does 00029 // not apply to the code that you add in this way. To avoid misleading 00030 // anyone as to the status of such modified files, you must delete 00031 // this exception notice from them. 00032 // 00033 // If you write modifications of your own for GNU Common C++, it is your choice 00034 // whether to permit this exception to apply to your modifications. 00035 // If you do not wish that, delete this exception notice. 00036 // 00037 00044 #ifndef CCXX_OBJECT_H_ 00045 #define CCXX_OBJECT_H_ 00046 00047 #ifndef CCXX_MISSING_H_ 00048 #include <cc++/missing.h> 00049 #endif 00050 00051 #ifdef CCXX_NAMESPACES 00052 namespace ost { 00053 #endif 00054 00055 class __EXPORT MapObject; 00056 class __EXPORT MapIndex; 00057 00065 class __EXPORT RefObject 00066 { 00067 protected: 00068 friend class RefPointer; 00069 00070 unsigned refCount; 00071 00075 inline RefObject() 00076 {refCount = 0;}; 00077 00082 virtual ~RefObject(); 00083 00084 public: 00093 virtual void *getObject(void) = 0; 00094 }; 00095 00104 class __EXPORT RefPointer 00105 { 00106 protected: 00107 RefObject *ref; 00108 00112 void detach(void); 00113 00118 virtual void enterLock(void); 00119 00124 virtual void leaveLock(void); 00125 00126 public: 00130 inline RefPointer() 00131 {ref = NULL;}; 00132 00138 RefPointer(RefObject *obj); 00139 00145 RefPointer(const RefPointer &ptr); 00146 00147 virtual ~RefPointer(); 00148 00149 RefPointer& operator=(const RefObject &ref); 00150 00151 inline void *operator*() const 00152 {return getObject();}; 00153 00154 inline void *operator->() const 00155 {return getObject();}; 00156 00157 void *getObject(void) const; 00158 00159 bool operator!() const; 00160 }; 00161 00169 class __EXPORT LinkedSingle 00170 { 00171 protected: 00172 LinkedSingle *nextObject; 00173 00174 inline LinkedSingle() 00175 {nextObject = NULL;}; 00176 00177 virtual ~LinkedSingle(); 00178 00179 public: 00189 virtual LinkedSingle *getFirst(void); 00190 00198 virtual LinkedSingle *getLast(void); 00199 00206 inline LinkedSingle *getNext(void) 00207 {return nextObject;}; 00208 00216 virtual void insert(LinkedSingle& obj); 00217 00218 LinkedSingle &operator+=(LinkedSingle &obj); 00219 }; 00220 00228 class __EXPORT LinkedDouble 00229 { 00230 protected: 00231 LinkedDouble *nextObject, *prevObject; 00232 00233 inline LinkedDouble() 00234 {nextObject = prevObject = NULL;}; 00235 00236 virtual ~LinkedDouble(); 00237 00238 virtual void enterLock(void); 00239 00240 virtual void leaveLock(void); 00241 00242 public: 00243 00248 enum InsertMode 00249 { 00250 modeAtFirst, 00251 modeAtLast, 00252 modeBefore, 00253 modeAfter 00254 }; 00255 00263 virtual LinkedDouble *getFirst(void); 00264 00272 virtual LinkedDouble *getLast(void); 00273 00281 virtual LinkedDouble *getInsert(void); 00282 00289 inline LinkedDouble *getNext(void) 00290 {return nextObject;}; 00291 00297 inline LinkedDouble *getPrev(void) 00298 {return prevObject;}; 00299 00308 virtual void insert(LinkedDouble& obj, InsertMode position = modeAtLast); 00309 00313 virtual void detach(void); 00314 00315 LinkedDouble &operator+=(LinkedDouble &obj); 00316 00317 LinkedDouble &operator--(); 00318 }; 00319 00330 class __EXPORT MapTable : public Mutex 00331 { 00332 protected: 00333 friend class MapObject; 00334 friend class MapIndex; 00335 unsigned range; 00336 unsigned count; 00337 MapObject **map; 00338 00339 void cleanup(void); 00340 00341 public: 00347 MapTable(unsigned size); 00348 00352 virtual ~MapTable(); 00353 00362 virtual unsigned getIndex(const char *id); 00363 00369 inline unsigned getRange(void) 00370 {return range;}; 00371 00377 inline unsigned getSize(void) 00378 {return count;}; 00379 00387 void *getObject(const char *id); 00388 00395 void addObject(MapObject &obj); 00402 void *getFirst(); 00403 00410 void *getLast(); 00411 00418 void *getEnd() 00419 { return NULL; }; 00420 00430 void *getFree(void); 00431 00438 void addFree(MapObject *obj); 00439 00446 MapTable &operator+=(MapObject &obj); 00447 00455 virtual MapTable &operator-=(MapObject &obj); 00456 }; 00457 00467 class __EXPORT MapIndex 00468 { 00469 MapObject* thisObject; 00470 00471 public : 00472 00476 MapIndex() : thisObject(NULL) 00477 {}; 00478 00484 MapIndex(MapObject* theObject) : thisObject(theObject) 00485 {}; 00486 00492 MapIndex(const MapIndex& theIndex) : thisObject(theIndex.thisObject) 00493 {}; 00494 00501 void* operator*() const 00502 { return (void*)thisObject; } 00503 00509 MapIndex& operator=(MapObject *theObject); 00510 00516 MapIndex& operator++(); // prefix 00517 00523 MapIndex operator++(int) // postfix 00524 { return this->operator++(); } 00525 00531 bool operator==(const MapIndex& theIndex) const 00532 { return thisObject == theIndex.thisObject; }; 00533 00534 bool operator!=(const MapIndex& theIndex) const 00535 { return !(*this == theIndex); }; 00536 00543 bool operator==(const MapObject* theObject) const 00544 { return thisObject == theObject; }; 00545 00546 bool operator!=(const MapObject* theObject) const 00547 { return !(*this == theObject); }; 00548 }; 00549 00558 class __EXPORT MapObject 00559 { 00560 protected: 00561 friend class MapTable; 00562 friend class MapIndex; 00563 MapObject *nextObject; 00564 const char *idObject; 00565 MapTable *table; 00566 00567 public: 00568 00572 void detach(void); 00573 00579 MapObject(const char *id); 00580 }; 00581 00582 #ifdef CCXX_NAMESPACES 00583 } 00584 #endif 00585 00586 #endif 00587