libwt  1.0.0
A C++ library for the continous wavelet transform.
object.hh
1 
9 #ifndef __WT_OBJECT_HH__
10 #define __WT_OBJECT_HH__
11 
12 #include <complex>
13 #include <cmath>
14 
15 
16 namespace wt {
17 
22 class Object
23 {
24 protected:
26  Object();
27 
28 public:
30  virtual ~Object();
31 
33  Object *ref();
35  void unref();
36 
37 protected:
39  size_t _refCount;
40 };
41 
42 
45 class Container
46 {
47 public:
49  typedef Object ObjectType;
50 
51 public:
53  Container();
55  Container(Object *object);
57  Container(const Container &other);
59  virtual ~Container();
61  Container &operator=(const Container &other);
62 
64  template <class T>
65  inline bool is() {
66  return 0 != dynamic_cast<typename T::ObjectType *>(_object);
67  }
68 
71  template <class T>
72  inline T as() {
73  return T(dynamic_cast<typename T::ObjectType *>(_object));
74  }
75 
77  inline bool isNull() const { return 0 == _object; }
78 
79 protected:
82 };
83 
84 }
85 
86 #endif // __WT_OBJECT_HH__
bool isNull() const
Returns true if the container is empty (null).
Definition: object.hh:77
Object * _object
The object being managed.
Definition: object.hh:81
Object ObjectType
Specifies the object type being held by the container class.
Definition: object.hh:49
bool is()
Returns true if the object held by the container is of type T::ObjectType.
Definition: object.hh:65
Base class of all container classes holding a managed reference to some Object.
Definition: object.hh:45
Object * ref()
Retunrs a new reference to the object (increases the reference counter).
Definition: object.cc:16
void unref()
Invalidates this reference to the object (decreases the reference counter).
Definition: object.cc:22
Definition: convolution.hh:7
size_t _refCount
The reference counter.
Definition: object.hh:39
T as()
Dynamic container cast.
Definition: object.hh:72
Container()
Empty constructor.
Definition: object.cc:30
virtual ~Container()
Destructor.
Definition: object.cc:48
Base class of all managed objects.
Definition: object.hh:22
Container & operator=(const Container &other)
Assignment operator.
Definition: object.cc:53
Object()
Hidden constructor.
Definition: object.cc:5
virtual ~Object()
Destructor.
Definition: object.cc:11