The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
SmartDataStorePtr.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14
41template <class TYPE, class LOADER>
43public:
52 SmartDataStorePtr( IDataProviderSvc* pService, IRegistry* pRegistry, std::string path )
53 : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, std::move( path ) ), m_pObject( nullptr ) {}
54
57 SmartDataStorePtr( const SmartDataObjectPtr& copy ) : SmartDataObjectPtr( copy ), m_pObject( nullptr ) {}
58
60 virtual ~SmartDataStorePtr() = default;
61
64 m_pObject = dynamic_cast<TYPE*>( pObj );
65 return *this;
66 }
67
70 m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
71 return *this;
72 }
73
76 this->m_pObject = dynamic_cast<TYPE*>( const_cast<SmartDataObjectPtr*>( &copy ) );
77 return *this;
78 }
79
81 TYPE* ptr() { return accessTypeSafeData(); }
82
84 TYPE* operator->() { return accessTypeSafeData(); }
85
87 TYPE& operator*() {
88 TYPE* result = accessTypeSafeData();
89 return *result;
90 }
91
93 operator TYPE*() { return accessTypeSafeData(); }
94
96 operator TYPE&() {
97 TYPE* result = accessTypeSafeData();
98 return *result;
99 }
100
102 operator int() { return 0 != accessTypeSafeData(); }
103
105 bool operator!() { return 0 == accessTypeSafeData(); }
106
109 if ( 0 == m_pObject ) { m_pObject = dynamic_cast<TYPE*>( accessData() ); }
110 return m_pObject;
111 }
112
113protected:
115 mutable TYPE* m_pObject;
116};
117
128template <class A, class LDA, class B, class LDB>
130 if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
131 if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
132 return true; // Fine: Both objects exist
133 }
134 }
135 return false; // Tough luck: One is missing.
136}
137
148template <class B, class LDB>
149bool operator&&( bool test, SmartDataStorePtr<B, LDB>& object ) {
150 if ( test ) { // Test existence of the first object
151 if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
152 return true; // Fine: Both objects exist
153 }
154 }
155 return false; // Tough luck: One is missing.
156}
157
168template <class B, class LDB>
169bool operator&&( SmartDataStorePtr<B, LDB>& object, bool test ) {
170 if ( test ) { // Test existence of the first object
171 if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
172 return true; // Fine: Both objects exist
173 }
174 }
175 return false; // Tough luck: One is missing.
176}
177
192template <class A, class LDA, class B, class LDB>
194 if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
195 return true;
196 }
197 if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
198 return true;
199 }
200 return false; // Tough luck: Both are missing.
201}
202
213template <class B, class LDB>
214bool operator||( bool test, SmartDataStorePtr<B, LDB>& object ) {
215 if ( test ) { // Test existence of the first object
216 return true;
217 }
218 if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
219 return true; // Fine: Both objects exist
220 }
221 return false; // Tough luck: One is missing.
222}
223
234template <class B, class LDB>
235bool operator||( SmartDataStorePtr<B, LDB>& object, bool test ) {
236 if ( test ) { // Test existence of the first object
237 return true;
238 }
239 if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
240 return true; // Fine: Both objects exist
241 }
242 return false; // Tough luck: One is missing.
243}
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||(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:37
Data provider interface definition.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
const std::string & path() const
Path name.
SmartDataObjectPtr(AccessFunction access, IDataProviderSvc *pService, IRegistry *pDir, std::string path)
Standard constructor: Construct an SmartDataObjectPtr instance.
DataObject * accessData()
Static Object retrieval method: must call specific function.
A small class used to access easily (and efficiently) data items residing in data stores.
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
virtual ~SmartDataStorePtr()=default
Standard Destructor.
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct a copy of a SmartDataStorePtr instance.
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
SmartDataStorePtr(IDataProviderSvc *pService, IRegistry *pRegistry, std::string path)
Standard constructor: Construct an SmartDataStorePtr instance which is able to connect to a DataObjec...
TYPE * ptr()
Automatic conversion to data type.
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
TYPE * m_pObject
Pointer to data store object.
STL namespace.