src/lemon/default_map.h
changeset 1269 4c63ff4e16fa
parent 1164 80bb73097736
equal deleted inserted replaced
7:2f6dde0ad46b 8:41cef7bbdbb9
    40    *  will belong to and the Value.
    40    *  will belong to and the Value.
    41    */
    41    */
    42 
    42 
    43 
    43 
    44 
    44 
    45   template <typename _Graph, typename _Item, typename _ItemIt, typename _Value>
    45   template <typename _Graph, typename _Item, typename _Value>
    46   struct DefaultMapSelector {
    46   struct DefaultMapSelector {
    47     typedef ArrayMap<_Graph, _Item, _ItemIt, _Value> Map;
    47     typedef ArrayMap<_Graph, _Item, _Value> Map;
    48   };
    48   };
    49 
    49 
    50   // bool
    50   // bool
    51   template <typename _Graph, typename _Item, typename _ItemIt>
    51   template <typename _Graph, typename _Item>
    52   struct DefaultMapSelector<_Graph, _Item, _ItemIt, bool> {
    52   struct DefaultMapSelector<_Graph, _Item, bool> {
    53     typedef VectorMap<_Graph, _Item, bool> Map;
    53     typedef VectorMap<_Graph, _Item, bool> Map;
    54   };
    54   };
    55 
    55 
    56   // char
    56   // char
    57   template <typename _Graph, typename _Item, typename _ItemIt>
    57   template <typename _Graph, typename _Item>
    58   struct DefaultMapSelector<_Graph, _Item, _ItemIt, char> {
    58   struct DefaultMapSelector<_Graph, _Item, char> {
    59     typedef VectorMap<_Graph, _Item, char> Map;
    59     typedef VectorMap<_Graph, _Item, char> Map;
    60   };
    60   };
    61 
    61 
    62   template <typename _Graph, typename _Item, typename _ItemIt>
    62   template <typename _Graph, typename _Item>
    63   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed char> {
    63   struct DefaultMapSelector<_Graph, _Item, signed char> {
    64     typedef VectorMap<_Graph, _Item, signed char> Map;
    64     typedef VectorMap<_Graph, _Item, signed char> Map;
    65   };
    65   };
    66 
    66 
    67   template <typename _Graph, typename _Item, typename _ItemIt>
    67   template <typename _Graph, typename _Item>
    68   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned char> {
    68   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
    69     typedef VectorMap<_Graph, _Item, unsigned char> Map;
    69     typedef VectorMap<_Graph, _Item, unsigned char> Map;
    70   };
    70   };
    71 
    71 
    72 
    72 
    73   // int
    73   // int
    74   template <typename _Graph, typename _Item, typename _ItemIt>
    74   template <typename _Graph, typename _Item>
    75   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed int> {
    75   struct DefaultMapSelector<_Graph, _Item, signed int> {
    76     typedef VectorMap<_Graph, _Item, signed int> Map;
    76     typedef VectorMap<_Graph, _Item, signed int> Map;
    77   };
    77   };
    78 
    78 
    79   template <typename _Graph, typename _Item, typename _ItemIt>
    79   template <typename _Graph, typename _Item>
    80   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned int> {
    80   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
    81     typedef VectorMap<_Graph, _Item, unsigned int> Map;
    81     typedef VectorMap<_Graph, _Item, unsigned int> Map;
    82   };
    82   };
    83 
    83 
    84 
    84 
    85   // short
    85   // short
    86   template <typename _Graph, typename _Item, typename _ItemIt>
    86   template <typename _Graph, typename _Item>
    87   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed short> {
    87   struct DefaultMapSelector<_Graph, _Item, signed short> {
    88     typedef VectorMap<_Graph, _Item, signed short> Map;
    88     typedef VectorMap<_Graph, _Item, signed short> Map;
    89   };
    89   };
    90 
    90 
    91   template <typename _Graph, typename _Item, typename _ItemIt>
    91   template <typename _Graph, typename _Item>
    92   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned short> {
    92   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
    93     typedef VectorMap<_Graph, _Item, unsigned short> Map;
    93     typedef VectorMap<_Graph, _Item, unsigned short> Map;
    94   };
    94   };
    95 
    95 
    96 
    96 
    97   // long
    97   // long
    98   template <typename _Graph, typename _Item, typename _ItemIt>
    98   template <typename _Graph, typename _Item>
    99   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed long> {
    99   struct DefaultMapSelector<_Graph, _Item, signed long> {
   100     typedef VectorMap<_Graph, _Item, signed long> Map;
   100     typedef VectorMap<_Graph, _Item, signed long> Map;
   101   };
   101   };
   102 
   102 
   103   template <typename _Graph, typename _Item, typename _ItemIt>
   103   template <typename _Graph, typename _Item>
   104   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned long> {
   104   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
   105     typedef VectorMap<_Graph, _Item, unsigned long> Map;
   105     typedef VectorMap<_Graph, _Item, unsigned long> Map;
   106   };
   106   };
   107 
   107 
   108   // \todo handling long long type
   108   // \todo handling long long type
   109 
   109 
   110 
   110 
   111   // float
   111   // float
   112   template <typename _Graph, typename _Item, typename _ItemIt>
   112   template <typename _Graph, typename _Item>
   113   struct DefaultMapSelector<_Graph, _Item, _ItemIt, float> {
   113   struct DefaultMapSelector<_Graph, _Item, float> {
   114     typedef VectorMap<_Graph, _Item, float> Map;
   114     typedef VectorMap<_Graph, _Item, float> Map;
   115   };
   115   };
   116 
   116 
   117 
   117 
   118   // double
   118   // double
   119   template <typename _Graph, typename _Item, typename _ItemIt>
   119   template <typename _Graph, typename _Item>
   120   struct DefaultMapSelector<_Graph, _Item, _ItemIt, double> {
   120   struct DefaultMapSelector<_Graph, _Item, double> {
   121     typedef VectorMap<_Graph, _Item,  double> Map;
   121     typedef VectorMap<_Graph, _Item,  double> Map;
   122   };
   122   };
   123 
   123 
   124 
   124 
   125   // long double
   125   // long double
   126   template <typename _Graph, typename _Item, typename _ItemIt>
   126   template <typename _Graph, typename _Item>
   127   struct DefaultMapSelector<_Graph, _Item, _ItemIt, long double> {
   127   struct DefaultMapSelector<_Graph, _Item, long double> {
   128     typedef VectorMap<_Graph, _Item, long double> Map;
   128     typedef VectorMap<_Graph, _Item, long double> Map;
   129   };
   129   };
   130 
   130 
   131 
   131 
   132   // pointer
   132   // pointer
   133   template <typename _Graph, typename _Item, typename _ItemIt, typename _Ptr>
   133   template <typename _Graph, typename _Item, typename _Ptr>
   134   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _Ptr*> {
   134   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
   135     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   135     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   136   };
   136   };
   137 
   137 
   138 
   138 
   139 
   139 
   140   template <typename _Graph, 
   140   template <
   141 	    typename _Item,
   141     typename _Graph, 
   142 	    typename _ItemIt,
   142     typename _Item,
   143 	    typename _Value>
   143     typename _Value>
   144   class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map {
   144   class DefaultMap 
       
   145     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
   145   public:
   146   public:
   146     typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map Parent;
   147     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
   147     typedef DefaultMap<_Graph, _Item, _ItemIt, _Value> Map;
   148     typedef DefaultMap<_Graph, _Item, _Value> Map;
   148     
   149     
   149     typedef typename Parent::Graph Graph;
   150     typedef typename Parent::Graph Graph;
   150     typedef typename Parent::Value Value;
   151     typedef typename Parent::Value Value;
   151 
   152 
   152     DefaultMap(const Graph& _g) : Parent(_g) {}
   153     DefaultMap(const Graph& _g) : Parent(_g) {}
   168     typedef typename Parent::Edge Edge;
   169     typedef typename Parent::Edge Edge;
   169     typedef typename Parent::EdgeIt EdgeIt;
   170     typedef typename Parent::EdgeIt EdgeIt;
   170 
   171 
   171     
   172     
   172     template <typename _Value>
   173     template <typename _Value>
   173     class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
   174     class NodeMap 
       
   175       : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
   174     public:
   176     public:
   175       typedef DefaultMappableGraphExtender Graph;
   177       typedef DefaultMappableGraphExtender Graph;
   176       typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
   178       typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
   177 
   179 
   178       NodeMap(const Graph& _g) 
   180       NodeMap(const Graph& _g) 
   179 	: Parent(_g) {}
   181 	: Parent(_g) {}
   180       NodeMap(const Graph& _g, const _Value& _v) 
   182       NodeMap(const Graph& _g, const _Value& _v) 
   181 	: Parent(_g, _v) {}
   183 	: Parent(_g, _v) {}
   182     };
   184     };
   183 
   185 
   184     template <typename _Value>
   186     template <typename _Value>
   185     class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
   187     class EdgeMap 
       
   188       : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
   186     public:
   189     public:
   187       typedef DefaultMappableGraphExtender Graph;
   190       typedef DefaultMappableGraphExtender Graph;
   188       typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
   191       typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
   189 
   192 
   190       EdgeMap(const Graph& _g) 
   193       EdgeMap(const Graph& _g) 
   191 	: Parent(_g) {}
   194 	: Parent(_g) {}
   192       EdgeMap(const Graph& _g, const _Value& _v) 
   195       EdgeMap(const Graph& _g, const _Value& _v) 
   193 	: Parent(_g, _v) {}
   196 	: Parent(_g, _v) {}
   202 
   205 
   203     typedef MappableUndirGraphExtender Graph;
   206     typedef MappableUndirGraphExtender Graph;
   204     typedef DefaultMappableGraphExtender<_Base> Parent;
   207     typedef DefaultMappableGraphExtender<_Base> Parent;
   205 
   208 
   206     typedef typename Parent::UndirEdge UndirEdge;
   209     typedef typename Parent::UndirEdge UndirEdge;
   207     typedef typename Parent::UndirEdgeIt UndirEdgeIt;
       
   208 
   210 
   209     template <typename _Value>
   211     template <typename _Value>
   210     class UndirEdgeMap :
   212     class UndirEdgeMap 
   211       public DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> {
   213       : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
   212     public:
   214     public:
   213       typedef MappableUndirGraphExtender Graph;
   215       typedef MappableUndirGraphExtender Graph;
   214       typedef DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> Parent;
   216       typedef IterableMapExtender<
       
   217 	DefaultMap<Graph, UndirEdge, _Value> > Parent;
   215 
   218 
   216       UndirEdgeMap(const Graph& _g) 
   219       UndirEdgeMap(const Graph& _g) 
   217 	: Parent(_g) {}
   220 	: Parent(_g) {}
   218       UndirEdgeMap(const Graph& _g, const _Value& _v) 
   221       UndirEdgeMap(const Graph& _g, const _Value& _v) 
   219 	: Parent(_g, _v) {}
   222 	: Parent(_g, _v) {}