GNU CommonC++
|
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // Copyright (C) 2006-2010 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 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++(); // prefix 00522 00528 MapIndex operator++(int) // postfix 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