CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ora::Ptr< T > Class Template Reference

#include <Ptr.h>

Public Member Functions

void * address () const
 
template<class C >
Ptr< T > & cast (const Ptr< C > &)
 
template<class C >
ora::Ptr< T > & cast (const Ptr< C > &aPtr)
 
Tget () const
 
bool isLoaded () const
 
void load () const
 
boost::shared_ptr< IPtrLoader > & loader () const
 
 operator bool () const
 
bool operator! () const
 
template<class C >
bool operator!= (const Ptr< C > &aPtr) const
 
Toperator* () const
 
Toperator-> () const
 
Ptr< T > & operator= (T *)
 
Ptr< T > & operator= (const Ptr< T > &)
 
template<class C >
Ptr< T > & operator= (const Ptr< C > &)
 
template<class C >
ora::Ptr< T > & operator= (const Ptr< C > &aPtr)
 
template<class C >
bool operator== (const Ptr< C > &aPtr) const
 
 Ptr ()
 
 Ptr (T *anObject)
 
 Ptr (const Ptr< T > &)
 
template<class C >
 Ptr (const Ptr< C > &)
 
void reset ()
 
boost::shared_ptr< T > & share () const
 
virtual ~Ptr ()
 

Private Member Functions

Tptr (bool throw_flag) const
 

Private Attributes

bool m_isLoaded
 
boost::shared_ptr< IPtrLoaderm_loader
 
boost::shared_ptr< Tm_ptr
 

Detailed Description

template<typename T>
class ora::Ptr< T >

Templated class for the persistency of associated objects. The embedded object is treated as a normal C++ pointer in the writing mode, without to require an explicit write request on it. In the reading mode, the embedded object is loaded only at access time (lazy loading).

Definition at line 47 of file Ptr.h.

Constructor & Destructor Documentation

template<class T >
ora::Ptr< T >::Ptr ( )
inline

Definition at line 148 of file Ptr.h.

148  :
149  m_ptr(),m_loader(),m_isLoaded(false) {}
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
ora::Ptr< T >::Ptr ( T anObject)
inlineexplicit

Definition at line 152 of file Ptr.h.

152  :
153  m_ptr(anObject),m_loader(),m_isLoaded(true) {}
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
ora::Ptr< T >::Ptr ( const Ptr< T > &  aPtr)
inline

Definition at line 156 of file Ptr.h.

