00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // Copyright (C) 2006-2008 David Sugar, Tycho Softworks. 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free software 00019 // library without restriction. Specifically, if other files instantiate 00020 // templates or use macros or inline functions from this file, or you compile 00021 // this file and link it with other files to produce an executable, this 00022 // file does not by itself cause the resulting executable to be covered by 00023 // the GNU General Public License. This exception does not however 00024 // invalidate any other reasons why the executable file might be covered by 00025 // the GNU General Public License. 00026 // 00027 // This exception applies only to the code released under the name GNU 00028 // Common C++. If you copy code from other releases into a copy of GNU 00029 // Common C++, as the General Public License permits, the exception does 00030 // not apply to the code that you add in this way. To avoid misleading 00031 // anyone as to the status of such modified files, you must delete 00032 // this exception notice from them. 00033 // 00034 // If you write modifications of your own for GNU Common C++, it is your choice 00035 // whether to permit this exception to apply to your modifications. 00036 // If you do not wish that, delete this exception notice. 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++(); // prefix 00518 00524 MapIndex operator++(int) // postfix 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