| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

RefTable.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_REFTABLE_H
2 #define GAUDIKERNEL_REFTABLE_H 1
3
4
5 // Include files
6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/DataObject.h"
8 #include "GaudiKernel/StreamBuffer.h"
9 #include "GaudiKernel/SmartRefVector.h"
10 #include "GaudiKernel/SmartRef.h"
11 #include "GaudiKernel/HashMap.h" // Cannot use maps through sharable images....
12
13 // Externals
14 static const CLID CLID_RefTable1to1 = 300;
15 static const CLID CLID_RefTable1toN = 301;
16
17
18 //------------------------------------------------------------------------------
19 //
20 // Implementation and definition of template classes
21 // RefTableBase, RefTable1to1, RefTable1toN
22 //
23 // Author : Markus Frank
24 //
25 //------------------------------------------------------------------------------
45 template <class FROM, class MAPENTRY> class RefTableBase : public DataObject {
46 public:
47 // Type of the key
48 typedef FROM KeyType;
49 // Type of map entries
50 typedef MAPENTRY EntryType;
51 // My own type
52 typedef RefTableBase<FROM, EntryType> BaseType;
56 typedef GaudiUtils::HashMap< const void* , EntryType > TableType;
58 typedef TableType::iterator iterator;
60 typedef TableType::const_iterator const_iterator;
62 CLID m_clid;
63 private:
65 TableType m_table;
70 SmartRef<KeyType> m_fromRef;
71
72 protected:
74 bool insertMapElement ( const KeyType* from, EntryType& to ) {
75 return m_table.insert( from, to );
76 }
78 EntryType* i_reference(const KeyType* from) {
79 auto i = m_table.find( from );
80 return i != 0 ? &(i->second) : nullptr;
81 }
83 const EntryType* i_reference(const KeyType* from) const {
84 auto i = m_table.find( from );
85 return i != m_table.end() ? &(i->second) : nullptr;
86 }
87
88 public:
90 RefTableBase(const CLID& clid, int len) : m_clid(clid), m_table(len) {
91 }
93 virtual ~RefTableBase() = default;
95 virtual void clear() {
96 m_table.clear();
97 }
99 iterator begin() {
100 return m_table.begin();
101 }
103 const_iterator begin() const {
104 return m_table.begin();
105 }
107 iterator end() {
108 return m_table.end();
109 }
111 const_iterator end() const {
112 return m_table.end();
113 }
115 long size() const {
116 return m_table.size();
117 }
119 void reserve(int len) {
120 m_table.reserve(len);
121 }
123 virtual StreamBuffer& serialize( StreamBuffer& s ) const {
124 DataObject::serialize(s) << m_table.size();
125 //for (TableType::const_iterator i = m_table.begin(), stop = m_table.end(); i != stop; i++ ) {
126 // SmartRef<KeyType> fromRef;
127 // fromRef = (KeyType*)(*i).first;
128 // s << fromRef(this);
129 // s << (*i).second(this);
130 //}
131 return s;
132 }
134 virtual StreamBuffer& serialize( StreamBuffer& s ) {
135 long siz;
136 DataObject::serialize(s) >> siz;
137 m_table.reserve(siz);
138 //for ( long i = 0; i < siz; i++ ) {
139 // SmartRef<KeyType> fromRef;
140 // EntryType entry;
141 // s >> fromRef(this);
142 // s >> entry(this);
143 // insertMapElement( fromRef, entry);
144 //}
145 return s;
146 }
147 };
148
149 template <class FROM, class TO> class RefTable1to1
150 : public RefTableBase< FROM , SmartRef<TO> > {
151 public:
153 RefTable1to1 (const CLID& clid, int len=16)
154 : RefTableBase< FROM , SmartRef<TO> >(clid, len)
155 {
156 }
158 ~RefTable1to1() override = default;
159
161 virtual const CLID& clID() const {
162 return m_clid;
163 }
165 bool insert ( const FROM* from, TO* to ) {
166 return insertMapElement(from, EntryType(to));
167 }
169 bool insert ( const FROM* from, const EntryType& to) {
170 // We MUST check the environment of the smart pointer!
171 if ( 0 != to.data() || StreamBuffer::INVALID != to.hintID() ) {
172 return insertMapElement(from, EntryType(to));
173 }
174 return false;
175 }
177 TO* reference(const FROM* from) {
178 EntryType* e = i_reference(from);
179 return (0 == e) ? 0 : (*e);
180 }
181
183 const TO* reference(const FROM* from) const {
184 auto e = i_reference(from);
185 return e ? *e : nullptr;
186 }
187
189 bool isReferenced(const FROM* from, const TO* to ) const {
190 auto e = i_reference(from);
191 return e && ( *e == to );
192 }
194 bool isReferenced(const FROM* from, const EntryType& to ) {
195 const EntryType* e = i_reference(from);
196 return assoc && (*e!=to) && (e->target()==to.target());
197 }
198 };
199
200 template <class FROM, class TO> class RefTable1toN
201 : public RefTableBase< FROM , SmartRefVector<TO> > {
202 public:
204 RefTable1toN (const CLID& clid, int len=16)
205 : RefTableBase< FROM , SmartRefVector<TO> >(clid, len) {
206 }
208 ~RefTable1toN() override = default;
209
211 virtual const CLID& clID() const {
212 return m_clid;
213 }
215 bool insert ( const FROM* from, TO* to) {
216 EntryType* entry = i_reference(from);
217 if ( 0 == entry ) {
218 bool result = insertMapElement(from, EntryType());
219 EntryType* newEntry = i_reference(from);
220 if ( !( 0 == newEntry) ) {
221 newEntry->push_back( SmartRef<TO>(to) );
222 return true;
223 }
224 return false;
225 }
226 entry->push_back( SmartRef<TO>(to) );
227 return true;
228 }
230 bool insert ( const FROM* from, const SmartRef<TO>& to) {
231 EntryType* entry = i_reference(from);
232 if ( 0 == entry ) {
233 bool result = insertMapElement(from, EntryType());
234 EntryType* newEntry = i_reference(from);
235 if ( !(0 == newEntry) ) {
236 newEntry->push_back( to );
237 return true;
238 }
239 return false;
240 }
241 entry->push_back( to );
242 return true;
243 }
245 bool insert ( const FROM* from, const EntryType& to) {
246 return insertMapElement(from, const_cast<EntryType&>(to));
247 }
249 EntryType& reference(const FROM* from) {
250 static EntryType empty;
251 EntryType* e = i_reference(from);
252 return e ? *e : empty;
253 }
255 const EntryType& reference(const FROM* from) const {
256 static const EntryType empty;
257 EntryType* e = i_reference(from);
258 return e ? *e : empty;
259 }
261 bool isReferenced(const FROM* from, const EntryType& to ) {
262 auto e = i_reference(from);
263 return e && ( *e == to );
264 }
266 bool isReferenced(const FROM* from, const TO* to ) {
267 return isReferenced(from, SmartRef<TO>(to));
268 }
270 bool isReferenced(const FROM* from, const SmartRef<TO>& to ) {
271 const EntryType* e = i_reference(from);
272 return assoc && std::find(e->begin(), e->end(), to) != e->end();
273 }
274 };
275
276
277 #endif // GAUDIKERNEL_REFTABLE_H
278
RefTableBase::m_clid
CLID m_clid
Class id of the reference table.
Definition: RefTable.h:62
RefTable1to1
Definition: RefTable.h:149
Kernel.h
RefTableBase::BaseType
RefTableBase< FROM, EntryType > BaseType
Definition: RefTable.h:52
GaudiUtils::Map::size
size_type size() const
Definition: Map.h:182
RefTableBase::begin
iterator begin()
Start of direct access iterator.
Definition: RefTable.h:99
RefTable1toN::isReferenced
bool isReferenced(const FROM *from, const TO *to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:266
StreamBuffer
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
RefTableBase::serialize
virtual StreamBuffer & serialize(StreamBuffer &s)
Serialize the object for reading.
Definition: RefTable.h:134
SmartRef::target
const TYPE * target() const
Access to the object.
Definition: SmartRef.h:278
RefTableBase::i_reference
const EntryType * i_reference(const KeyType *from) const
Find Reference from it&#39;s source entry (CONST)
Definition: RefTable.h:83
RefTableBase::TableType
GaudiUtils::HashMap< const void *, EntryType > TableType
Define Reference map.
Definition: RefTable.h:56
RefTableBase::const_iterator
TableType::const_iterator const_iterator
Definition of map iterator (CONST)
Definition: RefTable.h:60
RefTableBase::begin
const_iterator begin() const
Start of direct access iterator (CONST)
Definition: RefTable.h:103
SmartRefVector.h
SmartRef< KeyType >
std::vector::end
T end(T...args)
RefTable1to1::reference
TO * reference(const FROM *from)
Find Reference from it&#39;s source entry.
Definition: RefTable.h:177
RefTable1to1::isReferenced
bool isReferenced(const FROM *from, const EntryType &to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:194
HashMap.h
RefTable1to1::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: RefTable.h:161
RefTable1toN::reference
const EntryType & reference(const FROM *from) const
Find Reference from it&#39;s source entry (CONST)
Definition: RefTable.h:255
StreamBuffer.h
SmartRefVector
Kernel objects: SmartRefVector.
Definition: SmartRefVector.h:54
RefTableBase::i_reference
EntryType * i_reference(const KeyType *from)
Find Reference from it&#39;s source entry.
Definition: RefTable.h:78
RefTableBase::KeyType
FROM KeyType
Definition: RefTable.h:48
RefTable1toN::insert
bool insert(const FROM *from, const EntryType &to)
Insert new Entry into Reference container.
Definition: RefTable.h:245
RefTable1to1::reference
const TO * reference(const FROM *from) const
Find Reference from it&#39;s source entry (CONST)
Definition: RefTable.h:183
std::vector::push_back
T push_back(T...args)
RefTableBase::reserve
void reserve(int len)
Size of References.
Definition: RefTable.h:119
RefTableBase::size
long size() const
Size of References.
Definition: RefTable.h:115
GaudiUtils::Map::end
iterator end()
Definition: Map.h:132
RefTableBase::iterator
TableType::iterator iterator
Definition of map iterator.
Definition: RefTable.h:58
SmartRef::data
TYPE * data()
Access to raw data pointer.
Definition: SmartRef.h:161
RefTableBase::end
iterator end()
End of direct access iterator.
Definition: RefTable.h:107
RefTableBase::RefTableBase
RefTableBase(const CLID &clid, int len)
Constructors.
Definition: RefTable.h:90
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:149
RefTable1toN::RefTable1toN
RefTable1toN(const CLID &clid, int len=16)
Standard Constructor.
Definition: RefTable.h:204
RefTableBase::end
const_iterator end() const
End of direct access iterator (CONST)
Definition: RefTable.h:111
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
GaudiUtils::Map::const_iterator
map_type::const_iterator const_iterator
Definition: Map.h:100
RefTableBase::clear
virtual void clear()
Clear Reference map.
Definition: RefTable.h:95
GaudiUtils::Map::begin
iterator begin()
Definition: Map.h:131
std::find
T find(T...args)
RefTableBase::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition: RefTable.h:123
RefTableBase
template <class FROM, class TO, class MAPENTRY> class RefTable
Definition: RefTable.h:45
RefTableBase::m_table
TableType m_table
Reference map.
Definition: RefTable.h:65
GaudiUtils::Map::iterator
map_type::iterator iterator
Definition: Map.h:99
std::vector::begin
T begin(T...args)
SmartRef::hintID
long hintID() const
Access hint id:
Definition: SmartRef.h:145
RefTable1toN::isReferenced
bool isReferenced(const FROM *from, const SmartRef< TO > &to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:270
RefTable1toN::insert
bool insert(const FROM *from, const SmartRef< TO > &to)
Insert new Entry into Reference container.
Definition: RefTable.h:230
RefTable1to1::RefTable1to1
RefTable1to1(const CLID &clid, int len=16)
Standard Constructor.
Definition: RefTable.h:153
RefTable1toN
Definition: RefTable.h:200
RefTable1to1::insert
bool insert(const FROM *from, const EntryType &to)
Insert new Entry into Reference container.
Definition: RefTable.h:169
SmartRef.h
RefTable1to1::insert
bool insert(const FROM *from, TO *to)
Insert new Entry into Reference container.
Definition: RefTable.h:165
RefTable1toN::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: RefTable.h:211
GaudiUtils::HashMap< const void *, EntryType >
GaudiUtils::Map::insert
std::pair< iterator, bool > insert(ValueType &&val)
Definition: Map.h:168
gaudirun.s
string s
Definition: gaudirun.py:245
GaudiUtils::Map::clear
void clear()
Definition: Map.h:178
RefTableBase::EntryType
MAPENTRY EntryType
Definition: RefTable.h:50
StreamBuffer::INVALID
Definition: StreamBuffer.h:117
RefTableBase::insertMapElement
bool insertMapElement(const KeyType *from, EntryType &to)
Insert new Entry into Reference container.
Definition: RefTable.h:74
RefTableBase::m_fromRef
SmartRef< KeyType > m_fromRef
This is a completely useless entry, but the compiler wants it to be instantiated before the serialize...
Definition: RefTable.h:70
RefTable1toN::reference
EntryType & reference(const FROM *from)
Find Reference from it&#39;s source entry.
Definition: RefTable.h:249
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
RefTable1to1::isReferenced
bool isReferenced(const FROM *from, const TO *to) const
Check if two entries are associated to each other.
Definition: RefTable.h:189
RefTableBase::~RefTableBase
virtual ~RefTableBase()=default
Destructor.
DataObject.h
RefTable1toN::isReferenced
bool isReferenced(const FROM *from, const EntryType &to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:261
RefTable1toN::insert
bool insert(const FROM *from, TO *to)
Insert new Entry into Reference container.
Definition: RefTable.h:215