The Gaudi Framework  v30r3 (a5ef0a68)
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 {
47 public:
56  SmartDataStorePtr( IDataProviderSvc* pService, IRegistry* pRegistry, const std::string& path )
57  : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, path ), m_pObject( 0 )
58  {
59  }
64 
66  virtual ~SmartDataStorePtr() {}
67 
70  {
71  m_pObject = dynamic_cast<TYPE*>( pObj );
72  return *this;
73  }
74 
77  {
78  m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
79  return *this;
80  }
81 
84  {
85  this->m_pObject = dynamic_cast<TYPE*>( const_cast<SmartDataObjectPtr*>( &copy ) );
86  return *this;
87  }
88 
90  TYPE* ptr() { return accessTypeSafeData(); }
91 
93  TYPE* operator->() { return accessTypeSafeData(); }
94 
96  TYPE& operator*()
97  {
98  TYPE* result = accessTypeSafeData();
99  return *result;
100  }
101 
103  operator TYPE*() { return accessTypeSafeData(); }
104 
106  operator TYPE&()
107  {
108  TYPE* result = accessTypeSafeData();
109  return *result;
110  }
111 
113  operator int() { return 0 != accessTypeSafeData(); }
114 
116  bool operator!() { return 0 == accessTypeSafeData(); }
117 
120  {
121  if ( 0 == m_pObject ) {
122  m_pObject = dynamic_cast<TYPE*>( accessData() );
123  }
124  return m_pObject;
125  }
126 
127 protected:
129  mutable TYPE* m_pObject;
130 };
131 
142 template <class A, class LDA, class B, class LDB>
144 {
145  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
146  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
147  return true; // Fine: Both objects exist
148  }
149  }
150  return false; // Tough luck: One is missing.
151 }
152 
163 template <class B, class LDB>
165 {
166  if ( test ) { // Test existence of the first object
167  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
168  return true; // Fine: Both objects exist
169  }
170  }
171  return false; // Tough luck: One is missing.
172 }
173 
184 template <class B, class LDB>
186 {
187  if ( test ) { // Test existence of the first object
188  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
189  return true; // Fine: Both objects exist
190  }
191  }
192  return false; // Tough luck: One is missing.
193 }
194 
209 template <class A, class LDA, class B, class LDB>
211 {
212  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
213  return true;
214  }
215  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
216  return true;
217  }
218  return false; // Tough luck: Both are missing.
219 }
220 
231 template <class B, class LDB>
233 {
234  if ( test ) { // Test existence of the first object
235  return true;
236  }
237  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
238  return true; // Fine: Both objects exist
239  }
240  return false; // Tough luck: One is missing.
241 }
242 
253 template <class B, class LDB>
255 {
256  if ( test ) { // Test existence of the first object
257  return true;
258  }
259  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
260  return true; // Fine: Both objects exist
261  }
262  return false; // Tough luck: One is missing.
263 }
264 #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.