lemon/bits/traits.h
changeset 215 17c644f5f98d
parent 184 716b220697a0
child 220 a5d8c039f218
equal deleted inserted replaced
3:4a232d98f8b2 4:2bd1c8a3158a
     1 
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 /* -*- C++ -*-
     2  *
     3  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  * This file is a part of LEMON, a generic C++ optimization library
       
     5  *
     4  *
     6  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     7  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     8  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     9  *
     8  *
    27 ///
    26 ///
    28 
    27 
    29 namespace lemon {
    28 namespace lemon {
    30   template <typename _Graph, typename _Item>
    29   template <typename _Graph, typename _Item>
    31   class ItemSetTraits {};
    30   class ItemSetTraits {};
    32   
    31 
    33 
    32 
    34   template <typename Graph, typename Enable = void>
    33   template <typename Graph, typename Enable = void>
    35   struct NodeNotifierIndicator {
    34   struct NodeNotifierIndicator {
    36     typedef InvalidType Type;
    35     typedef InvalidType Type;
    37   };
    36   };
    38   template <typename Graph>
    37   template <typename Graph>
    39   struct NodeNotifierIndicator<
    38   struct NodeNotifierIndicator<
    40     Graph, 
    39     Graph,
    41     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    40     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    42   > { 
    41   > {
    43     typedef typename Graph::NodeNotifier Type;
    42     typedef typename Graph::NodeNotifier Type;
    44   };
    43   };
    45 
    44 
    46   template <typename _Graph>
    45   template <typename _Graph>
    47   class ItemSetTraits<_Graph, typename _Graph::Node> {
    46   class ItemSetTraits<_Graph, typename _Graph::Node> {
    48   public:
    47   public:
    49     
    48 
    50     typedef _Graph Graph;
    49     typedef _Graph Graph;
    51 
    50 
    52     typedef typename Graph::Node Item;
    51     typedef typename Graph::Node Item;
    53     typedef typename Graph::NodeIt ItemIt;
    52     typedef typename Graph::NodeIt ItemIt;
    54 
    53 
    55     typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
    54     typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
    56 
    55 
    57     template <typename _Value>
    56     template <typename _Value>
    58     class Map : public Graph::template NodeMap<_Value> {
    57     class Map : public Graph::template NodeMap<_Value> {
    59     public:
    58     public:
    60       typedef typename Graph::template NodeMap<_Value> Parent; 
    59       typedef typename Graph::template NodeMap<_Value> Parent;
    61       typedef typename Graph::template NodeMap<_Value> Type; 
    60       typedef typename Graph::template NodeMap<_Value> Type;
    62       typedef typename Parent::Value Value;
    61       typedef typename Parent::Value Value;
    63 
    62 
    64       Map(const Graph& _digraph) : Parent(_digraph) {}
    63       Map(const Graph& _digraph) : Parent(_digraph) {}
    65       Map(const Graph& _digraph, const Value& _value) 
    64       Map(const Graph& _digraph, const Value& _value)
    66 	: Parent(_digraph, _value) {}
    65         : Parent(_digraph, _value) {}
    67 
    66 
    68      };
    67      };
    69 
    68 
    70   };
    69   };
    71 
    70 
    73   struct ArcNotifierIndicator {
    72   struct ArcNotifierIndicator {
    74     typedef InvalidType Type;
    73     typedef InvalidType Type;
    75   };
    74   };
    76   template <typename Graph>
    75   template <typename Graph>
    77   struct ArcNotifierIndicator<
    76   struct ArcNotifierIndicator<
    78     Graph, 
    77     Graph,
    79     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    78     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    80   > { 
    79   > {
    81     typedef typename Graph::ArcNotifier Type;
    80     typedef typename Graph::ArcNotifier Type;
    82   };
    81   };
    83 
    82 
    84   template <typename _Graph>
    83   template <typename _Graph>
    85   class ItemSetTraits<_Graph, typename _Graph::Arc> {
    84   class ItemSetTraits<_Graph, typename _Graph::Arc> {
    86   public:
    85   public:
    87     
    86 
    88     typedef _Graph Graph;
    87     typedef _Graph Graph;
    89 
    88 
    90     typedef typename Graph::Arc Item;
    89     typedef typename Graph::Arc Item;
    91     typedef typename Graph::ArcIt ItemIt;
    90     typedef typename Graph::ArcIt ItemIt;
    92 
    91 
    93     typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
    92     typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
    94 
    93 
    95     template <typename _Value>
    94     template <typename _Value>
    96     class Map : public Graph::template ArcMap<_Value> {
    95     class Map : public Graph::template ArcMap<_Value> {
    97     public:
    96     public:
    98       typedef typename Graph::template ArcMap<_Value> Parent; 
    97       typedef typename Graph::template ArcMap<_Value> Parent;
    99       typedef typename Graph::template ArcMap<_Value> Type; 
    98       typedef typename Graph::template ArcMap<_Value> Type;
   100       typedef typename Parent::Value Value;
    99       typedef typename Parent::Value Value;
   101 
   100 
   102       Map(const Graph& _digraph) : Parent(_digraph) {}
   101       Map(const Graph& _digraph) : Parent(_digraph) {}
   103       Map(const Graph& _digraph, const Value& _value) 
   102       Map(const Graph& _digraph, const Value& _value)
   104 	: Parent(_digraph, _value) {}
   103         : Parent(_digraph, _value) {}
   105     };
   104     };
   106 
   105 
   107   };
   106   };
   108 
   107 
   109   template <typename Graph, typename Enable = void>
   108   template <typename Graph, typename Enable = void>
   110   struct EdgeNotifierIndicator {
   109   struct EdgeNotifierIndicator {
   111     typedef InvalidType Type;
   110     typedef InvalidType Type;
   112   };
   111   };
   113   template <typename Graph>
   112   template <typename Graph>
   114   struct EdgeNotifierIndicator<
   113   struct EdgeNotifierIndicator<
   115     Graph, 
   114     Graph,
   116     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
   115     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
   117   > { 
   116   > {
   118     typedef typename Graph::EdgeNotifier Type;
   117     typedef typename Graph::EdgeNotifier Type;
   119   };
   118   };
   120 
   119 
   121   template <typename _Graph>
   120   template <typename _Graph>
   122   class ItemSetTraits<_Graph, typename _Graph::Edge> {
   121   class ItemSetTraits<_Graph, typename _Graph::Edge> {
   123   public:
   122   public:
   124     
   123 
   125     typedef _Graph Graph;
   124     typedef _Graph Graph;
   126 
   125 
   127     typedef typename Graph::Edge Item;
   126     typedef typename Graph::Edge Item;
   128     typedef typename Graph::EdgeIt ItemIt;
   127     typedef typename Graph::EdgeIt ItemIt;
   129 
   128 
   130     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
   129     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
   131 
   130 
   132     template <typename _Value>
   131     template <typename _Value>
   133     class Map : public Graph::template EdgeMap<_Value> {
   132     class Map : public Graph::template EdgeMap<_Value> {
   134     public:
   133     public:
   135       typedef typename Graph::template EdgeMap<_Value> Parent; 
   134       typedef typename Graph::template EdgeMap<_Value> Parent;
   136       typedef typename Graph::template EdgeMap<_Value> Type; 
   135       typedef typename Graph::template EdgeMap<_Value> Type;
   137       typedef typename Parent::Value Value;
   136       typedef typename Parent::Value Value;
   138 
   137 
   139       Map(const Graph& _digraph) : Parent(_digraph) {}
   138       Map(const Graph& _digraph) : Parent(_digraph) {}
   140       Map(const Graph& _digraph, const Value& _value) 
   139       Map(const Graph& _digraph, const Value& _value)
   141 	: Parent(_digraph, _value) {}
   140         : Parent(_digraph, _value) {}
   142     };
   141     };
   143 
   142 
   144   };
   143   };
   145 
   144 
   146   template <typename Map, typename Enable = void>
   145   template <typename Map, typename Enable = void>
   154     typedef Value ReturnValue;
   153     typedef Value ReturnValue;
   155   };
   154   };
   156 
   155 
   157   template <typename Map>
   156   template <typename Map>
   158   struct MapTraits<
   157   struct MapTraits<
   159     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
   158     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
   160   {
   159   {
   161     typedef True ReferenceMapTag;
   160     typedef True ReferenceMapTag;
   162     
   161 
   163     typedef typename Map::Key Key;
   162     typedef typename Map::Key Key;
   164     typedef typename Map::Value Value;
   163     typedef typename Map::Value Value;
   165 
   164 
   166     typedef typename Map::ConstReference ConstReturnValue;
   165     typedef typename Map::ConstReference ConstReturnValue;
   167     typedef typename Map::Reference ReturnValue;
   166     typedef typename Map::Reference ReturnValue;
   168 
   167 
   169     typedef typename Map::ConstReference ConstReference; 
   168     typedef typename Map::ConstReference ConstReference;
   170     typedef typename Map::Reference Reference;
   169     typedef typename Map::Reference Reference;
   171  };
   170  };
   172 
   171 
   173   template <typename MatrixMap, typename Enable = void>
   172   template <typename MatrixMap, typename Enable = void>
   174   struct MatrixMapTraits {
   173   struct MatrixMapTraits {
   182     typedef Value ReturnValue;
   181     typedef Value ReturnValue;
   183   };
   182   };
   184 
   183 
   185   template <typename MatrixMap>
   184   template <typename MatrixMap>
   186   struct MatrixMapTraits<
   185   struct MatrixMapTraits<
   187     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
   186     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
   188                                   void>::type > 
   187                                   void>::type >
   189   {
   188   {
   190     typedef True ReferenceMapTag;
   189     typedef True ReferenceMapTag;
   191     
   190 
   192     typedef typename MatrixMap::FirstKey FirstKey;
   191     typedef typename MatrixMap::FirstKey FirstKey;
   193     typedef typename MatrixMap::SecondKey SecondKey;
   192     typedef typename MatrixMap::SecondKey SecondKey;
   194     typedef typename MatrixMap::Value Value;
   193     typedef typename MatrixMap::Value Value;
   195 
   194 
   196     typedef typename MatrixMap::ConstReference ConstReturnValue;
   195     typedef typename MatrixMap::ConstReference ConstReturnValue;
   197     typedef typename MatrixMap::Reference ReturnValue;
   196     typedef typename MatrixMap::Reference ReturnValue;
   198 
   197 
   199     typedef typename MatrixMap::ConstReference ConstReference; 
   198     typedef typename MatrixMap::ConstReference ConstReference;
   200     typedef typename MatrixMap::Reference Reference;
   199     typedef typename MatrixMap::Reference Reference;
   201  };
   200  };
   202 
   201 
   203   // Indicators for the tags
   202   // Indicators for the tags
   204 
   203 
   207     static const bool value = false;
   206     static const bool value = false;
   208   };
   207   };
   209 
   208 
   210   template <typename Graph>
   209   template <typename Graph>
   211   struct NodeNumTagIndicator<
   210   struct NodeNumTagIndicator<
   212     Graph, 
   211     Graph,
   213     typename enable_if<typename Graph::NodeNumTag, void>::type
   212     typename enable_if<typename Graph::NodeNumTag, void>::type
   214   > {
   213   > {
   215     static const bool value = true;
   214     static const bool value = true;
   216   };
   215   };
   217 
   216 
   220     static const bool value = false;
   219     static const bool value = false;
   221   };
   220   };
   222 
   221 
   223   template <typename Graph>
   222   template <typename Graph>
   224   struct EdgeNumTagIndicator<
   223   struct EdgeNumTagIndicator<
   225     Graph, 
   224     Graph,
   226     typename enable_if<typename Graph::EdgeNumTag, void>::type
   225     typename enable_if<typename Graph::EdgeNumTag, void>::type
   227   > {
   226   > {
   228     static const bool value = true;
   227     static const bool value = true;
   229   };
   228   };
   230 
   229 
   233     static const bool value = false;
   232     static const bool value = false;
   234   };
   233   };
   235 
   234 
   236   template <typename Graph>
   235   template <typename Graph>
   237   struct FindEdgeTagIndicator<
   236   struct FindEdgeTagIndicator<
   238     Graph, 
   237     Graph,
   239     typename enable_if<typename Graph::FindEdgeTag, void>::type
   238     typename enable_if<typename Graph::FindEdgeTag, void>::type
   240   > {
   239   > {
   241     static const bool value = true;
   240     static const bool value = true;
   242   };
   241   };
   243 
   242 
   246     static const bool value = false;
   245     static const bool value = false;
   247   };
   246   };
   248 
   247 
   249   template <typename Graph>
   248   template <typename Graph>
   250   struct UndirectedTagIndicator<
   249   struct UndirectedTagIndicator<
   251     Graph, 
   250     Graph,
   252     typename enable_if<typename Graph::UndirectedTag, void>::type
   251     typename enable_if<typename Graph::UndirectedTag, void>::type
   253   > {
   252   > {
   254     static const bool value = true;
   253     static const bool value = true;
   255   };
   254   };
   256 
   255 
   259     static const bool value = false;
   258     static const bool value = false;
   260   };
   259   };
   261 
   260 
   262   template <typename Graph>
   261   template <typename Graph>
   263   struct BuildTagIndicator<
   262   struct BuildTagIndicator<
   264     Graph, 
   263     Graph,
   265     typename enable_if<typename Graph::BuildTag, void>::type
   264     typename enable_if<typename Graph::BuildTag, void>::type
   266   > {
   265   > {
   267     static const bool value = true;
   266     static const bool value = true;
   268   };
   267   };
   269 
   268