Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
object.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38 
45 #ifndef CCXX_OBJECT_H_
46 #define CCXX_OBJECT_H_
47 
48 #ifndef CCXX_MISSING_H_
49 #include <cc++/missing.h>
50 #endif
51 
52 #ifdef CCXX_NAMESPACES
53 namespace ost {
54 #endif
55 
58 
67 {
68 protected:
69  friend class RefPointer;
70 
71  unsigned refCount;
72 
76  inline RefObject()
77  {refCount = 0;};
78 
83  virtual ~RefObject();
84 
85 public:
94  virtual void *getObject(void) = 0;
95 };
96 
106 {
107 protected:
109 
113  void detach(void);
114 
119  virtual void enterLock(void);
120 
125  virtual void leaveLock(void);
126 
127 public:
131  inline RefPointer()
132  {ref = NULL;};
133 
139  RefPointer(RefObject *obj);
140 
146  RefPointer(const RefPointer &ptr);
147 
148  virtual ~RefPointer();
149 
150  RefPointer& operator=(const RefObject &ref);
151 
152  inline void *operator*() const
153  {return getObject();};
154 
155  inline void *operator->() const
156  {return getObject();};
157 
158  void *getObject(void) const;
159 
160  bool operator!() const;
161 };
162 
171 {
172 protected:
174 
175  inline LinkedSingle()
176  {nextObject = NULL;};
177 
178  virtual ~LinkedSingle();
179 
180 public:
190  virtual LinkedSingle *getFirst(void);
191 
199  virtual LinkedSingle *getLast(void);
200 
207  inline LinkedSingle *getNext(void)
208  {return nextObject;};
209 
217  virtual void insert(LinkedSingle& obj);
218 
219  LinkedSingle &operator+=(LinkedSingle &obj);
220 };
221 
230 {
231 protected:
232  LinkedDouble *nextObject, *prevObject;
233 
234  inline LinkedDouble()
235  {nextObject = prevObject = NULL;};
236 
237  virtual ~LinkedDouble();
238 
239  virtual void enterLock(void);
240 
241  virtual void leaveLock(void);
242 
243  virtual LinkedDouble *firstObject();
244 
245  virtual LinkedDouble *lastObject();
246 
247 public:
248 
254  {
258  modeAfter
259  };
260 
268  virtual LinkedDouble *getFirst(void);
269 
277  virtual LinkedDouble *getLast(void);
278 
286  virtual LinkedDouble *getInsert(void);
287 
294  inline LinkedDouble *getNext(void)
295  {return nextObject;};
296 
302  inline LinkedDouble *getPrev(void)
303  {return prevObject;};
304 
313  virtual void insert(LinkedDouble& obj, InsertMode position = modeAtLast);
314 
318  virtual void detach(void);
319 
320  LinkedDouble &operator+=(LinkedDouble &obj);
321 
322  LinkedDouble &operator--();
323 };
324 
335 class __EXPORT MapTable : public Mutex
336 {
337 protected:
338  friend class MapObject;
339  friend class MapIndex;
340  unsigned range;
341  unsigned count;
343 
344  void cleanup(void);
345 
346 public:
352  MapTable(unsigned size);
353 
357  virtual ~MapTable();
358 
367  virtual unsigned getIndex(const char *id);
368 
374  inline unsigned getRange(void)
375  {return range;};
376 
382  inline unsigned getSize(void)
383  {return count;};
384 
392  void *getObject(const char *id);
393 
400  void addObject(MapObject &obj);
407  void *getFirst();
408 
415  void *getLast();
416 
423  void *getEnd()
424  { return NULL; };
425 
435  void *getFree(void);
436 
443  void addFree(MapObject *obj);
444 
451  MapTable &operator+=(MapObject &obj);
452 
460  virtual MapTable &operator-=(MapObject &obj);
461 };
462 
473 {
475 
476 public :
477 
481  MapIndex() : thisObject(NULL)
482  {};
483 
489  MapIndex(MapObject* theObject) : thisObject(theObject)
490  {};
491 
497  MapIndex(const MapIndex& theIndex) : thisObject(theIndex.thisObject)
498  {};
499 
506  void* operator*() const
507  { return (void*)thisObject; }
508 
514  MapIndex& operator=(MapObject *theObject);
515 
521  MapIndex& operator++(); // prefix
522 
528  MapIndex operator++(int) // postfix
529  { return this->operator++(); }
530 
536  bool operator==(const MapIndex& theIndex) const
537  { return thisObject == theIndex.thisObject; };
538 
539  bool operator!=(const MapIndex& theIndex) const
540  { return !(*this == theIndex); };
541 
548  bool operator==(const MapObject* theObject) const
549  { return thisObject == theObject; };
550 
551  bool operator!=(const MapObject* theObject) const
552  { return !(*this == theObject); };
553 };
554 
564 {
565 protected:
566  friend class MapTable;
567  friend class MapIndex;
569  const char *idObject;
571 
572 public:
573 
577  void detach(void);
578 
584  MapObject(const char *id);
585 };
586 
587 #ifdef CCXX_NAMESPACES
588 }
589 #endif
590 
591 #endif
592 
LinkedDouble * getNext(void)
Get next object, for convenience.
Definition: object.h:294
InsertMode
Requested in overloaded insert() method to indicate how to insert data into list. ...
Definition: object.h:253
Self managed double linked list object chain.
Definition: object.h:229
bool operator==(const MapObject *theObject) const
Comparison operator, between the MapIndex and a MapObject, useful to avoid casts for sake of clearnes...
Definition: object.h:548
LinkedDouble * prevObject
Definition: object.h:232
bool operator!=(const MapIndex &theIndex) const
Definition: object.h:539
insert at first position in list pointed by current object
Definition: object.h:255
void * getEnd()
Get table's end, useful for cycle control; it is returned as void * for easy re-cast.
Definition: object.h:423
The MapIndex allows linear access into a MapTable, that otherwise could have its elements being retri...
Definition: object.h:472
LinkedSingle * getNext(void)
Get next object, for convenience.
Definition: object.h:207
A reference countable object.
Definition: object.h:66
Pointer to reference counted objects.
Definition: object.h:105
substitute functions which may be missing in target platform libc.
unsigned getSize(void)
Return the number of object stored in this table.
Definition: object.h:382
RefPointer()
Create an unattached pointer.
Definition: object.h:131
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:186
MapObject ** map
Definition: object.h:342
insert at last position in list pointed by current object
Definition: object.h:256
void * operator->() const
Definition: object.h:155
unsigned range
Definition: object.h:340
class __EXPORT MapObject
Definition: object.h:56
RefObject * ref
Definition: object.h:108
LinkedDouble * getPrev(void)
Get prev object in the list.
Definition: object.h:302
void * getObject(void) const
LinkedSingle * nextObject
Definition: object.h:173
A map table allows for entities to be mapped (hash index) onto it.
Definition: object.h:335
MapObject * nextObject
Definition: object.h:568
The MapObject is a base class which can be used to make a derived class operate on a MapTable...
Definition: object.h:563
unsigned count
Definition: object.h:341
void * operator*() const
Definition: object.h:152
RefObject()
The constructor simply initializes the count.
Definition: object.h:76
MapIndex(const MapIndex &theIndex)
Creates a copy of a given map index.
Definition: object.h:497
#define __EXPORT
Definition: audio2.h:51
MapIndex operator++(int)
Postfix increment operator, to be used in loops and such.
Definition: object.h:528
bool operator==(const MapIndex &theIndex) const
Comparison operator, between two MapIndex's.
Definition: object.h:536
void * operator*() const
Dereference operator: the pointed object it is returned as void * for easy re-cast.
Definition: object.h:506
Self managed single linked list object chain.
Definition: object.h:170
bool operator!=(const MapObject *theObject) const
Definition: object.h:551
LinkedDouble()
Definition: object.h:234
MapIndex(MapObject *theObject)
Creates a map index pointing to a specific map object.
Definition: object.h:489
unsigned getRange(void)
Return range of this table.
Definition: object.h:374
MapIndex()
Creates an empty map index (pointing to nothing).
Definition: object.h:481
unsigned refCount
Definition: object.h:71
LinkedSingle()
Definition: object.h:175
insert in list before current object
Definition: object.h:257
MapTable * table
Definition: object.h:570
MapObject * thisObject
Definition: object.h:474
const char * idObject
Definition: object.h:569