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::UniqueRef< T > Class Template Reference

#include <UniqueRef.h>

Public Member Functions

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

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::UniqueRef< T >

Templated class for the persistency of associated objects. Same features as Ptr (lazy loading) + support of polymorhism .

Definition at line 13 of file UniqueRef.h.

Constructor & Destructor Documentation

template<class T >
ora::UniqueRef< T >::UniqueRef ( )

Definition at line 114 of file UniqueRef.h.

114  :
115  m_ptr(),m_loader(),m_isLoaded(false) {}
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
ora::UniqueRef< T >::UniqueRef ( T anObject)
explicit

Definition at line 117 of file UniqueRef.h.

117  :
118  m_ptr(anObject),m_loader(),m_isLoaded(true) {}
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
ora::UniqueRef< T >::UniqueRef ( const UniqueRef< T > &  aPtr)

Definition at line 120 of file UniqueRef.h.

120  :
121  m_ptr(aPtr.m_ptr),m_loader(aPtr.m_loader),m_isLoaded(false){
122 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
template<class C >
ora::UniqueRef< T >::UniqueRef ( const UniqueRef< C > &  aPtr)

Definition at line 125 of file UniqueRef.h.

References trackerHits::c, funct::C, and edmStreamStallGrapher::t.

125  :
126  m_ptr(aPtr.share()),m_loader(aPtr.loader()),m_isLoaded(aPtr.isLoaded()) {
127  // compile-time type checking
128  C* c = 0; T* t(c); assert(t==0);
129 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
long double T
template<class T >
ora::UniqueRef< T >::~UniqueRef ( )
virtual

Definition at line 131 of file UniqueRef.h.

131  {
132 }

Member Function Documentation

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

Definition at line 184 of file UniqueRef.h.

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

184  {
185  return m_ptr.get();
186 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
template<typename T>
template<class C >
UniqueRef<T>& ora::UniqueRef< T >::cast ( const UniqueRef< C > &  )
template<typename T>
template<class C >
ora::UniqueRef<T>& ora::UniqueRef< T >::cast ( const UniqueRef< C > &  aPtr)

Definition at line 159 of file UniqueRef.h.

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

159  {
160  reset();
161  m_loader = aPtr.loader();
162  m_ptr = boost::dynamic_pointer_cast(aPtr.share());
163  m_isLoaded = aPtr.isLoaded();
164  return *this;
165 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
void reset()
Definition: UniqueRef.h:202
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
T * ora::UniqueRef< T >::get ( void  ) const
template<typename T>
bool ora::UniqueRef< T >::isLoaded ( ) const
inline

Definition at line 89 of file UniqueRef.h.

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

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

89  {
90  return m_isLoaded;
91  }
template<typename T>
boost::shared_ptr<IPtrLoader>& ora::UniqueRef< T >::loader ( ) const
inline

Definition at line 84 of file UniqueRef.h.

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

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

84  {
85  return m_loader;
86  }
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
ora::UniqueRef< T >::operator bool ( ) const

Definition at line 194 of file UniqueRef.h.

194  {
195  return ptr(false);
196 }
T * ptr(bool throw_flag) const
Definition: UniqueRef.h:208
template<class T >
bool ora::UniqueRef< T >::operator! ( ) const

Definition at line 198 of file UniqueRef.h.

198  {
199  return ptr(false)==0;
200 }
T * ptr(bool throw_flag) const
Definition: UniqueRef.h:208
template<typename T>
template<class C >
bool ora::UniqueRef< T >::operator!= ( const UniqueRef< C > &  aPtr) const
inline

Definition at line 74 of file UniqueRef.h.

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

74  {
75  return !(this->operator==(aPtr));
76  }
bool operator==(const UniqueRef< C > &aPtr) const
Definition: UniqueRef.h:70
template<class T >
T & ora::UniqueRef< T >::operator* ( ) const

Definition at line 171 of file UniqueRef.h.

171  {
172  return *ptr(true);
173 }
T * ptr(bool throw_flag) const
Definition: UniqueRef.h:208
template<class T >
T * ora::UniqueRef< T >::operator-> ( ) const

Definition at line 167 of file UniqueRef.h.

167  {
168  return ptr(true);
169 }
T * ptr(bool throw_flag) const
Definition: UniqueRef.h:208
template<class T >
ora::UniqueRef< T > & ora::UniqueRef< T >::operator= ( T aPtr)

Definition at line 134 of file UniqueRef.h.

References reset().

134  {
135  reset();
136  m_ptr.reset(aPtr);
137  m_isLoaded = true;
138  return *this;
139 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
void reset()
Definition: UniqueRef.h:202
template<class T >
ora::UniqueRef< T > & ora::UniqueRef< T >::operator= ( const UniqueRef< T > &  aPtr)

Definition at line 141 of file UniqueRef.h.

References ora::UniqueRef< T >::m_isLoaded, ora::UniqueRef< T >::m_loader, ora::UniqueRef< T >::m_ptr, and reset().

141  {
142  reset();
143  m_loader = aPtr.m_loader;
144  m_ptr = aPtr.m_ptr;
145  m_isLoaded = aPtr.m_isLoaded;
146  return *this;
147 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
void reset()
Definition: UniqueRef.h:202
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<typename T>
template<class C >
UniqueRef<T>& ora::UniqueRef< T >::operator= ( const UniqueRef< C > &  )
template<typename T>
template<class C >
ora::UniqueRef<T>& ora::UniqueRef< T >::operator= ( const UniqueRef< C > &  aPtr)

Definition at line 150 of file UniqueRef.h.

References trackerHits::c, funct::C, ora::UniqueRef< T >::isLoaded(), ora::UniqueRef< T >::loader(), reset(), ora::UniqueRef< T >::share(), and edmStreamStallGrapher::t.

150  {
151  C* c = 0; T* t(c); assert(t==0);
152  reset();
153  m_loader = aPtr.loader();
154  m_ptr = aPtr.share();
155  m_isLoaded = aPtr.isLoaded();
156  return *this;
157 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
void reset()
Definition: UniqueRef.h:202
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
long double T
template<typename T>
template<class C >
bool ora::UniqueRef< T >::operator== ( const UniqueRef< C > &  aPtr) const
inline

Definition at line 70 of file UniqueRef.h.

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

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

70  {
71  return m_ptr == static_cast<C*>(aPtr.address());
72  }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
template<class T >
T * ora::UniqueRef< T >::ptr ( bool  throw_flag) const
private

Definition at line 208 of file UniqueRef.h.

References ora::throwException().

208  {
209  if(!m_ptr.get()){
210  if(!m_loader.get()){
211  if(throwFlag) throwException("Loader is not installed.",
212  "UniqueRef::ptr()");
213  }
214  if(!m_isLoaded && m_loader.get()){
215  m_ptr.reset( static_cast<T*>(m_loader->load()));
216  m_isLoaded = true;
217  }
218  }
219  if(!m_ptr.get()){
220  if(throwFlag) throwException("Underlying pointer is null.",
221  "UniqueRef::ptr()");
222  }
223  return m_ptr.get();
224 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
template<class T >
void ora::UniqueRef< T >::reset ( void  )

Definition at line 202 of file UniqueRef.h.

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

202  {
203  m_ptr.reset();
204  m_loader.reset();
205  m_isLoaded = false;
206 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
boost::shared_ptr< IPtrLoader > m_loader
Definition: UniqueRef.h:104
template<class T >
boost::shared_ptr< T > & ora::UniqueRef< T >::share ( ) const
inline

Definition at line 180 of file UniqueRef.h.

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

180  {
181  return m_ptr;
182 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101
template<class T >
const std::type_info * ora::UniqueRef< T >::typeInfo ( ) const

Definition at line 188 of file UniqueRef.h.

References run_regression::ret.

188  {
189  const std::type_info* ret = 0;
190  if(m_ptr) ret = &typeid(*m_ptr);
191  return ret;
192 }
boost::shared_ptr< T > m_ptr
Definition: UniqueRef.h:101

Member Data Documentation

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

Definition at line 107 of file UniqueRef.h.

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

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

Definition at line 104 of file UniqueRef.h.

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

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

Definition at line 101 of file UniqueRef.h.

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