| The Gaudi Framework v32r1 (f65d50dc)

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 public:
55 SmartDataStorePtr( IDataProviderSvc* pService, IRegistry* pRegistry, const std::string& path )
56 : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, path ), m_pObject( 0 ) {}
60 SmartDataStorePtr( const SmartDataObjectPtr& copy ) : SmartDataObjectPtr( copy ), m_pObject( 0 ) {}
61
63 virtual ~SmartDataStorePtr() {}
64
66 SmartDataStorePtr& operator=( DataObject* pObj ) {
67 m_pObject = dynamic_cast<TYPE*>( pObj );
68 return *this;
69 }
70
72 SmartDataStorePtr& operator=( const DataObject* pObj ) {
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
111 TYPE* accessTypeSafeData() {
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>
132 bool operator&&( SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2 ) {
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>
152 bool operator&&( bool test, SmartDataStorePtr<B, LDB>& object ) {
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>
172 bool operator&&( SmartDataStorePtr<B, LDB>& object, bool test ) {
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>
196 bool operator||( SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2 ) {
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>
217 bool operator||( bool test, SmartDataStorePtr<B, LDB>& object ) {
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>
238 bool operator||( SmartDataStorePtr<B, LDB>& object, bool test ) {
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
SmartDataStorePtr::accessTypeSafeData
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
Definition: SmartDataStorePtr.h:111
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:132
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:66
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:43
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
Definition: SmartDataStorePtr.h:78
std::string
STL class.
SmartDataStorePtr::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:84
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:71
compareRootHistos.test
string test
Definition: compareRootHistos.py:15
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:86
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
SmartDataStorePtr::operator->
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:87
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:72
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:196
SmartDataStorePtr::operator!
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
Definition: SmartDataStorePtr.h:108
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:55
SmartDataStorePtr::operator *
TYPE & operator *()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:90
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:118
SmartDataStorePtr::~SmartDataStorePtr
virtual ~SmartDataStorePtr()
Standard Destructor.
Definition: SmartDataStorePtr.h:63
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct an copy of a SmartDataStorePtr instance.
Definition: SmartDataStorePtr.h:60
SmartDataObjectPtr.h