156  :
157  m_ptr(aPtr.m_ptr),m_loader(aPtr.m_loader),m_isLoaded(false){
158 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
template<class C >
ora::Ptr< T >::Ptr ( const Ptr< C > &  aPtr)
inline

Definition at line 162 of file Ptr.h.

References assert(), EnergyCorrector::c, funct::C, and edmStreamStallGrapher::t.

162  :
163  m_ptr(aPtr.share()),m_loader(aPtr.loader()),m_isLoaded(aPtr.isLoaded()) {
164  // compile-time type checking
165  C* c = 0; T* t(c); assert(t==0);
166 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
assert(m_qm.get())
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
long double T
template<class T >
ora::Ptr< T >::~Ptr ( )
inlinevirtual

Definition at line 169 of file Ptr.h.

169  {
170 }

Member Function Documentation

template<class T >
void * ora::Ptr< T >::address ( ) const
inline

Definition at line 227 of file Ptr.h.

Referenced by ora::Ptr< T >::operator==().

227  {
228  return m_ptr.get();
229 }
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<typename T>
template<class C >
Ptr<T>& ora::Ptr< T >::cast ( const Ptr< C > &  )
template<typename T>
template<class C >
ora::Ptr<T>& ora::Ptr< T >::cast ( const Ptr< C > &  aPtr)
inline

Definition at line 199 of file Ptr.h.

References ora::Ptr< T >::isLoaded(), ora::Ptr< T >::loader(), and ora::Ptr< T >::share().

199  {
200  m_loader = aPtr.loader();
201  m_ptr = boost::dynamic_pointer_cast( aPtr.share());
202  m_isLoaded = aPtr.isLoaded();
203  return *this;
204 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
T * ora::Ptr< T >::get ( void  ) const
inline
template<typename T>
bool ora::Ptr< T >::isLoaded ( ) const
inline

Definition at line 123 of file Ptr.h.

References ora::Ptr< T >::m_isLoaded.

Referenced by ora::Ptr< T >::cast(), and ora::Ptr< T >::operator=().

123  {
124  return m_isLoaded;
125  }
bool m_isLoaded
Definition: Ptr.h:141
template<class T >
void ora::Ptr< T >::load ( ) const
inline

Definition at line 249 of file Ptr.h.

Referenced by MatrixToProcess.MatrixToProcess::getProcess(), and MatrixToProcess.MatrixToProcess::listAll().

249  {
250  ptr( false );
251 }
T * ptr(bool throw_flag) const
Definition: Ptr.h:254
template<typename T>
boost::shared_ptr<IPtrLoader>& ora::Ptr< T >::loader ( ) const
inline

Definition at line 115 of file Ptr.h.

References ora::Ptr< T >::m_loader.

Referenced by ora::Ptr< T >::cast(), and ora::Ptr< T >::operator=().

115  {
116  return m_loader;
117  }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
template<class T >
ora::Ptr< T >::operator bool ( ) const
inline

Definition at line 232 of file Ptr.h.

232  {
233  return ptr(false);
234 }
T * ptr(bool throw_flag) const
Definition: Ptr.h:254
template<class T >
bool ora::Ptr< T >::operator! ( ) const
inline

Definition at line 237 of file Ptr.h.

237  {
238  return ptr(false)==0;
239 }
T * ptr(bool throw_flag) const
Definition: Ptr.h:254
template<typename T>
template<class C >
bool ora::Ptr< T >::operator!= ( const Ptr< C > &  aPtr) const
inline

Definition at line 105 of file Ptr.h.

References ora::Ptr< T >::operator==().

105  {
106  return !(this->operator==(aPtr));
107  }
bool operator==(const Ptr< C > &aPtr) const
Definition: Ptr.h:101
template<class T >
T & ora::Ptr< T >::operator* ( ) const
inline

Definition at line 212 of file Ptr.h.

212  {
213  return *ptr(true);
214 }
T * ptr(bool throw_flag) const
Definition: Ptr.h:254
template<class T >
T * ora::Ptr< T >::operator-> ( ) const
inline

Definition at line 207 of file Ptr.h.

207  {
208  return ptr(true);
209 }
T * ptr(bool throw_flag) const
Definition: Ptr.h:254
template<class T >
ora::Ptr< T > & ora::Ptr< T >::operator= ( T aPtr)
inline

Definition at line 173 of file Ptr.h.

173  {
174  m_ptr.reset(aPtr);
175  m_isLoaded = true;
176  return *this;
177 }
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
ora::Ptr< T > & ora::Ptr< T >::operator= ( const Ptr< T > &  aPtr)
inline

Definition at line 180 of file Ptr.h.

References ora::Ptr< T >::m_isLoaded, ora::Ptr< T >::m_loader, and ora::Ptr< T >::m_ptr.

180  {
181  m_loader = aPtr.m_loader;
182  m_isLoaded = aPtr.m_isLoaded;
183  m_ptr = aPtr.m_ptr;
184  return *this;
185 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<typename T>
template<class C >
Ptr<T>& ora::Ptr< T >::operator= ( const Ptr< C > &  )
template<typename T>
template<class C >
ora::Ptr<T>& ora::Ptr< T >::operator= ( const Ptr< C > &  aPtr)
inline

Definition at line 189 of file Ptr.h.

References assert(), EnergyCorrector::c, funct::C, ora::Ptr< T >::isLoaded(), ora::Ptr< T >::loader(), ora::Ptr< T >::share(), and edmStreamStallGrapher::t.

189  {
190  C* c = 0; T* t(c); assert(t==0);
191  m_loader = aPtr.loader();
192  m_isLoaded = aPtr.isLoaded();
193  m_ptr = aPtr.share();
194  return *this;
195 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
assert(m_qm.get())
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
long double T
template<typename T>
template<class C >
bool ora::Ptr< T >::operator== ( const Ptr< C > &  aPtr) const
inline

Definition at line 101 of file Ptr.h.

References ora::Ptr< T >::address(), funct::C, and ora::Ptr< T >::m_ptr.

Referenced by ora::Ptr< T >::operator!=().

101  {
102  return m_ptr == static_cast<C*>(aPtr.address());
103  }
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
T * ora::Ptr< T >::ptr ( bool  throw_flag) const
inlineprivate

Definition at line 254 of file Ptr.h.

References ora::throwException().

254  {
255  if(!m_ptr.get()){
256  if(!m_loader.get()){
257  if(throwFlag) throwException("Loader is not installed.","Ptr::ptr()");
258  }
259  if(!m_isLoaded && m_loader.get()){
260  m_ptr.reset( static_cast<T*>(m_loader->load()));
261  m_isLoaded = true;
262  }
263  }
264  if(!m_ptr.get()){
265  if(throwFlag) throwException("Underlying pointer is null.","Ptr::ptr()");
266  }
267  return m_ptr.get();
268 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
void ora::Ptr< T >::reset ( void  )
inline

Definition at line 242 of file Ptr.h.

Referenced by MatrixReader.MatrixReader::__init__(), and MatrixReader.MatrixReader::showRaw().

242  {
243  m_ptr.reset();
244  m_loader.reset();
245  m_isLoaded = false;
246 }
boost::shared_ptr< IPtrLoader > m_loader
Definition: Ptr.h:138
bool m_isLoaded
Definition: Ptr.h:141
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135
template<class T >
boost::shared_ptr< T > & ora::Ptr< T >::share ( ) const
inline

Definition at line 222 of file Ptr.h.

Referenced by ora::Ptr< T >::cast(), and ora::Ptr< T >::operator=().

222  {
223  return m_ptr;
224 }
boost::shared_ptr< T > m_ptr
Definition: Ptr.h:135

Member Data Documentation

template<typename T>
bool ora::Ptr< T >::m_isLoaded
mutableprivate

Definition at line 141 of file Ptr.h.

Referenced by ora::Ptr< T >::isLoaded(), and ora::Ptr< T >::operator=().

template<typename T>
boost::shared_ptr<IPtrLoader> ora::Ptr< T >::m_loader
mutableprivate

Definition at line 138 of file Ptr.h.

Referenced by ora::Ptr< T >::loader(), and ora::Ptr< T >::operator=().

template<typename T>
boost::shared_ptr<T> ora::Ptr< T >::m_ptr
mutableprivate

Definition at line 135 of file Ptr.h.

Referenced by ora::Ptr< T >::operator=(), and ora::Ptr< T >::operator==().