1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2009
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     9  * Permission to use, modify and distribute this software is granted
 
    10  * provided that this copyright notice appears in all copies. For
 
    11  * precise terms see the accompanying LICENSE file.
 
    13  * This software is provided "AS IS" with no warranty of any kind,
 
    14  * express or implied, and with no claim as to its suitability for any
 
    19 #ifndef LEMON_BITS_TRAITS_H
 
    20 #define LEMON_BITS_TRAITS_H
 
    23 //\brief Traits for graphs and maps
 
    26 #include <lemon/bits/enable_if.h>
 
    30   struct InvalidType {};
 
    32   template <typename GR, typename _Item>
 
    33   class ItemSetTraits {};
 
    36   template <typename GR, typename Enable = void>
 
    37   struct NodeNotifierIndicator {
 
    38     typedef InvalidType Type;
 
    40   template <typename GR>
 
    41   struct NodeNotifierIndicator<
 
    43     typename enable_if<typename GR::NodeNotifier::Notifier, void>::type
 
    45     typedef typename GR::NodeNotifier Type;
 
    48   template <typename GR>
 
    49   class ItemSetTraits<GR, typename GR::Node> {
 
    55     typedef typename GR::Node Item;
 
    56     typedef typename GR::NodeIt ItemIt;
 
    58     typedef typename NodeNotifierIndicator<GR>::Type ItemNotifier;
 
    61     class Map : public GR::template NodeMap<V> {
 
    62       typedef typename GR::template NodeMap<V> Parent;
 
    65       typedef typename GR::template NodeMap<V> Type;
 
    66       typedef typename Parent::Value Value;
 
    68       Map(const GR& _digraph) : Parent(_digraph) {}
 
    69       Map(const GR& _digraph, const Value& _value)
 
    70         : Parent(_digraph, _value) {}
 
    76   template <typename GR, typename Enable = void>
 
    77   struct ArcNotifierIndicator {
 
    78     typedef InvalidType Type;
 
    80   template <typename GR>
 
    81   struct ArcNotifierIndicator<
 
    83     typename enable_if<typename GR::ArcNotifier::Notifier, void>::type
 
    85     typedef typename GR::ArcNotifier Type;
 
    88   template <typename GR>
 
    89   class ItemSetTraits<GR, typename GR::Arc> {
 
    95     typedef typename GR::Arc Item;
 
    96     typedef typename GR::ArcIt ItemIt;
 
    98     typedef typename ArcNotifierIndicator<GR>::Type ItemNotifier;
 
   100     template <typename V>
 
   101     class Map : public GR::template ArcMap<V> {
 
   102       typedef typename GR::template ArcMap<V> Parent;
 
   105       typedef typename GR::template ArcMap<V> Type;
 
   106       typedef typename Parent::Value Value;
 
   108       Map(const GR& _digraph) : Parent(_digraph) {}
 
   109       Map(const GR& _digraph, const Value& _value)
 
   110         : Parent(_digraph, _value) {}
 
   115   template <typename GR, typename Enable = void>
 
   116   struct EdgeNotifierIndicator {
 
   117     typedef InvalidType Type;
 
   119   template <typename GR>
 
   120   struct EdgeNotifierIndicator<
 
   122     typename enable_if<typename GR::EdgeNotifier::Notifier, void>::type
 
   124     typedef typename GR::EdgeNotifier Type;
 
   127   template <typename GR>
 
   128   class ItemSetTraits<GR, typename GR::Edge> {
 
   134     typedef typename GR::Edge Item;
 
   135     typedef typename GR::EdgeIt ItemIt;
 
   137     typedef typename EdgeNotifierIndicator<GR>::Type ItemNotifier;
 
   139     template <typename V>
 
   140     class Map : public GR::template EdgeMap<V> {
 
   141       typedef typename GR::template EdgeMap<V> Parent;
 
   144       typedef typename GR::template EdgeMap<V> Type;
 
   145       typedef typename Parent::Value Value;
 
   147       Map(const GR& _digraph) : Parent(_digraph) {}
 
   148       Map(const GR& _digraph, const Value& _value)
 
   149         : Parent(_digraph, _value) {}
 
   154   template <typename Map, typename Enable = void>
 
   156     typedef False ReferenceMapTag;
 
   158     typedef typename Map::Key Key;
 
   159     typedef typename Map::Value Value;
 
   161     typedef Value ConstReturnValue;
 
   162     typedef Value ReturnValue;
 
   165   template <typename Map>
 
   167     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
 
   169     typedef True ReferenceMapTag;
 
   171     typedef typename Map::Key Key;
 
   172     typedef typename Map::Value Value;
 
   174     typedef typename Map::ConstReference ConstReturnValue;
 
   175     typedef typename Map::Reference ReturnValue;
 
   177     typedef typename Map::ConstReference ConstReference;
 
   178     typedef typename Map::Reference Reference;
 
   181   template <typename MatrixMap, typename Enable = void>
 
   182   struct MatrixMapTraits {
 
   183     typedef False ReferenceMapTag;
 
   185     typedef typename MatrixMap::FirstKey FirstKey;
 
   186     typedef typename MatrixMap::SecondKey SecondKey;
 
   187     typedef typename MatrixMap::Value Value;
 
   189     typedef Value ConstReturnValue;
 
   190     typedef Value ReturnValue;
 
   193   template <typename MatrixMap>
 
   194   struct MatrixMapTraits<
 
   195     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
 
   198     typedef True ReferenceMapTag;
 
   200     typedef typename MatrixMap::FirstKey FirstKey;
 
   201     typedef typename MatrixMap::SecondKey SecondKey;
 
   202     typedef typename MatrixMap::Value Value;
 
   204     typedef typename MatrixMap::ConstReference ConstReturnValue;
 
   205     typedef typename MatrixMap::Reference ReturnValue;
 
   207     typedef typename MatrixMap::ConstReference ConstReference;
 
   208     typedef typename MatrixMap::Reference Reference;
 
   211   // Indicators for the tags
 
   213   template <typename GR, typename Enable = void>
 
   214   struct NodeNumTagIndicator {
 
   215     static const bool value = false;
 
   218   template <typename GR>
 
   219   struct NodeNumTagIndicator<
 
   221     typename enable_if<typename GR::NodeNumTag, void>::type
 
   223     static const bool value = true;
 
   226   template <typename GR, typename Enable = void>
 
   227   struct ArcNumTagIndicator {
 
   228     static const bool value = false;
 
   231   template <typename GR>
 
   232   struct ArcNumTagIndicator<
 
   234     typename enable_if<typename GR::ArcNumTag, void>::type
 
   236     static const bool value = true;
 
   239   template <typename GR, typename Enable = void>
 
   240   struct EdgeNumTagIndicator {
 
   241     static const bool value = false;
 
   244   template <typename GR>
 
   245   struct EdgeNumTagIndicator<
 
   247     typename enable_if<typename GR::EdgeNumTag, void>::type
 
   249     static const bool value = true;
 
   252   template <typename GR, typename Enable = void>
 
   253   struct FindArcTagIndicator {
 
   254     static const bool value = false;
 
   257   template <typename GR>
 
   258   struct FindArcTagIndicator<
 
   260     typename enable_if<typename GR::FindArcTag, void>::type
 
   262     static const bool value = true;
 
   265   template <typename GR, typename Enable = void>
 
   266   struct FindEdgeTagIndicator {
 
   267     static const bool value = false;
 
   270   template <typename GR>
 
   271   struct FindEdgeTagIndicator<
 
   273     typename enable_if<typename GR::FindEdgeTag, void>::type
 
   275     static const bool value = true;
 
   278   template <typename GR, typename Enable = void>
 
   279   struct UndirectedTagIndicator {
 
   280     static const bool value = false;
 
   283   template <typename GR>
 
   284   struct UndirectedTagIndicator<
 
   286     typename enable_if<typename GR::UndirectedTag, void>::type
 
   288     static const bool value = true;
 
   291   template <typename GR, typename Enable = void>
 
   292   struct BuildTagIndicator {
 
   293     static const bool value = false;
 
   296   template <typename GR>
 
   297   struct BuildTagIndicator<
 
   299     typename enable_if<typename GR::BuildTag, void>::type
 
   301     static const bool value = true;