| The Gaudi Framework v27r1

- 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> class SmartDataStorePtr : public SmartDataObjectPtr {
45 public:
54 SmartDataStorePtr(IDataProviderSvc* pService, IRegistry* pRegistry, const std::string& path)
55 : SmartDataObjectPtr(LOADER::access(),pService,pRegistry,path), m_pObject(0)
56 {
57 }
61 SmartDataStorePtr(const SmartDataObjectPtr& copy)
62 : SmartDataObjectPtr( copy ), m_pObject(0)
63 {
64 }
65
67 virtual ~SmartDataStorePtr() {
68 }
69
71 SmartDataStorePtr& operator=( DataObject* pObj ) {
72 m_pObject = dynamic_cast<TYPE*>(pObj);
73 return *this;
74 }
75
77 SmartDataStorePtr& operator=( const DataObject* pObj ) {
78 m_pObject = dynamic_cast<TYPE*>(const_cast<DataObject*>(pObj));
79 return *this;
80 }
81
83 SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) {
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
126 TYPE* accessTypeSafeData() {
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>
150 bool operator&& (SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2) {
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>
170 bool operator&& (bool test, SmartDataStorePtr<B, LDB>& object) {
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>
190 bool operator&& (SmartDataStorePtr<B, LDB>& object, bool test) {
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>
214 bool operator|| (SmartDataStorePtr<A, LDA>& object_1, SmartDataStorePtr<B, LDB>& object_2) {
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>
236 bool operator|| (bool test, SmartDataStorePtr<B, LDB>& object) {
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>
257 bool operator|| (SmartDataStorePtr<B, LDB>& object, bool test) {
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
SmartDataStorePtr::accessTypeSafeData
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
Definition: SmartDataStorePtr.h:126
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:71
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
std::string
STL class.
SmartDataStorePtr::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:89
compareRootHistos.test
string test
Definition: compareRootHistos.py:15
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:103
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:78
SmartDataStorePtr::operator*
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:99
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:53
SmartDataStorePtr::operator->
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:94
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:77
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:44
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy)
unhides assignment operator of base class
Definition: SmartDataStorePtr.h:83
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
Definition: SmartDataStorePtr.h:214
SmartDataStorePtr::operator!
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr(...) ) {}
Definition: SmartDataStorePtr.h:121
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:54
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
Definition: SmartDataStorePtr.h:150
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:135
SmartDataStorePtr::~SmartDataStorePtr
virtual ~SmartDataStorePtr()
Standard Destructor.
Definition: SmartDataStorePtr.h:67
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct an copy of a SmartDataStorePtr instance.
Definition: SmartDataStorePtr.h:61
SmartDataObjectPtr.h