| The Gaudi Framework v30r0 (c919700c)

- 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 // Include files
5 #include "GaudiKernel/DataObject.h"
6 #include "GaudiKernel/HashMap.h" // Cannot use maps through sharable images....
7 #include "GaudiKernel/Kernel.h"
8 #include "GaudiKernel/SmartRef.h"
9 #include "GaudiKernel/SmartRefVector.h"
10 #include "GaudiKernel/StreamBuffer.h"
11
12 // Externals
13 static const CLID CLID_RefTable1to1 = 300;
14 static const CLID CLID_RefTable1toN = 301;
15
16 //------------------------------------------------------------------------------
17 //
18 // Implementation and definition of template classes
19 // RefTableBase, RefTable1to1, RefTable1toN
20 //
21 // Author : Markus Frank
22 //
23 //------------------------------------------------------------------------------
43 template <class FROM, class MAPENTRY>
44 class RefTableBase : public DataObject
45 {
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
64 private:
66 TableType m_table;
71 SmartRef<KeyType> m_fromRef;
72
73 protected:
75 bool insertMapElement( const KeyType* from, EntryType& to ) { return m_table.insert( from, to ); }
77 EntryType* i_reference( const KeyType* from )
78 {
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 {
85 auto i = m_table.find( from );
86 return i != m_table.end() ? &( i->second ) : nullptr;
87 }
88
89 public:
91 RefTableBase( const CLID& clid, int len ) : m_clid( clid ), m_table( len ) {}
93 virtual ~RefTableBase() = default;
95 virtual void clear() { m_table.clear(); }
97 iterator begin() { return m_table.begin(); }
99 const_iterator begin() const { return m_table.begin(); }
101 iterator end() { return m_table.end(); }
103 const_iterator end() const { return m_table.end(); }
105 long size() const { return m_table.size(); }
107 void reserve( int len ) { m_table.reserve( len ); }
109 virtual StreamBuffer& serialize( StreamBuffer& s ) const
110 {
111 DataObject::serialize( s ) << m_table.size();
112 // for (TableType::const_iterator i = m_table.begin(), stop = m_table.end(); i != stop; i++ ) {
113 // SmartRef<KeyType> fromRef;
114 // fromRef = (KeyType*)(*i).first;
115 // s << fromRef(this);
116 // s << (*i).second(this);
117 //}
118 return s;
119 }
121 virtual StreamBuffer& serialize( StreamBuffer& s )
122 {
123 long siz;
124 DataObject::serialize( s ) >> siz;
125 m_table.reserve( siz );
126 // for ( long i = 0; i < siz; i++ ) {
127 // SmartRef<KeyType> fromRef;
128 // EntryType entry;
129 // s >> fromRef(this);
130 // s >> entry(this);
131 // insertMapElement( fromRef, entry);
132 //}
133 return s;
134 }
135 };
136
137 template <class FROM, class TO>
138 class RefTable1to1 : public RefTableBase<FROM, SmartRef<TO>>
139 {
140 public:
142 RefTable1to1( const CLID& clid, int len = 16 ) : RefTableBase<FROM, SmartRef<TO>>( clid, len ) {}
144 ~RefTable1to1() override = default;
145
147 virtual const CLID& clID() const { return m_clid; }
149 bool insert( const FROM* from, TO* to ) { return insertMapElement( from, EntryType( to ) ); }
151 bool insert( const FROM* from, const EntryType& to )
152 {
153 // We MUST check the environment of the smart pointer!
154 if ( 0 != to.data() || StreamBuffer::INVALID != to.hintID() ) {
155 return insertMapElement( from, EntryType( to ) );
156 }
157 return false;
158 }
160 TO* reference( const FROM* from )
161 {
162 EntryType* e = i_reference( from );
163 return ( 0 == e ) ? 0 : ( *e );
164 }
165
167 const TO* reference( const FROM* from ) const
168 {
169 auto e = i_reference( from );
170 return e ? *e : nullptr;
171 }
172
174 bool isReferenced( const FROM* from, const TO* to ) const
175 {
176 auto e = i_reference( from );
177 return e && ( *e == to );
178 }
180 bool isReferenced( const FROM* from, const EntryType& to )
181 {
182 const EntryType* e = i_reference( from );
183 return assoc && ( *e != to ) && ( e->target() == to.target() );
184 }
185 };
186
187 template <class FROM, class TO>
188 class RefTable1toN : public RefTableBase<FROM, SmartRefVector<TO>>
189 {
190 public:
192 RefTable1toN( const CLID& clid, int len = 16 ) : RefTableBase<FROM, SmartRefVector<TO>>( clid, len ) {}
194 ~RefTable1toN() override = default;
195
197 virtual const CLID& clID() const { return m_clid; }
199 bool insert( const FROM* from, TO* to )
200 {
201 EntryType* entry = i_reference( from );
202 if ( 0 == entry ) {
203 bool result = insertMapElement( from, EntryType() );
204 EntryType* newEntry = i_reference( from );
205 if ( !( 0 == newEntry ) ) {
206 newEntry->push_back( SmartRef<TO>( to ) );
207 return true;
208 }
209 return false;
210 }
211 entry->push_back( SmartRef<TO>( to ) );
212 return true;
213 }
215 bool insert( const FROM* from, const SmartRef<TO>& to )
216 {
217 EntryType* entry = i_reference( from );
218 if ( 0 == entry ) {
219 bool result = insertMapElement( from, EntryType() );
220 EntryType* newEntry = i_reference( from );
221 if ( !( 0 == newEntry ) ) {
222 newEntry->push_back( to );
223 return true;
224 }
225 return false;
226 }
227 entry->push_back( to );
228 return true;
229 }
231 bool insert( const FROM* from, const EntryType& to )
232 {
233 return insertMapElement( from, const_cast<EntryType&>( to ) );
234 }
236 EntryType& reference( const FROM* from )
237 {
238 static EntryType empty;
239 EntryType* e = i_reference( from );
240 return e ? *e : empty;
241 }
243 const EntryType& reference( const FROM* from ) const
244 {
245 static const EntryType empty;
246 EntryType* e = i_reference( from );
247 return e ? *e : empty;
248 }
250 bool isReferenced( const FROM* from, const EntryType& to )
251 {
252 auto e = i_reference( from );
253 return e && ( *e == to );
254 }
256 bool isReferenced( const FROM* from, const TO* to ) { return isReferenced( from, SmartRef<TO>( to ) ); }
258 bool isReferenced( const FROM* from, const SmartRef<TO>& to )
259 {
260 const EntryType* e = i_reference( from );
261 return assoc && std::find( e->begin(), e->end(), to ) != e->end();
262 }
263 };
264
265 #endif // GAUDIKERNEL_REFTABLE_H
RefTableBase::m_clid
CLID m_clid
Class id of the reference table.
Definition: RefTable.h:62
RefTable1to1
Definition: RefTable.h:138
Kernel.h
RefTableBase::BaseType
RefTableBase< FROM, EntryType > BaseType
Definition: RefTable.h:52
GaudiUtils::Map::size
size_type size() const
Definition: Map.h:199
RefTableBase::begin
iterator begin()
Start of direct access iterator.
Definition: RefTable.h:97
RefTable1toN::isReferenced
bool isReferenced(const FROM *from, const TO *to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:256
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:121
SmartRef::target
const TYPE * target() const
Access to the object.
Definition: SmartRef.h:279
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::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:99
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:160
RefTable1to1::isReferenced
bool isReferenced(const FROM *from, const EntryType &to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:180
HashMap.h
RefTable1to1::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: RefTable.h:147
RefTable1toN::reference
const EntryType & reference(const FROM *from) const
Find Reference from it&#39;s source entry (CONST)
Definition: RefTable.h:243
StreamBuffer.h
SmartRefVector
Kernel objects: SmartRefVector.
Definition: SmartRefVector.h:55
RefTableBase::i_reference
EntryType * i_reference(const KeyType *from)
Find Reference from it&#39;s source entry.
Definition: RefTable.h:77
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:231
RefTable1to1::reference
const TO * reference(const FROM *from) const
Find Reference from it&#39;s source entry (CONST)
Definition: RefTable.h:167
std::vector::push_back
T push_back(T...args)
GaudiUtils::Map::insert
std::pair< iterator, bool > insert(ValueType &&val)
Definition: Map.h:174
RefTableBase::reserve
void reserve(int len)
Size of References.
Definition: RefTable.h:107
RefTableBase::size
long size() const
Size of References.
Definition: RefTable.h:105
GaudiUtils::Map::end
iterator end()
Definition: Map.h:134
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:167
RefTableBase::end
iterator end()
End of direct access iterator.
Definition: RefTable.h:101
RefTableBase::RefTableBase
RefTableBase(const CLID &clid, int len)
Constructors.
Definition: RefTable.h:91
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:151
RefTable1toN::RefTable1toN
RefTable1toN(const CLID &clid, int len=16)
Standard Constructor.
Definition: RefTable.h:192
RefTableBase::end
const_iterator end() const
End of direct access iterator (CONST)
Definition: RefTable.h:103
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
GaudiUtils::Map< const void *, EntryType, std::unordered_map< const void *, EntryType, Hash< const void * > > >::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:133
RefTableBase::TableType
GaudiUtils::HashMap< const void *, EntryType > TableType
Define Reference map.
Definition: RefTable.h:56
std::find
T find(T...args)
RefTableBase::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition: RefTable.h:109
RefTableBase
template <class FROM, class TO, class MAPENTRY> class RefTable
Definition: RefTable.h:44
RefTableBase::m_table
TableType m_table
Reference map.
Definition: RefTable.h:66
GaudiUtils::Map< const void *, EntryType, std::unordered_map< const void *, EntryType, Hash< const void * > > >::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:159
RefTable1toN::isReferenced
bool isReferenced(const FROM *from, const SmartRef< TO > &to)
Check if two entries are Referenced to each other.
Definition: RefTable.h:258
RefTable1toN::insert
bool insert(const FROM *from, const SmartRef< TO > &to)
Insert new Entry into Reference container.
Definition: RefTable.h:215
RefTable1to1::RefTable1to1
RefTable1to1(const CLID &clid, int len=16)
Standard Constructor.
Definition: RefTable.h:142
RefTable1toN
Definition: RefTable.h:188
RefTable1to1::insert
bool insert(const FROM *from, const EntryType &to)
Insert new Entry into Reference container.
Definition: RefTable.h:151
SmartRef.h
RefTable1to1::insert
bool insert(const FROM *from, TO *to)
Insert new Entry into Reference container.
Definition: RefTable.h:149
RefTable1toN::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: RefTable.h:197
GaudiUtils::HashMap< const void *, EntryType >
gaudirun.s
string s
Definition: gaudirun.py:253
GaudiUtils::Map::clear
void clear()
Definition: Map.h:195
RefTableBase::EntryType
MAPENTRY EntryType
Definition: RefTable.h:50
StreamBuffer::INVALID
Definition: StreamBuffer.h:119
RefTableBase::insertMapElement
bool insertMapElement(const KeyType *from, EntryType &to)
Insert new Entry into Reference container.
Definition: RefTable.h:75
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:71
RefTable1toN::reference
EntryType & reference(const FROM *from)
Find Reference from it&#39;s source entry.
Definition: RefTable.h:236
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:174
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:250
RefTable1toN::insert
bool insert(const FROM *from, TO *to)
Insert new Entry into Reference container.
Definition: RefTable.h:199