CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ora::Ptr< T > Class Template Reference

#include <Ptr.h>

List of all members.

Public Member Functions

void * address () const
template<class C >
Ptr< T > & cast (const Ptr< C > &)
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
template<class C >
Ptr< T > & operator= (const Ptr< C > &)
Ptr< T > & operator= (const Ptr< T > &)
Ptr< T > & operator= (T *)
template<class C >
bool operator== (const Ptr< C > &aPtr) const
 Ptr (const Ptr< T > &)
 Ptr ()
 Ptr (T *anObject)
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.

                      :
  m_ptr(),m_loader(),m_isLoaded(false) {}
template<class T >
ora::Ptr< T >::Ptr ( T anObject) [inline, explicit]

Definition at line 152 of file Ptr.h.

                                 :
  m_ptr(anObject),m_loader(),m_isLoaded(true) {}
template<class T >
ora::Ptr< T >::Ptr ( const Ptr< T > &  aPtr) [inline]

Definition at line 156 of file Ptr.h.

                                        :
  m_ptr(aPtr.m_ptr),m_loader(aPtr.m_loader),m_isLoaded(false){
}
template<class T >
template<class C >
ora::Ptr< T >::Ptr ( const Ptr< C > &  aPtr) [inline]

Definition at line 162 of file Ptr.h.

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

                                        :
  m_ptr(aPtr.share()),m_loader(aPtr.loader()),m_isLoaded(aPtr.isLoaded()) {
  // compile-time type checking
  C* c = 0; T* t(c); assert(t==0);
}
template<class T >
ora::Ptr< T >::~Ptr ( ) [inline, virtual]

Definition at line 169 of file Ptr.h.

                       {
}

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==().

                                       {
  return m_ptr.get();  
}
template<class 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().

                                                   {
  m_loader = aPtr.loader();
  m_ptr = boost::dynamic_pointer_cast( aPtr.share());
  m_isLoaded = aPtr.isLoaded();
  return *this;  
}
template<class T >
T * ora::Ptr< T >::get ( void  ) const [inline]

Definition at line 217 of file Ptr.h.

                                {
  return ptr(false);  
}
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=().

                          {
      return m_isLoaded;
    }
template<class T >
void ora::Ptr< T >::load ( ) const [inline]

Definition at line 249 of file Ptr.h.

                                  {
  ptr( false );
}
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=().

                                                {
      return m_loader;
    }
template<class T >
ora::Ptr< T >::operator bool ( ) const [inline]

Definition at line 232 of file Ptr.h.

                                      {
  return ptr(false);
}
template<class T >
bool ora::Ptr< T >::operator! ( ) const [inline]

Definition at line 237 of file Ptr.h.

                                       {
  return ptr(false)==0;
}
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==().

                                              {
      return !(this->operator==(aPtr));     
    }
template<class T >
T & ora::Ptr< T >::operator* ( ) const [inline]

Definition at line 212 of file Ptr.h.

                                     {
  return *ptr(true);
}
template<class T >
T * ora::Ptr< T >::operator-> ( ) const [inline]

Definition at line 207 of file Ptr.h.

                                      {
  return ptr(true);
}
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.

                                                        {
  m_loader = aPtr.m_loader;
  m_isLoaded = aPtr.m_isLoaded;
  m_ptr = aPtr.m_ptr;
  return *this;  
}
template<class T >
ora::Ptr< T > & ora::Ptr< T >::operator= ( T aPtr) [inline]

Definition at line 173 of file Ptr.h.

References ora::Ptr< T >::reset().

                                              {
  m_ptr.reset(aPtr);
  m_isLoaded = true;
  return *this;
}
template<class 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 trackerHits::c, funct::C, ora::Ptr< T >::isLoaded(), ora::Ptr< T >::loader(), ora::Ptr< T >::share(), and lumiQTWidget::t.

                                                        {
  C* c = 0; T* t(c); assert(t==0);
  m_loader = aPtr.loader();
  m_isLoaded = aPtr.isLoaded();
  m_ptr = aPtr.share();
  return *this;
}
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!=().

                                              {
      return m_ptr == static_cast<C*>(aPtr.address());
    }
template<class T >
T * ora::Ptr< T >::ptr ( bool  throw_flag) const [inline, private]

Definition at line 254 of file Ptr.h.

References ora::throwException().

                                             {
  if(!m_ptr.get()){
    if(!m_loader.get()){
      if(throwFlag) throwException("Loader is not installed.","Ptr::ptr()");
    }
    if(!m_isLoaded && m_loader.get()){
      m_ptr.reset( static_cast<T*>(m_loader->load()));
      m_isLoaded = true;
    }
  }
  if(!m_ptr.get()){
    if(throwFlag) throwException("Underlying pointer is null.","Ptr::ptr()");    
  }
  return m_ptr.get();
}
template<class T >
void ora::Ptr< T >::reset ( void  ) [inline]

Definition at line 242 of file Ptr.h.

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

                            {
  m_ptr.reset();
  m_loader.reset();
  m_isLoaded = false;
}
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=().

                                                  {
  return m_ptr;
}

Member Data Documentation

template<typename T>
bool ora::Ptr< T >::m_isLoaded [mutable, private]

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 [mutable, private]

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 [mutable, private]

Definition at line 135 of file Ptr.h.

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