00001
00002
00003
00004
00005
00006
00007
00008 #ifndef COMMUNICATIONSTRUCTURE_HPP_
00009 #define COMMUNICATIONSTRUCTURE_HPP_
00010
00011 #include <string>
00012 #include "IdGraph.h"
00013 #include "IdUndirectedGraph.h"
00014 #include "../label/LabelMap.hpp"
00015
00016 namespace cosi {
00017
00018 #define PRJ(x) x::
00019
00020 template<class L> class CommunicationStructure : public IdGraph,
00021 public LabelMap<L> {
00022 public:
00023
00024 CommunicationStructure() :
00025 IdGraph("Unknown") {
00026 }
00027 ;
00028
00029 CommunicationStructure(std::string pName) :
00030 IdGraph(pName) {
00031 }
00032 ;
00033
00034 int AddVertex() {
00035 int Id = IdGraph::AddVertex();
00036 LabelMap<L>::Set(Id, L()) ;
00037 return Id ;
00038 }
00039 ;
00040
00042 void AddVertex(int Id) {
00043 IdGraph::AddVertex(Id);
00044 LabelMap<L>::Set(Id, L()) ;
00045 }
00046 ;
00047
00049 void DeleteVertex(int Id) {
00050 IdGraph::DeleteVertex(Id);
00051 LabelMap<L>::Erase(Id);
00052 }
00053 ;
00054
00056 void AddEdge(int i, int j) {
00057 IdGraph::AddEdge(i, j);
00058 LabelMap<L>::Set(Edge(i, j), L());
00059 }
00060 ;
00061
00063 void AddEdge(Edge pE) {
00064 IdGraph::AddEdge(pE);
00065 LabelMap<L>::Set(pE, L());
00066 }
00067 ;
00068
00070 void DeleteEdge(int i, int j) {
00071 IdGraph::DeleteEdge(i, j);
00072 LabelMap<L>::Erase(Edge(i, j));
00073 }
00074 ;
00075
00076 void DeleteEdge(Edge pE) {
00077 IdGraph::DeleteEdge(pE);
00078 LabelMap<L>::Erase(pE);
00079 }
00080 ;
00081
00082 L& operator[](Vertex V) {
00083 return LabelMap<L>::Get(V) ;
00084 }
00085 ;
00086
00087 L& operator[](Edge E) {
00088 return LabelMap<L>::Get(E) ;
00089 }
00090 ;
00091
00092 std::string PrintNode(int V) {
00093 std::string s;
00094 s += IdGraph::PrintNode(V) ;
00095 s += (*this)[V].Print() ;
00096 return s ;
00097 }
00098
00099 std::string PrintEdge(int U, int V) {
00100 std::string s;
00101 s+= IdGraph::PrintEdge(U, V) ;
00102 s+= (*this)[Edge(U,V)].Print() ;
00103 return s ;
00104 }
00105
00106 std::string PrintEdge(Edge pE) {
00107 std::string s;
00108 s+= IdGraph::PrintEdge(pE) ;
00109 s+= (*this)[pE].Print() ;
00110 return s ;
00111 }
00112
00113 };
00114
00115 template<class L> class U_CommunicationStructure : public IdUndirectedGraph,
00116 public LabelMap<L> {
00117 public:
00118
00119 U_CommunicationStructure() :
00120 IdUndirectedGraph("Unknown") {
00121 }
00122 ;
00123
00124 U_CommunicationStructure(std::string pName) :
00125 IdUndirectedGraph(pName) {
00126 }
00127 ;
00128
00130 void AddVertex(int Id) {
00131 IdUndirectedGraph::AddVertex(Id);
00132 LabelMap<L>::Set(Id, L()) ;
00133 }
00134 ;
00135
00137 void DeleteVertex(int Id) {
00138 IdUndirectedGraph::DeleteVertex(Id);
00139 LabelMap<L>::Erase(Id);
00140 }
00141 ;
00142
00144 void AddEdge(int i, int j) {
00145 IdUndirectedGraph::AddEdge(i, j);
00146 LabelMap<L>::Set(Edge(i, j), L());
00147 LabelMap<L>::Set(Edge(j, i), L());
00148 }
00149 ;
00150
00152 void AddEdge(Edge pE) {
00153 IdUndirectedGraph::AddEdge(pE);
00154 LabelMap<L>::Set(pE, L());
00155 Edge E(pE.V() , pE.U());
00156 LabelMap<L>::Set(E, L());
00157 }
00158 ;
00159
00161 void DeleteEdge(int i, int j) {
00162 IdUndirectedGraph::DeleteEdge(i, j);
00163 LabelMap<L>::Erase(Edge(i, j));
00164 LabelMap<L>::Erase(Edge(j, i));
00165 }
00166 ;
00167
00168 void DeleteEdge(Edge pE) {
00169 IdUndirectedGraph::DeleteEdge(pE);
00170 LabelMap<L>::Erase(pE);
00171 Edge E(pE.V() , pE.U());
00172 LabelMap<L>::Erase(E);
00173 }
00174 ;
00175
00176 L& operator[](Vertex V) {
00177 return LabelMap<L>::Get(V) ;
00178 }
00179 ;
00180
00181 L& operator[](Edge E) {
00182 if ( !(LabelMap<L>::Get(E)).IsBot() )
00183 return LabelMap<L>::Get(E) ;
00184 Edge Re ;
00185 Re.U(E.V()) ;
00186 Re.V(E.U()) ;
00187 if ( !(LabelMap<L>::Get(Re)).IsBot() )
00188 return LabelMap<L>::Get(Re) ;
00189 return LabelMap<L>::Get(E);
00190 }
00191 ;
00192
00193 std::string PrintNode(int V) {
00194 std::string s;
00195 s += IdUndirectedGraph::PrintNode(V) ;
00196 s += (*this)[V].Print() ;
00197 return s ;
00198 }
00199
00200 std::string PrintEdge(int U, int V) {
00201 std::string s;
00202 s+= IdUndirectedGraph::PrintEdge(U, V) ;
00203 s+= (*this)[Edge(U,V)].Print() ;
00204 return s ;
00205 }
00206
00207 std::string PrintEdge(Edge pE) {
00208 std::string s;
00209 s+= IdUndirectedGraph::PrintEdge(pE) ;
00210 s+= (*this)[pE].Print() ;
00211 return s ;
00212 }
00213
00214 };
00215
00216 }
00217
00218 #endif