Chemical Data Processing Library C++ API - Version 1.4.0
CairoPointer.hpp
Go to the documentation of this file.
1 /*
2  * CairoPointer.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_VIS_CAIROPOINTER_HPP
30 #define CDPL_VIS_CAIROPOINTER_HPP
31 
32 #include "CDPL/Vis/APIPrefix.hpp"
33 
34 
35 typedef struct _cairo cairo_t;
36 typedef struct _cairo_surface cairo_surface_t;
37 typedef struct _cairo_pattern cairo_pattern_t;
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Vis
44  {
45 
58  template <typename T>
60 
65  template <>
67  {
68 
73  static cairo_t* reference(cairo_t* p) throw();
74 
78  static void destroy(cairo_t* p) throw();
79  };
80 
85  template <>
87  {
88 
94 
98  static void destroy(cairo_surface_t* p) throw();
99  };
100 
105  template <>
107  {
108 
114 
118  static void destroy(cairo_pattern_t* p) throw();
119  };
120 
146  template <typename T>
148  {
149 
150  public:
157  explicit CairoPointer(T* ptr = 0) throw();
158 
164  CairoPointer(const CairoPointer& ptr) throw();
165 
171 
185  CairoPointer& operator=(const CairoPointer& ptr) throw();
186 
191  bool operator!() const throw();
192 
198  T& operator*() const throw();
199 
208  T* operator->() const throw();
209 
214  T* get() const throw();
215 
222  T* release() throw();
223 
233  void reset(T* ptr = 0) throw();
234 
235  private:
236  T* pointer;
237  };
238  } // namespace Vis
239 } // namespace CDPL
240 
241 
242 // Implementation
243 
244 template <typename T>
245 CDPL::Vis::CairoPointer<T>::CairoPointer(T* p) throw():
246  pointer(p)
247 {}
248 
249 template <typename T>
251  pointer(CairoPointerTraits<T>::reference(other.pointer))
252 {}
253 
254 template <typename T>
256 {
258 }
259 
260 template <typename T>
262 {
263  if (this != &other) {
265  pointer = CairoPointerTraits<T>::reference(other.pointer);
266  }
267 
268  return *this;
269 }
270 
271 template <typename T>
273 {
274  return !pointer;
275 }
276 
277 template <typename T>
279 {
280  return *pointer;
281 }
282 
283 template <typename T>
285 {
286  return pointer;
287 }
288 
289 template <typename T>
291 {
292  return pointer;
293 }
294 
295 template <typename T>
297 {
298  T* tmp = pointer;
299  pointer = 0;
300  return tmp;
301 }
302 
303 template <typename T>
305 {
306  if (p != pointer) {
308  pointer = p;
309  }
310 }
311 
312 #endif // CDPL_VIS_CAIROPOINTER_HPP
struct _cairo_surface cairo_surface_t
Definition: CairoPointer.hpp:36
struct _cairo cairo_t
Definition: CairoPointer.hpp:35
struct _cairo_pattern cairo_pattern_t
Definition: CairoPointer.hpp:37
Definition of the preprocessor macro CDPL_VIS_API.
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
A smart pointer managing the lifetime of allocated Cairo 2D Graphics Library data structures.
Definition: CairoPointer.hpp:148
void reset(T *ptr=0)
Replaces the currently managed object with the object pointed to by ptr.
Definition: CairoPointer.hpp:304
T * get() const
Returns a pointer to the managed object.
Definition: CairoPointer.hpp:290
T * operator->() const
Returns a pointer to the managed object.
Definition: CairoPointer.hpp:284
T * release()
Releases the currently managed object.
Definition: CairoPointer.hpp:296
bool operator!() const
Tells whether this CairoPointer references an object or holds a null pointer.
Definition: CairoPointer.hpp:272
CairoPointer & operator=(const CairoPointer &ptr)
Assignment operator.
Definition: CairoPointer.hpp:261
CairoPointer(T *ptr=0)
Constructs a CairoPointer that manages the reference count of the object pointed to by ptr.
Definition: CairoPointer.hpp:245
T & operator*() const
Returns a non-const reference to the managed object.
Definition: CairoPointer.hpp:278
~CairoPointer()
Destroys the CairoPointer.
Definition: CairoPointer.hpp:255
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int p
Specifies that the stereocenter has p configuration.
Definition: CIPDescriptor.hpp:121
The namespace of the Chemical Data Processing Library.
static void destroy(cairo_pattern_t *p)
Decrements the reference count of the object pointed to by p by 1.
static cairo_pattern_t * reference(cairo_pattern_t *p)
Increments the reference count of the object pointed to by p by 1.
static void destroy(cairo_surface_t *p)
Decrements the reference count of the object pointed to by p by 1.
static cairo_surface_t * reference(cairo_surface_t *p)
Increments the reference count of the object pointed to by p by 1.
static cairo_t * reference(cairo_t *p)
Increments the reference count of the object pointed to by p by 1.
static void destroy(cairo_t *p)
Decrements the reference count of the object pointed to by p by 1.
Traits class providing the reference-count management functions for a particular Cairo 2D Graphics Li...
Definition: CairoPointer.hpp:59