00001
00002 #ifndef RELATION_H
00003 #define RELATION_H
00004
00005 #include "RelKey.h"
00006 #include "GaudiKernel/ClassID.h"
00007 #include "GaudiKernel/ContainedObject.h"
00008 #include <vector>
00009 #include <string>
00010 #include <iostream>
00011
00012
00013
00024 static const CLID CLID_Relation = 5100;
00025
00026
00027 namespace Event {
00028
00029 template <class T1, class T2>
00030 class RelTable;
00031
00032
00033
00034 template <class T1, class T2>
00035 class Relation: public ContainedObject {
00036
00037 public:
00038
00039 virtual const CLID& clID() const { return Relation::classID(); }
00040 static const CLID& classID() { return CLID_Relation; }
00041
00042
00043 Relation(T1* obj1, T2* obj2): m_first(obj1), m_second(obj2) {}
00044 Relation(T1* obj1, T2* obj2, std::string info);
00045 Relation(T1* obj1, T2* obj2, std::vector<std::string> infos);
00046
00047 const T1* getFirst() const {return m_first.getData();}
00048 T1* getFirst() { return m_first.getData();}
00049
00050 const T2* getSecond() const {return m_second.getData();}
00051 T2* getSecond() { return m_second.getData();}
00052
00054 void addInfo(std::string inf);
00055 std::vector<std::string> getInfos() const;
00056
00058 std::ostream& fillStream( std::ostream& s ) const;
00059
00060 friend class RelTable<T1,T2>;
00061
00062 private:
00063
00065 RelKey<T1,T1,T2> m_first;
00067 RelKey<T2,T1,T2> m_second;
00069 std::vector<std::string> m_infos;
00070
00071 void setFirst(T1* obj) {m_first.setData(obj);}
00072 void setSecond(T2 *obj) {m_second.setData(obj);}
00073
00074 };
00075
00076
00077
00078 template <class T1, class T2>
00079 inline Relation<T1,T2>::Relation(T1* obj1, T2* obj2, std::string info):
00080 m_first(obj1), m_second(obj2), m_infos(1,info) {}
00081
00082
00083 template <class T1, class T2>
00084 inline Relation<T1,T2>::Relation(T1* obj1, T2* obj2, std::vector<std::string> infos):
00085 m_first(obj1), m_second(obj2), m_infos(infos) {}
00086
00087
00088
00089 template <class T1, class T2>
00090 void Relation<T1,T2>::addInfo(std::string inf) {
00091
00092
00093
00094 m_infos.push_back(inf);
00095
00096 }
00097
00098 template <class T1, class T2>
00099 std::vector<std::string> Relation<T1,T2>::getInfos() const {
00100
00101
00102
00103
00104 return m_infos;
00105 }
00106
00107
00108 template <class T1, class T2>
00109 inline std::ostream& Relation<T1,T2>::fillStream( std::ostream& s ) const {
00110
00111 s << " Base class Relation"
00112 << "\n First Column: ";
00113 m_first.toStream(s);
00114 s << "\n Second Column: ";
00115 m_second.toStream(s);
00116 s << "\n Additional Information: ";
00117
00118 std::vector<std::string>::const_iterator i;
00119 for(i = m_infos.begin(); i != m_infos.end(); i++)
00120 {
00121 s << "\n " << *i;
00122 }
00123 return s;
00124 }
00125
00126 }
00127
00128 #endif // RELATION_H
00129