Chemical Data Processing Library C++ API - Version 1.1.1
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 
46  template <typename T>
48 
53  template <>
55  {
56 
61  static cairo_t* reference(cairo_t* p) throw();
62 
66  static void destroy(cairo_t* p) throw();
67  };
68 
73  template <>
75  {
76 
82 
86  static void destroy(cairo_surface_t* p) throw();
87  };
88 
93  template <>
95  {
96 
102 
106  static void destroy(cairo_pattern_t* p) throw();
107  };
108 
134  template <typename T>
136  {
137 
138  public:
145  explicit CairoPointer(T* ptr = 0) throw();
146 
152  CairoPointer(const CairoPointer& ptr) throw();
153 
159 
173  CairoPointer& operator=(const CairoPointer& ptr) throw();
174 
179  bool operator!() const throw();
180 
186  T& operator*() const throw();
187 
196  T* operator->() const throw();
197 
202  T* get() const throw();
203 
210  T* release() throw();
211 
221  void reset(T* ptr = 0) throw();
222 
223  private:
224  T* pointer;
225  };
226  } // namespace Vis
227 } // namespace CDPL
228 
229 
230 // Implementation
231 
232 template <typename T>
233 CDPL::Vis::CairoPointer<T>::CairoPointer(T* p) throw():
234  pointer(p)
235 {}
236 
237 template <typename T>
239  pointer(CairoPointerTraits<T>::reference(other.pointer))
240 {}
241 
242 template <typename T>
244 {
246 }
247 
248 template <typename T>
250 {
251  if (this != &other) {
253  pointer = CairoPointerTraits<T>::reference(other.pointer);
254  }
255 
256  return *this;
257 }
258 
259 template <typename T>
261 {
262  return !pointer;
263 }
264 
265 template <typename T>
267 {
268  return *pointer;
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  T* tmp = pointer;
287  pointer = 0;
288  return tmp;
289 }
290 
291 template <typename T>
293 {
294  if (p != pointer) {
296  pointer = p;
297  }
298 }
299 
300 #endif // CDPL_VIS_CAIROPOINTER_HPP
CDPL::Vis::CairoPointer::operator!
bool operator!() const
Tells whether this CairoPointer references an object or holds a null pointer.
Definition: CairoPointer.hpp:260
CDPL::Chem::CIPDescriptor::p
const unsigned int p
Specifies that the stereocenter has p configuration.
Definition: CIPDescriptor.hpp:121
cairo_pattern_t
struct _cairo_pattern cairo_pattern_t
Definition: CairoPointer.hpp:37
CDPL::Vis::CairoPointer::operator=
CairoPointer & operator=(const CairoPointer &ptr)
Assignment operator.
Definition: CairoPointer.hpp:249
CDPL::Vis::CairoPointerTraits< cairo_pattern_t >::reference
static cairo_pattern_t * reference(cairo_pattern_t *p)
Increments the reference count of the object pointed to by p by 1.
CDPL::Vis::CairoPointer::operator->
T * operator->() const
Returns a pointer to the referenced object.
Definition: CairoPointer.hpp:272
CDPL::Vis::CairoPointerTraits< cairo_surface_t >::destroy
static void destroy(cairo_surface_t *p)
Decrements the reference count of the object pointed to by p by 1.
cairo_surface_t
struct _cairo_surface cairo_surface_t
Definition: CairoPointer.hpp:36
CDPL::Vis::CairoPointerTraits< cairo_t >::destroy
static void destroy(cairo_t *p)
Decrements the reference count of the object pointed to by p by 1.
cairo_t
struct _cairo cairo_t
Definition: CairoPointer.hpp:35
CDPL::Vis::CairoPointer::~CairoPointer
~CairoPointer()
Destroys the CairoPointer.
Definition: CairoPointer.hpp:243
CDPL_VIS_API
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Vis::CairoPointerTraits< cairo_surface_t >::reference
static cairo_surface_t * reference(cairo_surface_t *p)
Increments the reference count of the object pointed to by p by 1.
CDPL::Vis::CairoPointer::operator*
T & operator*() const
Returns a non-const reference to the pointed-to object.
Definition: CairoPointer.hpp:266
CDPL::Vis::CairoPointerTraits< cairo_t >::reference
static cairo_t * reference(cairo_t *p)
Increments the reference count of the object pointed to by p by 1.
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Vis::CairoPointer::get
T * get() const
Returns a pointer to the referenced object.
Definition: CairoPointer.hpp:278
CDPL::Vis::CairoPointerTraits< cairo_pattern_t >::destroy
static void destroy(cairo_pattern_t *p)
Decrements the reference count of the object pointed to by p by 1.
CDPL::Vis::CairoPointer::release
T * release()
Releases the currently referenced object.
Definition: CairoPointer.hpp:284
CDPL::Vis::CairoPointerTraits
Definition: CairoPointer.hpp:47
APIPrefix.hpp
Definition of the preprocessor macro CDPL_VIS_API.
CDPL::Vis::CairoPointer::reset
void reset(T *ptr=0)
Replaces the current object reference with a reference to the object pointed to by ptr.
Definition: CairoPointer.hpp:292
CDPL::Vis::CairoPointer
A smart pointer managing the lifetime of allocated Cairo data structures.
Definition: CairoPointer.hpp:136
CDPL::Vis::CairoPointer::CairoPointer
CairoPointer(T *ptr=0)
Constructs a CairoPointer that manages the reference count of the object pointed to by ptr.
Definition: CairoPointer.hpp:233