| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# SmartDataStorePtr.h

Go to the documentation of this file.

    00001 //      ====================================================================
    00002 //      SmartDataStorePtr.h
    00003 //      --------------------------------------------------------------------
    00004 //
    00005 //      Package    : GaudiKernel ( The LHCb Offline System)
    00006 //
    00007 //  Description: Implementation of a smart pointer class to access
    00008 //               easily (and efficiently) data stores.
    00009 //
    00010 //      Author     : M.Frank
    00011 //      ====================================================================
    00012 #ifndef GAUDIKERNEL_SMARTDATASTOREPTR_H
    00013 #define GAUDIKERNEL_SMARTDATASTOREPTR_H 1
    00014
    00015 // Framework include files
    00016 #include "GaudiKernel/SmartDataObjectPtr.h"
    00017
    00044 template <class TYPE, class LOADER> class SmartDataStorePtr : public SmartDataObjectPtr   {
    00045 public:
    00054   SmartDataStorePtr(IDataProviderSvc* pService, IRegistry* pRegistry, const std::string& path)
    00055     : SmartDataObjectPtr(LOADER::access(),pService,pRegistry,path), m_pObject(0)
    00056   {
    00057   }
    00061   SmartDataStorePtr(const SmartDataObjectPtr& copy)
    00062     : SmartDataObjectPtr( copy ), m_pObject(0)
    00063   {
    00064   }
    00065
    00067   virtual ~SmartDataStorePtr()  {
    00068   }
    00069
    00071   SmartDataStorePtr& operator=( DataObject* pObj )    {
    00072     m_pObject = dynamic_cast<TYPE*>(pObj);
    00073     return *this;
    00074   }
    00075
    00077   SmartDataStorePtr& operator=( const DataObject* pObj )    {
    00078     m_pObject = dynamic_cast<TYPE*>(const_cast<DataObject*>(pObj));
    00079     return *this;
    00080   }
    00081
    00083   SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) {
    00084     this->m_pObject = dynamic_cast<TYPE*>(const_cast<SmartDataObjectPtr*>(&copy));
    00085     return *this;
    00086   }
    00087
    00089   TYPE* ptr()    {
    00090     return accessTypeSafeData();
    00091   }
    00092
    00094   TYPE* operator->()    {
    00095     return accessTypeSafeData();
    00096   }
    00097
    00099   TYPE& operator*()    {
    00100     TYPE* result = accessTypeSafeData();
    00101     return *result;
    00102   }
    00103
    00105   operator TYPE*()    {
    00106     return accessTypeSafeData();
    00107   }
    00108
    00110   operator TYPE&()    {
    00111     TYPE* result = accessTypeSafeData();
    00112     return *result;
    00113   }
    00114
    00116   operator int()   {
    00117     return 0 != accessTypeSafeData();
    00118   }
    00119
    00121   bool operator !()   {
    00122     return 0 == accessTypeSafeData();
    00123   }
    00124
    00126   TYPE* accessTypeSafeData()     {
    00127     if ( 0 == m_pObject )   {
    00128       m_pObject = dynamic_cast<TYPE*>(accessData());
    00129     }
    00130     return m_pObject;
    00131   }
    00132
    00133 protected:
    00135   mutable TYPE*     m_pObject;
    00136
    00137 };
    00138
    00149 template <class A, class LDA, class B, class LDB>
    00150 bool operator&& (SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2)    {
    00151   if ( 0 != object_1.accessTypeSafeData() )    {     // Test existence of the first object
    00152     if ( 0 != object_2.accessTypeSafeData() )    {   // Test existence of the second object
    00153       return true;                                   // Fine: Both objects exist
    00154     }
    00155   }
    00156   return false;                                      // Tough luck: One is missing.
    00157 }
    00158
    00169 template <class B, class LDB>
    00170 bool operator&& (bool test, SmartDataStorePtr<B, LDB>& object)    {
    00171   if ( test )    {                                   // Test existence of the first object
    00172     if ( 0 != object.accessTypeSafeData() )    {     // Test existence of the second object
    00173       return true;                                   // Fine: Both objects exist
    00174     }
    00175   }
    00176   return false;                                      // Tough luck: One is missing.
    00177 }
    00178
    00189 template <class B, class LDB>
    00190 bool operator&& (SmartDataStorePtr<B, LDB>& object, bool test)    {
    00191   if ( test )    {                                   // Test existence of the first object
    00192     if ( 0 != object.accessTypeSafeData() )    {     // Test existence of the second object
    00193       return true;                                   // Fine: Both objects exist
    00194     }
    00195   }
    00196   return false;                                      // Tough luck: One is missing.
    00197 }
    00198
    00213 template <class A, class LDA, class B, class LDB>
    00214 bool operator|| (SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2)    {
    00215   if ( 0 != object_1.accessTypeSafeData() )    {     // Test existence of the first object
    00216     return true;
    00217   }
    00218   if ( 0 != object_2.accessTypeSafeData() )    {     // Test existence of the second object
    00219     return true;
    00220   }
    00221   return false;                                      // Tough luck: Both are missing.
    00222 }
    00223
    00224
    00235 template <class B, class LDB>
    00236 bool operator|| (bool test, SmartDataStorePtr<B, LDB>& object)    {
    00237   if ( test )    {                                 // Test existence of the first object
    00238     return true;
    00239   }
    00240   if ( 0 != object.accessTypeSafeData() )    {     // Test existence of the second object
    00241     return true;                                   // Fine: Both objects exist
    00242   }
    00243   return false;                                    // Tough luck: One is missing.
    00244 }
    00245
    00256 template <class B, class LDB>
    00257 bool operator|| (SmartDataStorePtr<B, LDB>& object, bool test)    {
    00258   if ( test )    {                                 // Test existence of the first object
    00259     return true;
    00260   }
    00261   if ( 0 != object.accessTypeSafeData() )    {     // Test existence of the second object
    00262     return true;                                   // Fine: Both objects exist
    00263   }
    00264   return false;                                    // Tough luck: One is missing.
    00265 }
    00266 #endif // GAUDIKERNEL_SMARTDATASTOREPTR_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines