Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

default_map.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * lemon/default_map.h - Part of LEMON, a generic C++ optimization library
00003  *
00004  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00005  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00006  *
00007  * Permission to use, modify and distribute this software is granted
00008  * provided that this copyright notice appears in all copies. For
00009  * precise terms see the accompanying LICENSE file.
00010  *
00011  * This software is provided "AS IS" with no warranty of any kind,
00012  * express or implied, and with no claim as to its suitability for any
00013  * purpose.
00014  *
00015  */
00016 
00017 #ifndef LEMON_DEFAULT_MAP_H
00018 #define LEMON_DEFAULT_MAP_H
00019 
00020 
00021 #include <lemon/bits/array_map.h>
00022 #include <lemon/bits/vector_map.h>
00023 
00028 
00029 namespace lemon {
00030 
00033 
00045   template <typename _Graph, typename _Item, typename _Value>
00046   struct DefaultMapSelector {
00047     typedef ArrayMap<_Graph, _Item, _Value> Map;
00048   };
00049 
00050   // bool
00051   template <typename _Graph, typename _Item>
00052   struct DefaultMapSelector<_Graph, _Item, bool> {
00053     typedef VectorMap<_Graph, _Item, bool> Map;
00054   };
00055 
00056   // char
00057   template <typename _Graph, typename _Item>
00058   struct DefaultMapSelector<_Graph, _Item, char> {
00059     typedef VectorMap<_Graph, _Item, char> Map;
00060   };
00061 
00062   template <typename _Graph, typename _Item>
00063   struct DefaultMapSelector<_Graph, _Item, signed char> {
00064     typedef VectorMap<_Graph, _Item, signed char> Map;
00065   };
00066 
00067   template <typename _Graph, typename _Item>
00068   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
00069     typedef VectorMap<_Graph, _Item, unsigned char> Map;
00070   };
00071 
00072 
00073   // int
00074   template <typename _Graph, typename _Item>
00075   struct DefaultMapSelector<_Graph, _Item, signed int> {
00076     typedef VectorMap<_Graph, _Item, signed int> Map;
00077   };
00078 
00079   template <typename _Graph, typename _Item>
00080   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
00081     typedef VectorMap<_Graph, _Item, unsigned int> Map;
00082   };
00083 
00084 
00085   // short
00086   template <typename _Graph, typename _Item>
00087   struct DefaultMapSelector<_Graph, _Item, signed short> {
00088     typedef VectorMap<_Graph, _Item, signed short> Map;
00089   };
00090 
00091   template <typename _Graph, typename _Item>
00092   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
00093     typedef VectorMap<_Graph, _Item, unsigned short> Map;
00094   };
00095 
00096 
00097   // long
00098   template <typename _Graph, typename _Item>
00099   struct DefaultMapSelector<_Graph, _Item, signed long> {
00100     typedef VectorMap<_Graph, _Item, signed long> Map;
00101   };
00102 
00103   template <typename _Graph, typename _Item>
00104   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
00105     typedef VectorMap<_Graph, _Item, unsigned long> Map;
00106   };
00107 
00108   // \todo handling long long type
00109 
00110 
00111   // float
00112   template <typename _Graph, typename _Item>
00113   struct DefaultMapSelector<_Graph, _Item, float> {
00114     typedef VectorMap<_Graph, _Item, float> Map;
00115   };
00116 
00117 
00118   // double
00119   template <typename _Graph, typename _Item>
00120   struct DefaultMapSelector<_Graph, _Item, double> {
00121     typedef VectorMap<_Graph, _Item,  double> Map;
00122   };
00123 
00124 
00125   // long double
00126   template <typename _Graph, typename _Item>
00127   struct DefaultMapSelector<_Graph, _Item, long double> {
00128     typedef VectorMap<_Graph, _Item, long double> Map;
00129   };
00130 
00131 
00132   // pointer
00133   template <typename _Graph, typename _Item, typename _Ptr>
00134   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
00135     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
00136   };
00137 
00138 
00139 
00140   template <
00141     typename _Graph, 
00142     typename _Item,
00143     typename _Value>
00144   class DefaultMap 
00145     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
00146   public:
00147     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
00148     typedef DefaultMap<_Graph, _Item, _Value> Map;
00149     
00150     typedef typename Parent::Graph Graph;
00151     typedef typename Parent::Value Value;
00152 
00153     DefaultMap(const Graph& _g) : Parent(_g) {}
00154     DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
00155   };
00156 
00157 
00158 
00159   template <typename _Base> 
00160   class DefaultMappableGraphExtender : public _Base {
00161   public:
00162 
00163     typedef DefaultMappableGraphExtender<_Base> Graph;
00164     typedef _Base Parent;
00165 
00166     typedef typename Parent::Node Node;
00167     typedef typename Parent::NodeIt NodeIt;
00168 
00169     typedef typename Parent::Edge Edge;
00170     typedef typename Parent::EdgeIt EdgeIt;
00171 
00172     
00173     template <typename _Value>
00174     class NodeMap 
00175       : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
00176     public:
00177       typedef DefaultMappableGraphExtender Graph;
00178       typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
00179 
00180       NodeMap(const Graph& _g) 
00181         : Parent(_g) {}
00182       NodeMap(const Graph& _g, const _Value& _v) 
00183         : Parent(_g, _v) {}
00184     };
00185 
00186     template <typename _Value>
00187     class EdgeMap 
00188       : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
00189     public:
00190       typedef DefaultMappableGraphExtender Graph;
00191       typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
00192 
00193       EdgeMap(const Graph& _g) 
00194         : Parent(_g) {}
00195       EdgeMap(const Graph& _g, const _Value& _v) 
00196         : Parent(_g, _v) {}
00197     };
00198     
00199   };
00200 
00201   template <typename _Base> 
00202   class MappableUndirGraphExtender : 
00203     public DefaultMappableGraphExtender<_Base> {
00204   public:
00205 
00206     typedef MappableUndirGraphExtender Graph;
00207     typedef DefaultMappableGraphExtender<_Base> Parent;
00208 
00209     typedef typename Parent::UndirEdge UndirEdge;
00210 
00211     template <typename _Value>
00212     class UndirEdgeMap 
00213       : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
00214     public:
00215       typedef MappableUndirGraphExtender Graph;
00216       typedef IterableMapExtender<
00217         DefaultMap<Graph, UndirEdge, _Value> > Parent;
00218 
00219       UndirEdgeMap(const Graph& _g) 
00220         : Parent(_g) {}
00221       UndirEdgeMap(const Graph& _g, const _Value& _v) 
00222         : Parent(_g, _v) {}
00223     };
00224 
00225 
00226   };
00227 
00228 }
00229 
00230 #endif

Generated on Sat Aug 27 14:14:50 2005 for LEMON by  doxygen 1.4.4