Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SmartDataStorePtr.h
Go to the documentation of this file.
1 // ====================================================================
2 // SmartDataStorePtr.h
3 // --------------------------------------------------------------------
4 //
5 // Package : GaudiKernel ( The LHCb Offline System)
6 //
7 // Description: Implementation of a smart pointer class to access
8 // easily (and efficiently) data stores.
9 //
10 // Author : M.Frank
11 // ====================================================================
12 #ifndef GAUDIKERNEL_SMARTDATASTOREPTR_H
13 #define GAUDIKERNEL_SMARTDATASTOREPTR_H 1
14 
15 // Framework include files
17 
44 template <class TYPE, class LOADER>
46 public:
55  SmartDataStorePtr( IDataProviderSvc* pService, IRegistry* pRegistry, const std::string& path )
56  : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, path ), m_pObject( 0 ) {}
61 
63  virtual ~SmartDataStorePtr() {}
64 
67  m_pObject = dynamic_cast<TYPE*>( pObj );
68  return *this;
69  }
70 
73  m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
74  return *this;
75  }
76 
78  SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) override {
79  this->m_pObject = dynamic_cast<TYPE*>( const_cast<SmartDataObjectPtr*>( &copy ) );
80  return *this;
81  }
82 
84  TYPE* ptr() { return accessTypeSafeData(); }
85 
87  TYPE* operator->() { return accessTypeSafeData(); }
88 
90  TYPE& operator*() {
91  TYPE* result = accessTypeSafeData();
92  return *result;
93  }
94 
96  operator TYPE*() { return accessTypeSafeData(); }
97 
99  operator TYPE&() {
100  TYPE* result = accessTypeSafeData();
101  return *result;
102  }
103 
105  operator int() { return 0 != accessTypeSafeData(); }
106 
108  bool operator!() { return 0 == accessTypeSafeData(); }
109 
112  if ( 0 == m_pObject ) { m_pObject = dynamic_cast<TYPE*>( accessData() ); }
113  return m_pObject;
114  }
115 
116 protected:
118  mutable TYPE* m_pObject;
119 };
120 
131 template <class A, class LDA, class B, class LDB>
133  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
134  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
135  return true; // Fine: Both objects exist
136  }
137  }
138  return false; // Tough luck: One is missing.
139 }
140 
151 template <class B, class LDB>
153  if ( test ) { // Test existence of the first object
154  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
155  return true; // Fine: Both objects exist
156  }
157  }
158  return false; // Tough luck: One is missing.
159 }
160 
171 template <class B, class LDB>
173  if ( test ) { // Test existence of the first object
174  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
175  return true; // Fine: Both objects exist
176  }
177  }
178  return false; // Tough luck: One is missing.
179 }
180 
195 template <class A, class LDA, class B, class LDB>
197  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
198  return true;
199  }
200  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
201  return true;
202  }
203  return false; // Tough luck: Both are missing.
204 }
205 
216 template <class B, class LDB>
218  if ( test ) { // Test existence of the first object
219  return true;
220  }
221  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
222  return true; // Fine: Both objects exist
223  }
224  return false; // Tough luck: One is missing.
225 }
226 
237 template <class B, class LDB>
239  if ( test ) { // Test existence of the first object
240  return true;
241  }
242  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
243  return true; // Fine: Both objects exist
244  }
245  return false; // Tough luck: One is missing.
246 }
247 #endif // GAUDIKERNEL_SMARTDATASTOREPTR_H
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Data provider interface definition.
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
STL class.
TYPE * ptr()
Automatic conversion to data type.
DataObject * accessData()
Static Object retrieval method: must call specific function.
const std::string & path() const
Path name.
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
A small class used to access easily (and efficiently) data items residing in data stores...
A small class used to access easily (and efficiently) data items residing in data stores...
bool operator||(SmartDataStorePtr< A, LDA > &object_1, SmartDataStorePtr< B, LDB > &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartDataPtr<MCV...
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
SmartDataStorePtr(IDataProviderSvc *pService, IRegistry *pRegistry, const std::string &path)
Standard constructor: Construct an SmartDataStorePtr instance which is able to connect to a DataObjec...
bool operator&&(SmartDataStorePtr< A, LDA > &object_1, SmartDataStorePtr< B, LDB > &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartDataPtr<MCV...
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
TYPE * m_pObject
Pointer to data store object.
virtual ~SmartDataStorePtr()
Standard Destructor.
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct an copy of a SmartDataStorePtr instance.