libpgplotxx.a (C++ interface to PGPLOT)
pghandle.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef TF_PGHANDLE_H_VERSION
38 
39 #define TF_PGHANDLE_H_VERSION \
40  "TF_PGHANDLE_H V1.0 "
41 #define TF_PGHANDLE_H_CVSID \
42  "$Id$"
43 
44 namespace pgplot {
45 
51 
84  template<class X>
85  class HandleOfConst {
86  public:
90  template<class Y> friend class HandleOfConst;
91 
104  typedef X Tvalue;
105  typedef X* Tpointer;
106  typedef X& Treference;
107  typedef const X* Tpointer_to_const;
108  typedef const X& Treference_to_const;
114 
116  HandleOfConst():
118  Mpointer(new Tvalue()), Mpcount(new int(1)) { }
119 
122  Mpointer(new Tvalue(x)), Mpcount(new int(1)) { }
123 
125  template<class Y>
127  Mpointer(h.Mpointer), Mpcount(h.Mpcount)
128  { (*Mpcount)++; }
130 
133  { if (--(*Mpcount)==0) { delete Mpointer; delete Mpcount; } }
134 
136 
137  Tpointer_to_const operator->() const { return Mpointer; }
139 
143 
145  template<class Y>
147  {
148  if (Mpointer == h.Mpointer) return *this;
149  if (--(*Mpcount) == 0) { delete Mpointer; delete Mpcount; }
150  Mpointer=h.Mpointer;
151  Mpcount=h.Mpcount;
152  (*Mpcount)++;
153  return *this;
154  }
155 
156  protected:
158 
159  Tpointer pointer() const { return Mpointer;}
161 
163  Treference reference() const { return *Mpointer;}
165 
166  private:
170  int* Mpcount;
171  }; // template class HandleOfConst
172 
173  /*----------------------------------------------------------------------*/
174 
218  template<class X>
219  class Handle: public HandleOfConst<X> {
220  public:
233  typedef X Tvalue;
234  typedef X* Tpointer;
235  typedef X& Treference;
236  typedef const X* Tpointer_to_const;
237  typedef const X& Treference_to_const;
249  Handle(): Tbase() { }
251 
254  Tbase(x) { }
255 
257  template<class Y>
258  Handle(const Handle<Y>& h): Tbase(h) { }
260 
262 
263  Tpointer operator->() const { return Tbase::pointer(); }
265 
267  Treference operator*() const { return Tbase::reference(); }
269 
271  template<class Y>
273  {
274  Tbase::operator=(h);
275  return *this;
276  }
277 
278  }; // template class Handle
279 
282 } // namespace pgplot
283 
284 #endif // TF_PGHANDLE_H_VERSION (includeguard)
285 
286 /* ----- END OF pghandle.h ----- */
HandleOfConst< Tvalue > Tbase
Definition: pghandle.h:238
Tbase Tcontainer_of_const
Definition: pghandle.h:240
HandleOfConst< Tvalue > Tcontainer
Definition: pghandle.h:109
contains all pgplot stuff
Definition: affpgplot.cc:46
Handle(Treference_to_const x)
Initializing constructor.
Definition: pghandle.h:253
Tcontainer & operator=(const Handle< Y > &h)
Assignement operator providing transparency to inheritance.
Definition: pghandle.h:272
Tpointer operator->() const
Write access operator with pointer semantics.
Definition: pghandle.h:264
Handle(const Handle< Y > &h)
Copy constructor providing transparency to inheritance.
Definition: pghandle.h:258
~HandleOfConst()
Destructor that takes care of reference count.
Definition: pghandle.h:132
The handle class.
Definition: pghandle.h:219
Base class for handles.
Definition: pghandle.h:85
Tpointer_to_const operator->() const
Read access operator with pointer semantics.
Definition: pghandle.h:138
Tcontainer Tcontainer_of_const
Definition: pghandle.h:110
int * Mpcount
reference counter
Definition: pghandle.h:170
Treference operator*() const
Write access operator with pointer semantics.
Definition: pghandle.h:267
Tcontainer_of_const Tcoc
Definition: pghandle.h:241
const X * Tpointer_to_const
Definition: pghandle.h:236
const X * Tpointer_to_const
Definition: pghandle.h:107
const X & Treference_to_const
Definition: pghandle.h:237
Treference reference() const
expose the object to derived classes
Definition: pghandle.h:163
Tcontainer_of_const Tcoc
Definition: pghandle.h:111
Handle< Tvalue > Tcontainer
Definition: pghandle.h:239
Treference_to_const operator*() const
Read access operator with pointer semantics.
Definition: pghandle.h:141
const X & Treference_to_const
Definition: pghandle.h:108
HandleOfConst(Treference_to_const x)
Constructor to initialize the handle.
Definition: pghandle.h:121
HandleOfConst()
Default constructor if class X provides one too.
Definition: pghandle.h:117
Handle()
Default constructor.
Definition: pghandle.h:250
Tpointer Mpointer
internal pointer to the handled object
Definition: pghandle.h:168
Tcontainer & operator=(const HandleOfConst< Y > &h)
Assignement operator that provide transparency for inheritance.
Definition: pghandle.h:146
Tpointer pointer() const
expose the pointer to derived classes
Definition: pghandle.h:160