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 00064 class __EXPORT RefObject 00065 { 00066 protected: 00067 friend class RefPointer; 00068 00069 unsigned refCount; 00070 00074 inline RefObject() 00075 {refCount = 0;}; 00076 00081 virtual ~RefObject(); 00082 00083 public: 00092 virtual void *getObject(void) = 0; 00093 }; 00094 00103 class __EXPORT RefPointer 00104 { 00105 protected: 00106 RefObject *ref; 00107 00111 void detach(void); 00112 00117 virtual void enterLock(void); 00118 00123 virtual void leaveLock(void); 00124 00125 public: 00129 inline RefPointer() 00130 {ref = NULL;}; 00131 00137 RefPointer(RefObject *obj); 00138 00144 RefPointer(const RefPointer &ptr); 00145 00146 virtual ~RefPointer(); 00147 00148 RefPointer& operator=(const RefObject &ref); 00149 00150 inline void *operator*() const 00151 {return getObject();}; 00152 00153 inline void *operator->() const 00154 {return getObject();}; 00155 00156 void *getObject(void) const; 00157 00158 bool operator!() const; 00159 }; 00160 00168 class __EXPORT LinkedSingle 00169 { 00170 protected: 00171 LinkedSingle *nextObject; 00172 00173 inline LinkedSingle() 00174 {nextObject = NULL;}; 00175 00176 virtual ~LinkedSingle(); 00177 00178 public: 00188 virtual LinkedSingle *getFirst(void); 00189 00197 virtual LinkedSingle *getLast(void); 00198 00205 inline LinkedSingle *getNext(void) 00206 {return nextObject;}; 00207 00215 virtual void insert(LinkedSingle& obj); 00216 00217 LinkedSingle &operator+=(LinkedSingle &obj); 00218 }; 00219 00227 class __EXPORT LinkedDouble 00228 { 00229 protected: 00230 LinkedDouble *nextObject, *prevObject; 00231 00232 inline LinkedDouble() 00233 {nextObject = prevObject = NULL;}; 00234 00235 virtual ~LinkedDouble(); 00236 00237 virtual void enterLock(void); 00238 00239 virtual void leaveLock(void); 00240 00241 public: 00242 00247 enum InsertMode 00248 { 00249 modeAtFirst, 00250 modeAtLast, 00251 modeBefore, 00252 modeAfter 00253 }; 00254 00262 virtual LinkedDouble *getFirst(void); 00263 00271 virtual LinkedDouble *getLast(void); 00272 00280 virtual LinkedDouble *getInsert(void); 00281 00288 inline LinkedDouble *getNext(void) 00289 {return nextObject;}; 00290 00296 inline LinkedDouble *getPrev(void) 00297 {return prevObject;}; 00298 00304 virtual void insert(LinkedDouble& obj); 00305 00312 virtual void insert(InsertMode position, LinkedDouble& obj); 00313 00317 virtual void detach(void); 00318 00319 LinkedDouble &operator+=(LinkedDouble &obj); 00320 00321 LinkedDouble &operator--(); 00322 }; 00323 00334 class __EXPORT MapTable : public Mutex 00335 { 00336 protected: 00337 friend class MapObject; 00338 unsigned range; 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 00381 void *getObject(const char *id); 00382 00389 void addObject(MapObject &obj); 00390 00400 void *getFree(void); 00401 00408 void addFree(MapObject *obj); 00409 00416 MapTable &operator+=(MapObject &obj); 00417 00425 virtual MapTable &operator-=(MapObject &obj); 00426 }; 00427 00436 class __EXPORT MapObject 00437 { 00438 protected: 00439 friend class MapTable; 00440 MapObject *nextObject; 00441 const char *idObject; 00442 MapTable *table; 00443 00447 void detach(void); 00448 00454 MapObject(const char *id); 00455 }; 00456 00457 #ifdef CCXX_NAMESPACES 00458 } 00459 #endif 00460 00461 #endif 00462