00001
00003 #ifndef __gdt_graph_array__
00004 #define __gdt_graph_array__
00005
00006
00007 #include <GDT/gdtmap.h>
00008 #include <GDT/gdtlist.h>
00009
00010
00011 class undi_graph;
00012 class struct_gdtnode;
00013 class struct_gdtedge;
00014
00015
00016 namespace gdt {
00017
00018 class EDGE_OP {
00019 public:
00020 static gdtlist<struct_gdtedge*> all(const undi_graph *g);
00021
00022 static int number(const undi_graph *g);
00023 };
00024
00025 class NODE_OP {
00026 public:
00027 static gdtlist<struct_gdtnode*> all(const undi_graph *g);
00028
00029 static int number(const undi_graph *g);
00030 };
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 template <class I, class OP, class E>
00041 class gdt_graph_array : public gdtmap<I, E>
00042 {
00043 private:
00044
00045 const undi_graph *g;
00046
00047 typedef gdtmap<I, E> base;
00048 typedef gdt_graph_array<I,OP,E> self;
00049
00050 protected:
00051
00052 public:
00053
00054 gdt_graph_array() : base(), g(NULL) {}
00055
00056 gdt_graph_array(const undi_graph& _g) : g(&_g) {
00057 assert(g);
00058 gdtmap<I,E>::delete_table();
00059 init_table(OP::number(g));
00060 }
00061
00062 gdt_graph_array(const undi_graph& _g, E x) : base(x), g(&_g) {
00063 assert(g);
00064 gdtmap<I,E>::delete_table();
00065 init_table(OP::number(g));
00066 I i;
00067 gdtlist<I> objs = OP::all(g);
00068 forall(i, objs) {
00069 this->operator[](i) = x;
00070 }
00071 }
00072
00073 gdt_graph_array(const self& A) : base(A), g(A.g) {
00074
00075 }
00076
00077 self& operator=(const self& A)
00078 {
00079 assert(A.g);
00080 g = A.g;
00081 base::operator = (A);
00082 return *this;
00083 }
00084
00085 const E& const_get(I i) const {
00086 assert(g);
00087 return base::operator[](i);
00088 }
00089
00090 E& get(I i) {
00091 assert(g);
00092 return base::operator[](i);
00093 }
00094
00095 const undi_graph& get_graph() const { return *g; }
00096
00097 void init() {
00098 gdtmap<I,E>::delete_table();
00099 g = NULL;
00100 gdtmap<I,E>::init_table();
00101 }
00102
00103 void init(const undi_graph& _g)
00104 {
00105 gdtmap<I,E>::delete_table();
00106 g = &_g;
00107 gdtmap<I,E>::init_table(OP::number(g));
00108 }
00109
00110 void init(const undi_graph& _g, E x)
00111 {
00112 set_default(x);
00113 init(_g);
00114 }
00115
00116 void init(const undi_graph& _g, int n, E x)
00117 {
00118 set_default(x);
00119 g = &_g;
00120 gdtmap<I,E>::init_table(n);
00121 }
00122 };
00123
00124
00125
00126 template <class E>
00127 class gdtnode_array : public gdt_graph_array<struct_gdtnode*, NODE_OP, E>
00128 {
00129 private:
00130 typedef gdt_graph_array<struct_gdtnode*, NODE_OP, E> base;
00131 typedef gdtnode_array<E> self;
00132 public:
00133 gdtnode_array() : base() {}
00134 gdtnode_array(const undi_graph& g) : base(g) {}
00135 gdtnode_array(const undi_graph& g, E x) : base(g,x) {}
00136 gdtnode_array(const self& A) : base(A) {}
00137
00138 self& operator=(const self& A) { base::operator = (A); return *this; }
00139 const E& operator[](struct_gdtnode* i) const { return base::const_get(i); }
00140 E& operator[](struct_gdtnode* i) { return base::get(i); }
00141 };
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 template <class E>
00172 class gdtedge_array : public gdt_graph_array<struct_gdtedge*, EDGE_OP, E>
00173 {
00174 private:
00175 typedef gdt_graph_array<struct_gdtedge*, EDGE_OP, E> base;
00176 typedef gdtedge_array<E> self;
00177 public:
00178 gdtedge_array() : base() {}
00179 gdtedge_array(const undi_graph& g) : base(g) {}
00180 gdtedge_array(const undi_graph& g, E x) : base(g,x) {}
00181 gdtedge_array(const self& A) : base(A) {}
00182
00183 self& operator=(const self& A) { base::operator = (A); return *this;}
00184 const E& operator[](struct_gdtedge* i) const { return base::const_get(i);}
00185 E& operator[](struct_gdtedge* i) { return base::get(i);}
00186 };
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 template <class E>
00216 class gdtnode_map : public gdtnode_array<E>
00217 {
00218 private:
00219 typedef gdtnode_array<E> base;
00220 typedef gdtnode_map<E> self;
00221 public:
00222 gdtnode_map() {}
00223 gdtnode_map(const undi_graph& g) : base(g) {}
00224 gdtnode_map(const undi_graph& g, E x) : base(g,x) {}
00225 gdtnode_map(const self& A) : base(A) {}
00226
00227 self& operator=(const self& A) { base::operator = (A); return *this; }
00228 const E& operator[](struct_gdtnode* i) const { return base::const_get(i); }
00229 E& operator[](struct_gdtnode* i) { return base::get(i); }
00230 };
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 template <class E>
00261 class gdtedge_map : public gdtedge_array<E>
00262 {
00263 private:
00264 typedef gdtedge_array<E> base;
00265 typedef gdtedge_map<E> self;
00266 public:
00267 gdtedge_map() {}
00268 gdtedge_map(const undi_graph& g) : base(g) {}
00269 gdtedge_map(const undi_graph& g, E x) : base(g,x) {}
00270 gdtedge_map(const self& A) : base(A) {}
00271
00272 self& operator=(const self& A) { base::operator = (A); return *this; }
00273 const E& operator[](struct_gdtedge* i) const { return base::const_get(i); }
00274 E& operator[](struct_gdtedge* i) { return base::get(i); }
00275 };
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 };
00305
00306 #endif