| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
16 #include "GaudiKernel/SmartDataObjectPtr.h"
17
44 template <class TYPE, class LOADER>
45 class SmartDataStorePtr : public SmartDataObjectPtr
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 }
63 SmartDataStorePtr( const SmartDataObjectPtr& copy ) : SmartDataObjectPtr( copy ), m_pObject( 0 ) {}
64
66 virtual ~SmartDataStorePtr() {}
67
69 SmartDataStorePtr& operator=( DataObject* pObj )
70 {
71 m_pObject = dynamic_cast<TYPE*>( pObj );
72 return *this;
73 }
74
76 SmartDataStorePtr& operator=( const DataObject* pObj )
77 {
78 m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
79 return *this;
80 }
81
83 SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) override
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
119 TYPE* accessTypeSafeData()
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>
143 bool operator&&( SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2 )
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>
164 bool operator&&( bool test, SmartDataStorePtr<B, LDB>& object )
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>
185 bool operator&&( SmartDataStorePtr<B, LDB>& object, bool test )
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>
210 bool operator||( SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2 )
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>
232 bool operator||( bool test, SmartDataStorePtr<B, LDB>& object )
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>
254 bool operator||( SmartDataStorePtr<B, LDB>& object, bool test )
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
SmartDataStorePtr::accessTypeSafeData
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
Definition: SmartDataStorePtr.h:119
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:69
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:46
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
Definition: SmartDataStorePtr.h:83
std::string
STL class.
SmartDataStorePtr::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:90
compareRootHistos.test
string test
Definition: compareRootHistos.py:15
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:91
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:76
SmartDataStorePtr::operator*
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:96
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
Objects::access
bool access(const ContainedObject *from, ContainedObject **to)
Definition: KeyedObject.cpp:55
SmartDataStorePtr::operator->
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:93
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:76
SmartDataObjectPtr
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataObjectPtr.h:32
SmartDataStorePtr
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataStorePtr.h:45
operator||
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...
Definition: SmartDataStorePtr.h:210
SmartDataStorePtr::operator!
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
Definition: SmartDataStorePtr.h:116
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(IDataProviderSvc *pService, IRegistry *pRegistry, const std::string &path)
Standard constructor: Construct an SmartDataStorePtr instance which is able to connect to a DataObjec...
Definition: SmartDataStorePtr.h:56
operator&&
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...
Definition: SmartDataStorePtr.h:143
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
SmartDataStorePtr::m_pObject
TYPE * m_pObject
Pointer to data store object.
Definition: SmartDataStorePtr.h:129
SmartDataStorePtr::~SmartDataStorePtr
virtual ~SmartDataStorePtr()
Standard Destructor.
Definition: SmartDataStorePtr.h:66
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct an copy of a SmartDataStorePtr instance.
Definition: SmartDataStorePtr.h:63
SmartDataObjectPtr.h