1 | #ifndef REFERENCE_COUNTER_H |
---|
2 | #define REFERENCE_COUNTER_H |
---|
3 | |
---|
4 | #ifdef HAVE_WRAPPERS |
---|
5 | |
---|
6 | #include "Wrappers.h" |
---|
7 | |
---|
8 | /*! \class ReferenceCounter |
---|
9 | * \brief Class ReferenceCounter may be used to derive classes from it |
---|
10 | * which deploy reference counting. |
---|
11 | * |
---|
12 | * Any instance of a class, say C, derived from ReferenceCounter is |
---|
13 | * equipped with a counter that stores how many instances of C exist. |
---|
14 | * Thereby, it becomes possible to better manage instances of C and |
---|
15 | * make shallow copies of instances of C by simply incrementing the |
---|
16 | * reference counter (which is a member of the superclass of C, i.e., |
---|
17 | * of ReferenceCounter). |
---|
18 | * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch |
---|
19 | */ |
---|
20 | class ReferenceCounter { |
---|
21 | private: |
---|
22 | /*! private member for storing the actual reference counter */ |
---|
23 | ReferenceCounterType m_counter; |
---|
24 | protected: |
---|
25 | /*! |
---|
26 | * A method for retrieving the actual reference counter. |
---|
27 | * @return the actual reference counter |
---|
28 | */ |
---|
29 | ReferenceCounterType getCounter () const; |
---|
30 | |
---|
31 | /*! |
---|
32 | * A method for retrieving whether the reference counter is |
---|
33 | * greater than 1. In this case, at least two references to the given |
---|
34 | * instance of ReferenceCounter exist. |
---|
35 | * @return true if the reference counter is greater than 1 |
---|
36 | */ |
---|
37 | bool isShared () const; |
---|
38 | |
---|
39 | /*! |
---|
40 | * A method for incrementing the reference counter. |
---|
41 | * @return the value of the reference counter after incrementing |
---|
42 | * @see ReferenceCounterType::decrement (); |
---|
43 | */ |
---|
44 | ReferenceCounterType increment (); |
---|
45 | |
---|
46 | /*! |
---|
47 | * A method for decrementing the reference counter. |
---|
48 | * @return the value of the reference counter after decrementing |
---|
49 | * @see ReferenceCounterType::increment (); |
---|
50 | */ |
---|
51 | ReferenceCounterType decrement (); |
---|
52 | public: |
---|
53 | /*! |
---|
54 | * A constructor for ReferenceCounter.<br> |
---|
55 | * This constructor will create a new instance with actual |
---|
56 | * reference counter set to zero. |
---|
57 | */ |
---|
58 | ReferenceCounter (); |
---|
59 | |
---|
60 | /*! |
---|
61 | * A copy constructor for ReferenceCounter.<br> |
---|
62 | * As this constructor should neither be called by the user nor |
---|
63 | * implicitely by some method, it will halt the program. |
---|
64 | */ |
---|
65 | ReferenceCounter (const ReferenceCounter& rc); |
---|
66 | |
---|
67 | /*! |
---|
68 | * A destructor for ReferenceCounter. |
---|
69 | */ |
---|
70 | ~ReferenceCounter (); |
---|
71 | /*! We enable PolyWrapper to "see" all methods of ReferenceCounter. */ |
---|
72 | friend class PolyWrapper; |
---|
73 | }; |
---|
74 | |
---|
75 | #endif |
---|
76 | /* HAVE_WRAPPERS */ |
---|
77 | |
---|
78 | #endif |
---|
79 | /* REFERENCE_COUNTER_H */ |
---|