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> class SmartDataStorePtr : public SmartDataObjectPtr {
45 public:
55  : SmartDataObjectPtr(LOADER::access(),pService,pRegistry,path), m_pObject(0)
56  {
57  }
62  : SmartDataObjectPtr( copy ), m_pObject(0)
63  {
64  }
65 
67  virtual ~SmartDataStorePtr() {
68  }
69 
72  m_pObject = dynamic_cast<TYPE*>(pObj);
73  return *this;
74  }
75 
78  m_pObject = dynamic_cast<TYPE*>(const_cast<DataObject*>(pObj));
79  return *this;
80  }
81 
83  SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) override {
84  this->m_pObject = dynamic_cast<TYPE*>(const_cast<SmartDataObjectPtr*>(&copy));
85  return *this;
86  }
87 
89  TYPE* ptr() {
90  return accessTypeSafeData();
91  }
92 
94  TYPE* operator->() {
95  return accessTypeSafeData();
96  }
97 
99  TYPE& operator*() {
100  TYPE* result = accessTypeSafeData();
101  return *result;
102  }
103 
105  operator TYPE*() {
106  return accessTypeSafeData();
107  }
108 
110  operator TYPE&() {
111  TYPE* result = accessTypeSafeData();
112  return *result;
113  }
114 
116  operator int() {
117  return 0 != accessTypeSafeData();
118  }
119 
121  bool operator !() {
122  return 0 == accessTypeSafeData();
123  }
124 
127  if ( 0 == m_pObject ) {
128  m_pObject = dynamic_cast<TYPE*>(accessData());
129  }
130  return m_pObject;
131  }
132 
133 protected:
135  mutable TYPE* m_pObject;
136 
137 };
138 
149 template <class A, class LDA, class B, class LDB>
151  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
152  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
153  return true; // Fine: Both objects exist
154  }
155  }
156  return false; // Tough luck: One is missing.
157 }
158 
169 template <class B, class LDB>
171  if ( test ) { // Test existence of the first object
172  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
173  return true; // Fine: Both objects exist
174  }
175  }
176  return false; // Tough luck: One is missing.
177 }
178 
189 template <class B, class LDB>
191  if ( test ) { // Test existence of the first object
192  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
193  return true; // Fine: Both objects exist
194  }
195  }
196  return false; // Tough luck: One is missing.
197 }
198 
213 template <class A, class LDA, class B, class LDB>
215  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
216  return true;
217  }
218  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
219  return true;
220  }
221  return false; // Tough luck: Both are missing.
222 }
223 
224 
235 template <class B, class LDB>
237  if ( test ) { // Test existence of the first object
238  return true;
239  }
240  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
241  return true; // Fine: Both objects exist
242  }
243  return false; // Tough luck: One is missing.
244 }
245 
256 template <class B, class LDB>
258  if ( test ) { // Test existence of the first object
259  return true;
260  }
261  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
262  return true; // Fine: Both objects exist
263  }
264  return false; // Tough luck: One is missing.
265 }
266 #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
bool access(const ContainedObject *from, ContainedObject **to)
Definition: KeyedObject.cpp:53
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.