ANNA Suite  2020b
Multipurpose development suite for Telco applications
AutoObject.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_dbos_AutoObject_hpp
10 #define anna_dbos_AutoObject_hpp
11 
12 #include <anna/dbos/Object.hpp>
13 
14 namespace anna {
15 
16 namespace dbos {
17 
18 
84 template <typename T> class AutoObject {
85 public:
92  explicit AutoObject(T* t) : a_t(t) {;}
93 
97  AutoObject() : a_t(NULL) {;}
98 
102  ~AutoObject() { if(a_t != NULL) T::release(a_t); }
103 
109  T* operator -> () const { return a_t; }
110 
116  T* operator = (T* t) {
117  if(a_t != t) {
118  T::release(a_t);
119  a_t = t;
120  }
121 
122  return a_t;
123  }
124 
130  T* operator = (const AutoObject <T>& other) noexcept(false) {
131  return (this != &other) ? (*this = T::duplicate(other.a_t)) : a_t;
132  }
133 
138  operator T*() const { return a_t; }
139 
140 private:
141  T* a_t;
142 };
143 
144 
145 }
146 }
147 
148 
149 
150 #endif
151 
152 
~AutoObject()
Definition: AutoObject.hpp:102
Definition: AutoObject.hpp:84
T * operator->() const
Definition: AutoObject.hpp:109
Definition: app.hpp:12
AutoObject()
Definition: AutoObject.hpp:97
T * operator=(T *t)
Definition: AutoObject.hpp:116
AutoObject(T *t)
Definition: AutoObject.hpp:92