commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AutoRefBase.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006-2007 Raphael David / CANTOR
3 //
4 
5 #ifndef CMR_AUTO_REF_BASE_DEFINED
6 #define CMR_AUTO_REF_BASE_DEFINED
7 
8 #include "Commore.h"
9 
10 namespace commore
11 {
12  class RefObject;
13  typedef RefObject* PRefObject;
14 
19  {
20  friend class RefObject;
21 
22  public:
27  : p_(0)
28  {}
33  : p_(p)
34  {
35  attach();
36  }
41  : p_(a.get_())
42  {
43  attach();
44  }
48  AutoRefBase& operator = (const AutoRefBase& a)
49  {
50  if ((void*)this != (void*)&a)
51  {
52  set_(a.get_());
53  }
54  return *this;
55  }
57  {
58  release();
59  }
60 
61  public:
65  RefObject* get_() const
66  {
67  return p_;
68  }
72  void set_(RefObject* p)
73  {
74  if (p_ != p)
75  {
76  release();
77  p_ = p;
78  attach();
79  }
80  }
84  void clear()
85  {
86  set_(0);
87  }
88 
89  private:
90  inline void attach();
91  inline void release();
92 
93  private:
94  RefObject* p_;
95  };
96 
103  {
104  friend class RefObject;
105  public:
107  : p_(p)
108  {
109  attach();
110  }
112  : p_(a.get_())
113  {
114  attach();
115  }
116  IAutoRefBase& operator = (const IAutoRefBase& a)
117  {
118  if ((void*)this != (void*)&a)
119  {
120  set_(a.get_());
121  }
122  return *this;
123  }
125  {
126  release();
127  }
128 
129  public:
130  RefObject* get_() const
131  {
132  return p_;
133  }
134  void set_(RefObject* p)
135  {
136  if (p_ != p)
137  {
138  release();
139  p_ = p;
140  attach();
141  }
142  }
143  void clear()
144  {
145  set_(0);
146  }
147 
148  private:
149  inline void attach();
150  inline void release();
151 
152  private:
153  RefObject* p_;
154  };
155 
156 }
157 #endif
~IAutoRefBase()
Definition: AutoRefBase.h:124
Definition: AutoRefBase.h:102
void set_(RefObject *p)
Definition: AutoRefBase.h:134
Definition: AutoRefBase.h:18
#define CMREXD
Definition: Compiler.h:22
IAutoRefBase(RefObject *p)
Definition: AutoRefBase.h:106
RefObject * PRefObject
Definition: AutoRefBase.h:12
void clear()
Definition: AutoRefBase.h:84
Definition: RefObject.h:89
AutoRefBase()
Definition: AutoRefBase.h:26
AutoRefBase(const AutoRefBase &a)
Definition: AutoRefBase.h:40
IAutoRefBase(const IAutoRefBase &a)
Definition: AutoRefBase.h:111
RefObject * get_() const
Definition: AutoRefBase.h:65
AutoRefBase(RefObject *p)
Definition: AutoRefBase.h:32
void set_(RefObject *p)
Definition: AutoRefBase.h:72
RefObject * get_() const
Definition: AutoRefBase.h:130
~AutoRefBase()
Definition: AutoRefBase.h:56
void clear()
Definition: AutoRefBase.h:143