src/lemon/default_map.h
changeset 981 2e34b796d532
parent 979 b5fb023cdb7b
child 987 87f7c54892df
equal deleted inserted replaced
3:bc1b3e27f6b4 4:70eb45d12049
    40    *  will belong to and the ValueType.
    40    *  will belong to and the ValueType.
    41    */
    41    */
    42 
    42 
    43 
    43 
    44 
    44 
    45   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
    45   template <typename _Graph, typename _Item, typename _ItemIt, typename _Value>
    46   struct DefaultMapSelector {
    46   struct DefaultMapSelector {
    47     typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
    47     typedef ArrayMap<_Graph, _Item, _ItemIt, _Value> Map;
    48   };
    48   };
    49 
    49 
    50   // bool
    50   // bool
    51   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    51   template <typename _Graph, typename _Item, typename _ItemIt>
    52   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
    52   struct DefaultMapSelector<_Graph, _Item, _ItemIt, bool> {
    53     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
    57   template <typename _Graph, typename _Item, typename _ItemIt>
    58   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
    58   struct DefaultMapSelector<_Graph, _Item, _ItemIt, char> {
    59     typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
    59     typedef VectorMap<_Graph, _Item, char> Map;
    60   };
    60   };
    61 
    61 
    62   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    62   template <typename _Graph, typename _Item, typename _ItemIt>
    63   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
    63   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed char> {
    64     typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
    64     typedef VectorMap<_Graph, _Item, signed char> Map;
    65   };
    65   };
    66 
    66 
    67   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    67   template <typename _Graph, typename _Item, typename _ItemIt>
    68   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
    68   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned char> {
    69     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
    74   template <typename _Graph, typename _Item, typename _ItemIt>
    75   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
    75   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed int> {
    76     typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
    76     typedef VectorMap<_Graph, _Item, signed int> Map;
    77   };
    77   };
    78 
    78 
    79   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    79   template <typename _Graph, typename _Item, typename _ItemIt>
    80   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
    80   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned int> {
    81     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
    86   template <typename _Graph, typename _Item, typename _ItemIt>
    87   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
    87   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed short> {
    88     typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
    88     typedef VectorMap<_Graph, _Item, signed short> Map;
    89   };
    89   };
    90 
    90 
    91   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    91   template <typename _Graph, typename _Item, typename _ItemIt>
    92   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
    92   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned short> {
    93     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
    98   template <typename _Graph, typename _Item, typename _ItemIt>
    99   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
    99   struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed long> {
   100     typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
   100     typedef VectorMap<_Graph, _Item, signed long> Map;
   101   };
   101   };
   102 
   102 
   103   template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   103   template <typename _Graph, typename _Item, typename _ItemIt>
   104   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
   104   struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned long> {
   105     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
   112   template <typename _Graph, typename _Item, typename _ItemIt>
   113   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
   113   struct DefaultMapSelector<_Graph, _Item, _ItemIt, float> {
   114     typedef VectorMap<_Graph, _Item, _IdMap, 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, typename _IdMap>
   119   template <typename _Graph, typename _Item, typename _ItemIt>
   120   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
   120   struct DefaultMapSelector<_Graph, _Item, _ItemIt, double> {
   121     typedef VectorMap<_Graph, _Item, _IdMap,  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, typename _IdMap>
   126   template <typename _Graph, typename _Item, typename _ItemIt>
   127   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
   127   struct DefaultMapSelector<_Graph, _Item, _ItemIt, long double> {
   128     typedef VectorMap<_Graph, _Item, _IdMap, 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 _IdMap, typename _Ptr>
   133   template <typename _Graph, typename _Item, typename _ItemIt, typename _Ptr>
   134   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
   134   struct DefaultMapSelector<_Graph, _Item, _ItemIt, _Ptr*> {
   135     typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
   135     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   136   };
   136   };
   137 
   137 
   138 
   138 
   139 
   139 
   140   template <typename _Graph, 
   140   template <typename _Graph, 
   141 	    typename _Item,
   141 	    typename _Item,
   142 	    typename _ItemIt,
   142 	    typename _ItemIt,
   143 	    typename _IdMap,
       
   144 	    typename _Value>
   143 	    typename _Value>
   145   class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
   144   class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map {
   146   public:
   145   public:
   147     typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
   146     typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map Parent;
   148     typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
   147     typedef DefaultMap<_Graph, _Item, _ItemIt, _Value> Map;
   149     
   148     
   150     typedef typename Parent::Graph Graph;
   149     typedef typename Parent::Graph Graph;
   151     typedef typename Parent::Registry Registry;
       
   152     typedef typename Parent::ValueType ValueType;
   150     typedef typename Parent::ValueType ValueType;
   153 
   151 
   154     DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
   152     DefaultMap(const Graph& _g) : Parent(_g) {}
   155     DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
   153     DefaultMap(const Graph& _g, const ValueType& _v) : Parent(_g, _v) {}
   156   };
   154   };
   157 
   155 
   158 
   156 
   159 
   157 
   160   template <typename _Base> 
   158   template <typename _Base> 
   164     typedef DefaultMappableGraphExtender<_Base> Graph;
   162     typedef DefaultMappableGraphExtender<_Base> Graph;
   165     typedef _Base Parent;
   163     typedef _Base Parent;
   166 
   164 
   167     typedef typename Parent::Node Node;
   165     typedef typename Parent::Node Node;
   168     typedef typename Parent::NodeIt NodeIt;
   166     typedef typename Parent::NodeIt NodeIt;
   169     typedef typename Parent::NodeIdMap NodeIdMap;
       
   170     typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
       
   171 
   167 
   172     typedef typename Parent::Edge Edge;
   168     typedef typename Parent::Edge Edge;
   173     typedef typename Parent::EdgeIt EdgeIt;
   169     typedef typename Parent::EdgeIt EdgeIt;
   174     typedef typename Parent::EdgeIdMap EdgeIdMap;
       
   175     typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
       
   176 
   170 
   177     
   171     
   178 
       
   179     template <typename _Value>
   172     template <typename _Value>
   180     class NodeMap : public DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
   173     class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
   181     public:
   174     public:
   182       typedef DefaultMappableGraphExtender<_Base> Graph;
   175       typedef DefaultMappableGraphExtender<_Base> Graph;
   183 
   176 
   184       typedef typename Graph::Node Node;
   177       typedef typename Graph::Node Node;
   185       typedef typename Graph::NodeIt NodeIt;
   178       typedef typename Graph::NodeIt NodeIt;
   186       typedef typename Graph::NodeIdMap NodeIdMap;
   179 
   187 
   180       typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
   188       typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
       
   189 
   181 
   190       //typedef typename Parent::Graph Graph;
   182       //typedef typename Parent::Graph Graph;
   191       typedef typename Parent::ValueType ValueType;
   183       typedef typename Parent::ValueType ValueType;
   192 
   184 
   193       NodeMap(const Graph& g) 
   185       NodeMap(const Graph& _g) 
   194 	: Parent(g, g.getNodeObserverRegistry()) {}
   186 	: Parent(_g) {}
   195       NodeMap(const Graph& g, const ValueType& v) 
   187       NodeMap(const Graph& _g, const ValueType& _v) 
   196 	: Parent(g, g.getNodeObserverRegistry(), v) {}
   188 	: Parent(_g, _v) {}
   197 
   189 
   198     };
   190     };
   199 
   191 
   200     template <typename _Value>
   192     template <typename _Value>
   201     class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
   193     class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
   202     public:
   194     public:
   203       typedef DefaultMappableGraphExtender<_Base> Graph;
   195       typedef DefaultMappableGraphExtender<_Base> Graph;
   204 
   196 
   205       typedef typename Graph::Edge Edge;
   197       typedef typename Graph::Edge Edge;
   206       typedef typename Graph::EdgeIt EdgeIt;
   198       typedef typename Graph::EdgeIt EdgeIt;
   207       typedef typename Graph::EdgeIdMap EdgeIdMap;
   199 
   208 
   200       typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
   209       typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
       
   210 
   201 
   211       //typedef typename Parent::Graph Graph;
   202       //typedef typename Parent::Graph Graph;
   212       typedef typename Parent::ValueType ValueType;
   203       typedef typename Parent::ValueType ValueType;
   213 
   204 
   214       EdgeMap(const Graph& g) 
   205       EdgeMap(const Graph& _g) 
   215 	: Parent(g, g.getEdgeObserverRegistry()) {}
   206 	: Parent(_g) {}
   216       EdgeMap(const Graph& g, const ValueType& v) 
   207       EdgeMap(const Graph& _g, const ValueType& _v) 
   217 	: Parent(g, g.getEdgeObserverRegistry(), v) {}
   208 	: Parent(_g, _v) {}
   218 
   209 
   219     };
   210     };
   220     
   211     
   221   };
   212   };
   222 
   213