6#include "GaudiKernel/ObjectList.h"
7#include "GaudiKernel/SmartRef.h"
28 template <
class T1,
class T2>
38 void init() { m_relations =
new ObjectList< Relation<T1,T2> >;}
63 std::vector< Relation<T1,T2>* >
getRelByFirst(
const T1* pobj)
const;
71 std::vector< Relation<T1,T2>* >
getRelBySecond(
const T2* pobj)
const;
97 unsigned long size()
const ;
105 ObjectList < Relation<T1,T2> >* m_relations;
123 template <
class T1,
class T2>
130 template <
class T1,
class T2>
136 bindRelationFirst(rel);
137 bindRelationSecond(rel);
138 m_relations->push_back(rel);
142 template <
class T1,
class T2>
152 if (bindRelationNoDup(rel))
154 bindRelationSecond(rel);
155 m_relations->push_back(rel);
162 template <
class T1,
class T2>
169 std::vector< Relation<T1,T2>* > rels;
170 if (!m_relations->size())
return rels;
171 SmartRef< Relation<T1,T2> > r = m_relations->front();
172 while (pobj != r->getFirst() && r->m_first.getFirst())
174 r = r->m_first.getFirst();
177 if (pobj == r->getFirst())
180 while (r->m_first.getSame())
182 rels.push_back(r->m_first.getSame());
183 r = r->m_first.getSame();
190 template <
class T1,
class T2>
196 std::vector< Relation<T1,T2>* > rels;
197 if (!m_relations->size())
return rels;
198 SmartRef< Relation<T1,T2> > r = m_relations->front();
199 while (pobj != r->getSecond() && r->m_second.getFirst())
201 r = r->m_second.getFirst();
204 if (pobj == r->getSecond())
207 while (r->m_second.getSame())
209 rels.push_back(r->m_second.getSame());
210 r = r->m_second.getSame();
217 template <
class T1,
class T2>
224 m_relations->remove(rel);
229 template <
class T1,
class T2>
236 m_relations->remove(rel);
242 template <
class T1,
class T2>
249 m_relations->remove(rel);
250 rel->setSecond(pobj);
255 template <
class T1,
class T2>
259 return m_relations->size();
262 template <
class T1,
class T2>
271 template <
class T1,
class T2>
276 if (m_relations->size())
278 SmartRef< Relation<T1,T2> > r = m_relations->front();
279 while ((r->getFirst() != rel->
getFirst()))
281 if (r->m_first.getFirst())
291 if (r->getFirst() != rel->
getFirst())
293 r->m_first.setFirst(rel);
302 r->m_first.setSame(rel);
309 template <
class T1,
class T2>
313 if (m_relations->size())
315 SmartRef< Relation<T1,T2> > r = m_relations->front();
317 while ((r->getSecond() != rel->getSecond()))
319 if (r->m_second.getFirst())
329 if (r->getSecond() != rel->getSecond())
331 r->m_second.setFirst(rel);
332 rel->m_second.setPrev(r);
336 temp = r->m_second.getSame();
337 rel->m_second.setSame(temp);
339 temp->m_second.setPrev(rel);
340 r->m_second.setSame(rel);
341 rel->m_second.setPrev(r);
348 template <
class T1,
class T2>
353 if (rel1->getSecond() == rel2->getSecond())
355 rel1 = rel1->m_first.getSame();
362 template <
class T1,
class T2>
367 if (m_relations->size())
369 SmartRef< Relation<T1,T2> > r = m_relations->front();
370 while ((r->getFirst() != rel->getFirst()))
372 if (r->m_first.getFirst())
374 r = r->m_first.getFirst();
382 if (r->getFirst() != rel->getFirst())
384 r->m_first.setFirst(rel);
385 rel->m_first.setPrev(r);
390 temp = findDup(r,rel);
393 temp = r->m_first.getSame();
394 rel->m_first.setSame(temp);
396 temp->m_first.setPrev(rel);
397 r->m_first.setSame(rel);
398 rel->m_first.setPrev(r);
403 std::copy(rel->m_infos.begin(),rel->m_infos.end(),std::back_inserter(temp->m_infos));
413 template <
class T1,
class T2>
418 prev = rel->m_first.getPrev();
419 next = rel->m_first.getSame();
421 next->m_first.setPrev(prev);
424 if (
prev->m_first.getFirst())
425 prev->m_first.setFirst(next);
427 prev->m_first.setSame(next);
429 first = rel->m_first.getFirst();
431 first->m_first.setPrev(next);
432 rel->m_first.setPrev(0);
433 rel->m_first.setSame(0);
434 rel->m_first.setFirst(0);
438 template <
class T1,
class T2>
443 prev = rel->m_second.getPrev();
444 next = rel->m_second.getSame();
446 next->m_second.setPrev(prev);
449 if (
prev->m_second.getFirst())
450 prev->m_second.setFirst(next);
452 prev->m_second.setSame(next);
454 first = rel->m_second.getFirst();
456 first->m_second.setPrev(next);
457 rel->m_second.setPrev(0);
458 rel->m_second.setSame(0);
459 rel->m_second.setFirst(0);
Relation< T2, T3 > * getSame()
Relation< T2, T3 > * getFirst()
void setSame(Relation< T2, T3 > *rel)
void setPrev(Relation< T2, T3 > *rel)
void changeSecond(Relation< T1, T2 > *rel, T2 *pobj)
std::vector< Relation< T1, T2 > * > getRelBySecond(const T2 *pobj) const
void init()
Initialize the internal pointer to an ObjectList of relations.
ObjectList< Relation< T1, T2 > > * getAllRelations() const
Returns the pointer to the collection of relations.
unsigned long size() const
This method returns the number of relations in the table.
void erase(Relation< T1, T2 > *rel)
bool addRelation(Relation< T1, T2 > *rel)
std::vector< Relation< T1, T2 > * > getRelByFirst(const T1 *pobj) const
void changeFirst(Relation< T1, T2 > *rel, T1 *pobj)
void addDupRel(Relation< T1, T2 > *rel)
const T1 * getFirst() const
This class is used to wrap a collection of Relations.
This class is used to relate pair of objets.