lemon/bits/traits.h
changeset 766 97744b6dabf8
parent 440 88ed40ad0d4f
child 1019 4c89e925cfe2
equal deleted inserted replaced
8:ff271b5de009 9:5bddaa99fc9a
    27 
    27 
    28 namespace lemon {
    28 namespace lemon {
    29 
    29 
    30   struct InvalidType {};
    30   struct InvalidType {};
    31 
    31 
    32   template <typename _Graph, typename _Item>
    32   template <typename GR, typename _Item>
    33   class ItemSetTraits {};
    33   class ItemSetTraits {};
    34 
    34 
    35 
    35 
    36   template <typename Graph, typename Enable = void>
    36   template <typename GR, typename Enable = void>
    37   struct NodeNotifierIndicator {
    37   struct NodeNotifierIndicator {
    38     typedef InvalidType Type;
    38     typedef InvalidType Type;
    39   };
    39   };
    40   template <typename Graph>
    40   template <typename GR>
    41   struct NodeNotifierIndicator<
    41   struct NodeNotifierIndicator<
    42     Graph,
    42     GR,
    43     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    43     typename enable_if<typename GR::NodeNotifier::Notifier, void>::type
    44   > {
    44   > {
    45     typedef typename Graph::NodeNotifier Type;
    45     typedef typename GR::NodeNotifier Type;
    46   };
    46   };
    47 
    47 
    48   template <typename _Graph>
    48   template <typename GR>
    49   class ItemSetTraits<_Graph, typename _Graph::Node> {
    49   class ItemSetTraits<GR, typename GR::Node> {
    50   public:
    50   public:
    51 
    51 
    52     typedef _Graph Graph;
    52     typedef GR Graph;
    53 
    53     typedef GR Digraph;
    54     typedef typename Graph::Node Item;
    54 
    55     typedef typename Graph::NodeIt ItemIt;
    55     typedef typename GR::Node Item;
    56 
    56     typedef typename GR::NodeIt ItemIt;
    57     typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
    57 
    58 
    58     typedef typename NodeNotifierIndicator<GR>::Type ItemNotifier;
    59     template <typename _Value>
    59 
    60     class Map : public Graph::template NodeMap<_Value> {
    60     template <typename V>
       
    61     class Map : public GR::template NodeMap<V> {
       
    62       typedef typename GR::template NodeMap<V> Parent;
       
    63 
    61     public:
    64     public:
    62       typedef typename Graph::template NodeMap<_Value> Parent;
    65       typedef typename GR::template NodeMap<V> Type;
    63       typedef typename Graph::template NodeMap<_Value> Type;
       
    64       typedef typename Parent::Value Value;
    66       typedef typename Parent::Value Value;
    65 
    67 
    66       Map(const Graph& _digraph) : Parent(_digraph) {}
    68       Map(const GR& _digraph) : Parent(_digraph) {}
    67       Map(const Graph& _digraph, const Value& _value)
    69       Map(const GR& _digraph, const Value& _value)
    68         : Parent(_digraph, _value) {}
    70         : Parent(_digraph, _value) {}
    69 
    71 
    70      };
    72      };
    71 
    73 
    72   };
    74   };
    73 
    75 
    74   template <typename Graph, typename Enable = void>
    76   template <typename GR, typename Enable = void>
    75   struct ArcNotifierIndicator {
    77   struct ArcNotifierIndicator {
    76     typedef InvalidType Type;
    78     typedef InvalidType Type;
    77   };
    79   };
    78   template <typename Graph>
    80   template <typename GR>
    79   struct ArcNotifierIndicator<
    81   struct ArcNotifierIndicator<
    80     Graph,
    82     GR,
    81     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    83     typename enable_if<typename GR::ArcNotifier::Notifier, void>::type
    82   > {
    84   > {
    83     typedef typename Graph::ArcNotifier Type;
    85     typedef typename GR::ArcNotifier Type;
    84   };
    86   };
    85 
    87 
    86   template <typename _Graph>
    88   template <typename GR>
    87   class ItemSetTraits<_Graph, typename _Graph::Arc> {
    89   class ItemSetTraits<GR, typename GR::Arc> {
    88   public:
    90   public:
    89 
    91 
    90     typedef _Graph Graph;
    92     typedef GR Graph;
    91 
    93     typedef GR Digraph;
    92     typedef typename Graph::Arc Item;
    94 
    93     typedef typename Graph::ArcIt ItemIt;
    95     typedef typename GR::Arc Item;
    94 
    96     typedef typename GR::ArcIt ItemIt;
    95     typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
    97 
    96 
    98     typedef typename ArcNotifierIndicator<GR>::Type ItemNotifier;
    97     template <typename _Value>
    99 
    98     class Map : public Graph::template ArcMap<_Value> {
   100     template <typename V>
       
   101     class Map : public GR::template ArcMap<V> {
       
   102       typedef typename GR::template ArcMap<V> Parent;
       
   103 
    99     public:
   104     public:
   100       typedef typename Graph::template ArcMap<_Value> Parent;
   105       typedef typename GR::template ArcMap<V> Type;
   101       typedef typename Graph::template ArcMap<_Value> Type;
       
   102       typedef typename Parent::Value Value;
   106       typedef typename Parent::Value Value;
   103 
   107 
   104       Map(const Graph& _digraph) : Parent(_digraph) {}
   108       Map(const GR& _digraph) : Parent(_digraph) {}
   105       Map(const Graph& _digraph, const Value& _value)
   109       Map(const GR& _digraph, const Value& _value)
   106         : Parent(_digraph, _value) {}
   110         : Parent(_digraph, _value) {}
   107     };
   111     };
   108 
   112 
   109   };
   113   };
   110 
   114 
   111   template <typename Graph, typename Enable = void>
   115   template <typename GR, typename Enable = void>
   112   struct EdgeNotifierIndicator {
   116   struct EdgeNotifierIndicator {
   113     typedef InvalidType Type;
   117     typedef InvalidType Type;
   114   };
   118   };
   115   template <typename Graph>
   119   template <typename GR>
   116   struct EdgeNotifierIndicator<
   120   struct EdgeNotifierIndicator<
   117     Graph,
   121     GR,
   118     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
   122     typename enable_if<typename GR::EdgeNotifier::Notifier, void>::type
   119   > {
   123   > {
   120     typedef typename Graph::EdgeNotifier Type;
   124     typedef typename GR::EdgeNotifier Type;
   121   };
   125   };
   122 
   126 
   123   template <typename _Graph>
   127   template <typename GR>
   124   class ItemSetTraits<_Graph, typename _Graph::Edge> {
   128   class ItemSetTraits<GR, typename GR::Edge> {
   125   public:
   129   public:
   126 
   130 
   127     typedef _Graph Graph;
   131     typedef GR Graph;
   128 
   132     typedef GR Digraph;
   129     typedef typename Graph::Edge Item;
   133 
   130     typedef typename Graph::EdgeIt ItemIt;
   134     typedef typename GR::Edge Item;
   131 
   135     typedef typename GR::EdgeIt ItemIt;
   132     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
   136 
   133 
   137     typedef typename EdgeNotifierIndicator<GR>::Type ItemNotifier;
   134     template <typename _Value>
   138 
   135     class Map : public Graph::template EdgeMap<_Value> {
   139     template <typename V>
       
   140     class Map : public GR::template EdgeMap<V> {
       
   141       typedef typename GR::template EdgeMap<V> Parent;
       
   142 
   136     public:
   143     public:
   137       typedef typename Graph::template EdgeMap<_Value> Parent;
   144       typedef typename GR::template EdgeMap<V> Type;
   138       typedef typename Graph::template EdgeMap<_Value> Type;
       
   139       typedef typename Parent::Value Value;
   145       typedef typename Parent::Value Value;
   140 
   146 
   141       Map(const Graph& _digraph) : Parent(_digraph) {}
   147       Map(const GR& _digraph) : Parent(_digraph) {}
   142       Map(const Graph& _digraph, const Value& _value)
   148       Map(const GR& _digraph, const Value& _value)
   143         : Parent(_digraph, _value) {}
   149         : Parent(_digraph, _value) {}
   144     };
   150     };
   145 
   151 
   146   };
   152   };
   147 
   153 
   202     typedef typename MatrixMap::Reference Reference;
   208     typedef typename MatrixMap::Reference Reference;
   203  };
   209  };
   204 
   210 
   205   // Indicators for the tags
   211   // Indicators for the tags
   206 
   212 
   207   template <typename Graph, typename Enable = void>
   213   template <typename GR, typename Enable = void>
   208   struct NodeNumTagIndicator {
   214   struct NodeNumTagIndicator {
   209     static const bool value = false;
   215     static const bool value = false;
   210   };
   216   };
   211 
   217 
   212   template <typename Graph>
   218   template <typename GR>
   213   struct NodeNumTagIndicator<
   219   struct NodeNumTagIndicator<
   214     Graph,
   220     GR,
   215     typename enable_if<typename Graph::NodeNumTag, void>::type
   221     typename enable_if<typename GR::NodeNumTag, void>::type
   216   > {
   222   > {
   217     static const bool value = true;
   223     static const bool value = true;
   218   };
   224   };
   219 
   225 
   220   template <typename Graph, typename Enable = void>
   226   template <typename GR, typename Enable = void>
   221   struct ArcNumTagIndicator {
   227   struct ArcNumTagIndicator {
   222     static const bool value = false;
   228     static const bool value = false;
   223   };
   229   };
   224 
   230 
   225   template <typename Graph>
   231   template <typename GR>
   226   struct ArcNumTagIndicator<
   232   struct ArcNumTagIndicator<
   227     Graph,
   233     GR,
   228     typename enable_if<typename Graph::ArcNumTag, void>::type
   234     typename enable_if<typename GR::ArcNumTag, void>::type
   229   > {
   235   > {
   230     static const bool value = true;
   236     static const bool value = true;
   231   };
   237   };
   232 
   238 
   233   template <typename Graph, typename Enable = void>
   239   template <typename GR, typename Enable = void>
   234   struct EdgeNumTagIndicator {
   240   struct EdgeNumTagIndicator {
   235     static const bool value = false;
   241     static const bool value = false;
   236   };
   242   };
   237 
   243 
   238   template <typename Graph>
   244   template <typename GR>
   239   struct EdgeNumTagIndicator<
   245   struct EdgeNumTagIndicator<
   240     Graph,
   246     GR,
   241     typename enable_if<typename Graph::EdgeNumTag, void>::type
   247     typename enable_if<typename GR::EdgeNumTag, void>::type
   242   > {
   248   > {
   243     static const bool value = true;
   249     static const bool value = true;
   244   };
   250   };
   245 
   251 
   246   template <typename Graph, typename Enable = void>
   252   template <typename GR, typename Enable = void>
   247   struct FindArcTagIndicator {
   253   struct FindArcTagIndicator {
   248     static const bool value = false;
   254     static const bool value = false;
   249   };
   255   };
   250 
   256 
   251   template <typename Graph>
   257   template <typename GR>
   252   struct FindArcTagIndicator<
   258   struct FindArcTagIndicator<
   253     Graph,
   259     GR,
   254     typename enable_if<typename Graph::FindArcTag, void>::type
   260     typename enable_if<typename GR::FindArcTag, void>::type
   255   > {
   261   > {
   256     static const bool value = true;
   262     static const bool value = true;
   257   };
   263   };
   258 
   264 
   259   template <typename Graph, typename Enable = void>
   265   template <typename GR, typename Enable = void>
   260   struct FindEdgeTagIndicator {
   266   struct FindEdgeTagIndicator {
   261     static const bool value = false;
   267     static const bool value = false;
   262   };
   268   };
   263 
   269 
   264   template <typename Graph>
   270   template <typename GR>
   265   struct FindEdgeTagIndicator<
   271   struct FindEdgeTagIndicator<
   266     Graph,
   272     GR,
   267     typename enable_if<typename Graph::FindEdgeTag, void>::type
   273     typename enable_if<typename GR::FindEdgeTag, void>::type
   268   > {
   274   > {
   269     static const bool value = true;
   275     static const bool value = true;
   270   };
   276   };
   271 
   277 
   272   template <typename Graph, typename Enable = void>
   278   template <typename GR, typename Enable = void>
   273   struct UndirectedTagIndicator {
   279   struct UndirectedTagIndicator {
   274     static const bool value = false;
   280     static const bool value = false;
   275   };
   281   };
   276 
   282 
   277   template <typename Graph>
   283   template <typename GR>
   278   struct UndirectedTagIndicator<
   284   struct UndirectedTagIndicator<
   279     Graph,
   285     GR,
   280     typename enable_if<typename Graph::UndirectedTag, void>::type
   286     typename enable_if<typename GR::UndirectedTag, void>::type
   281   > {
   287   > {
   282     static const bool value = true;
   288     static const bool value = true;
   283   };
   289   };
   284 
   290 
   285   template <typename Graph, typename Enable = void>
   291   template <typename GR, typename Enable = void>
   286   struct BuildTagIndicator {
   292   struct BuildTagIndicator {
   287     static const bool value = false;
   293     static const bool value = false;
   288   };
   294   };
   289 
   295 
   290   template <typename Graph>
   296   template <typename GR>
   291   struct BuildTagIndicator<
   297   struct BuildTagIndicator<
   292     Graph,
   298     GR,
   293     typename enable_if<typename Graph::BuildTag, void>::type
   299     typename enable_if<typename GR::BuildTag, void>::type
   294   > {
   300   > {
   295     static const bool value = true;
   301     static const bool value = true;
   296   };
   302   };
   297 
   303 
   298 }
   304 }