title
Graph Drawing Toolkit

An object-oriented C++ library for handling and drawing graphs

gdt_graph_array.h

Go to the documentation of this file.
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); //{return g->all_edges();};
00021         
00022         static int number(const undi_graph *g); //{return g->number_of_edges();}; 
00023 };
00024 
00025 class NODE_OP {
00026 public:
00027         static gdtlist<struct_gdtnode*> all(const undi_graph *g); //{return g->all_nodes();}; 
00028         
00029         static int number(const undi_graph *g); //{return g->number_of_nodes()};
00030 };
00031 
00032 /*
00033 class FACE_OP {
00034 public:
00035         static gdtlist<face> all(const undi_graph *g);
00036         static int number(const undi_graph *g);
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();  // inserted by titto 8/8/2005 to fix memory leak
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();  // inserted by titto 8/8/2005 to fix memory leak
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                 //assert(g); (pizzo april 7, 2003)
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 //#ifndef _DEBUG_NODE_ARRAY
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 #else
00145 
00146 template <class E>
00147 class struct_gdtnode*_array
00148 {       
00149         private:        
00150                 node_array<E> _debug_array;             
00151         public:
00152                 struct_gdtnode*_array() {}
00153                 struct_gdtnode*_array(const graph& g) : _debug_array(g) {}
00154                 struct_gdtnode*_array(const graph& g, E x) : _debug_array(g,x) {}
00155                 struct_gdtnode*_array(const struct_gdtnode*_array<E>& A) : _debug_array(A._debug_array) {}
00156 
00157                 struct_gdtnode*_array<E>& operator=(const struct_gdtnode*_array<E>& A) { _debug_array = A._debug_array; return *this;}
00158                 const E&  operator[](struct_gdtnode* i) const { return _debug_array[i];}                
00159                 E& operator[](struct_gdtnode* i) { return _debug_array[i];}     
00160                 
00161                 void init() { _debug_array.init(); }            
00162                 void init(const graph& g)  { _debug_array.init(g); }            
00163                 void init(const graph& g, E x) { _debug_array.init(g,x); }                                              
00164                 void init(const graph& g, int n, E x) { _debug_array.init(g,n,x); }             
00165 };
00166 
00167 #endif
00168 */
00169 //#ifndef _DEBUG_EDGE_ARRAY
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 #else
00189 
00190 template <class E>
00191 class struct_gdtedge*_array
00192 {       
00193         private:        
00194                 edge_array<E> _debug_array;             
00195         public:
00196                 struct_gdtedge*_array() {}
00197                 struct_gdtedge*_array(const graph& g) : _debug_array(g) {}
00198                 struct_gdtedge*_array(const graph& g, E x) : _debug_array(g,x) {}
00199                 struct_gdtedge*_array(const struct_gdtedge*_array<E>& A) : _debug_array(A._debug_array) {}
00200 
00201                 struct_gdtedge*_array<E>& operator=(const struct_gdtedge*_array<E>& A) { _debug_array = A.debug_array; return *this;}
00202                 const E&  operator[](struct_gdtedge* i) const { return _debug_array[i];}                
00203                 E& operator[](struct_gdtedge* i) { return _debug_array[i];}                             
00204 
00205                 void init() { _debug_array.init(); }            
00206                 void init(const graph& g)  { _debug_array.init(g); }            
00207                 void init(const graph& g, E x) { _debug_array.init(g,x); }                                              
00208                 void init(const graph& g, int n, E x) { _debug_array.init(g,n,x); }             
00209 };
00210 
00211 #endif
00212 */
00213 //#ifndef _DEBUG_NODE_MAP
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 #else
00234 
00235 template <class E>
00236 class struct_gdtnode*_map
00237 {       
00238         private:        
00239                 node_map<E> _debug_map;
00240         public:
00241                 struct_gdtnode*_map() {}
00242                 struct_gdtnode*_map(const graph& g) : _debug_map(g) {}
00243                 struct_gdtnode*_map(const graph& g, E x) : _debug_map(g,x) {}
00244                 struct_gdtnode*_map(const struct_gdtnode*_map<E>& A) : _debug_map(A._debug_map) {}
00245 
00246                 struct_gdtnode*_map<E>& operator=(const struct_gdtnode*_map<E>& A) { _debug_map = A._debug_map; return *this; }
00247                 const E&  operator[](struct_gdtnode* i) const { return _debug_map[i];   }               
00248                 E& operator[](struct_gdtnode* i) { return _debug_map[i]; }                              
00249 
00250                 void init() { _debug_map.init(); }              
00251                 void init(const graph& g)  { _debug_map.init(g); }              
00252                 void init(const graph& g, E x) { _debug_map.init(g,x); }                                                
00253                 void init(const graph& g, int n, E x) { _debug_map.init(g,n,x); }               
00254 };
00255 
00256 #endif
00257 */
00258 //#ifndef _DEBUG_EDGE_MAP
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 #else
00279 
00280 template <class E>
00281 class struct_gdtedge*_map
00282 {
00283         private:        
00284                 edge_map<E> _debug_map;         
00285         public:
00286                 struct_gdtedge*_map() {}
00287                 struct_gdtedge*_map(const graph& g) : _debug_map(g) {}
00288                 struct_gdtedge*_map(const graph& g, E x) : _debug_map(g,x) {}
00289                 struct_gdtedge*_map(const struct_gdtedge*_map<E>& A) : _debug_map(A._debug_map) {}
00290 
00291                 struct_gdtedge*_map<E>& operator=(const struct_gdtedge*_map<E>& A) { _debug_map = A._debug_map; return *this; }
00292                 const E&  operator[](struct_gdtedge* i) const { return _debug_map[i]; }
00293                 E& operator[](struct_gdtedge* i) { return _debug_map[i]; }
00294 
00295                 void init() { _debug_map.init(); }              
00296                 void init(const graph& g)  { _debug_map.init(g); }              
00297                 void init(const graph& g, E x) { _debug_map.init(g,x); }                                                
00298                 void init(const graph& g, int n, E x) { _debug_map.init(g,n,x); }               
00299 };
00300 
00301 #endif
00302 */
00303 
00304 };
00305 
00306 #endif

Generated on Thu Jan 10 14:48:01 2008 for GDToolkit GAPI by  doxygen 1.5.3