lemon/bits/traits.h
changeset 57 c1acf0018c0a
child 107 31a2e6d28f61
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/traits.h	Sun Jan 20 20:43:48 2008 +0100
     1.3 @@ -0,0 +1,272 @@
     1.4 +
     1.5 +/* -*- C++ -*-
     1.6 + *
     1.7 + * This file is a part of LEMON, a generic C++ optimization library
     1.8 + *
     1.9 + * Copyright (C) 2003-2007
    1.10 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.11 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.12 + *
    1.13 + * Permission to use, modify and distribute this software is granted
    1.14 + * provided that this copyright notice appears in all copies. For
    1.15 + * precise terms see the accompanying LICENSE file.
    1.16 + *
    1.17 + * This software is provided "AS IS" with no warranty of any kind,
    1.18 + * express or implied, and with no claim as to its suitability for any
    1.19 + * purpose.
    1.20 + *
    1.21 + */
    1.22 +
    1.23 +#ifndef LEMON_BITS_TRAITS_H
    1.24 +#define LEMON_BITS_TRAITS_H
    1.25 +
    1.26 +#include <lemon/bits/utility.h>
    1.27 +
    1.28 +///\file
    1.29 +///\brief Traits for graphs and maps
    1.30 +///
    1.31 +
    1.32 +namespace lemon {
    1.33 +  template <typename _Graph, typename _Item>
    1.34 +  class ItemSetTraits {};
    1.35 +  
    1.36 +
    1.37 +  template <typename Graph, typename Enable = void>
    1.38 +  struct NodeNotifierIndicator {
    1.39 +    typedef InvalidType Type;
    1.40 +  };
    1.41 +  template <typename Graph>
    1.42 +  struct NodeNotifierIndicator<
    1.43 +    Graph, 
    1.44 +    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    1.45 +  > { 
    1.46 +    typedef typename Graph::NodeNotifier Type;
    1.47 +  };
    1.48 +
    1.49 +  template <typename _Graph>
    1.50 +  class ItemSetTraits<_Graph, typename _Graph::Node> {
    1.51 +  public:
    1.52 +    
    1.53 +    typedef _Graph Graph;
    1.54 +
    1.55 +    typedef typename Graph::Node Item;
    1.56 +    typedef typename Graph::NodeIt ItemIt;
    1.57 +
    1.58 +    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
    1.59 +
    1.60 +    template <typename _Value>
    1.61 +    class Map : public Graph::template NodeMap<_Value> {
    1.62 +    public:
    1.63 +      typedef typename Graph::template NodeMap<_Value> Parent; 
    1.64 +      typedef typename Graph::template NodeMap<_Value> Type; 
    1.65 +      typedef typename Parent::Value Value;
    1.66 +
    1.67 +      Map(const Graph& _digraph) : Parent(_digraph) {}
    1.68 +      Map(const Graph& _digraph, const Value& _value) 
    1.69 +	: Parent(_digraph, _value) {}
    1.70 +
    1.71 +     };
    1.72 +
    1.73 +  };
    1.74 +
    1.75 +  template <typename Graph, typename Enable = void>
    1.76 +  struct ArcNotifierIndicator {
    1.77 +    typedef InvalidType Type;
    1.78 +  };
    1.79 +  template <typename Graph>
    1.80 +  struct ArcNotifierIndicator<
    1.81 +    Graph, 
    1.82 +    typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    1.83 +  > { 
    1.84 +    typedef typename Graph::ArcNotifier Type;
    1.85 +  };
    1.86 +
    1.87 +  template <typename _Graph>
    1.88 +  class ItemSetTraits<_Graph, typename _Graph::Arc> {
    1.89 +  public:
    1.90 +    
    1.91 +    typedef _Graph Graph;
    1.92 +
    1.93 +    typedef typename Graph::Arc Item;
    1.94 +    typedef typename Graph::ArcIt ItemIt;
    1.95 +
    1.96 +    typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
    1.97 +
    1.98 +    template <typename _Value>
    1.99 +    class Map : public Graph::template ArcMap<_Value> {
   1.100 +    public:
   1.101 +      typedef typename Graph::template ArcMap<_Value> Parent; 
   1.102 +      typedef typename Graph::template ArcMap<_Value> Type; 
   1.103 +      typedef typename Parent::Value Value;
   1.104 +
   1.105 +      Map(const Graph& _digraph) : Parent(_digraph) {}
   1.106 +      Map(const Graph& _digraph, const Value& _value) 
   1.107 +	: Parent(_digraph, _value) {}
   1.108 +    };
   1.109 +
   1.110 +  };
   1.111 +
   1.112 +  template <typename Graph, typename Enable = void>
   1.113 +  struct EdgeNotifierIndicator {
   1.114 +    typedef InvalidType Type;
   1.115 +  };
   1.116 +  template <typename Graph>
   1.117 +  struct EdgeNotifierIndicator<
   1.118 +    Graph, 
   1.119 +    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
   1.120 +  > { 
   1.121 +    typedef typename Graph::EdgeNotifier Type;
   1.122 +  };
   1.123 +
   1.124 +  template <typename _Graph>
   1.125 +  class ItemSetTraits<_Graph, typename _Graph::Edge> {
   1.126 +  public:
   1.127 +    
   1.128 +    typedef _Graph Graph;
   1.129 +
   1.130 +    typedef typename Graph::Edge Item;
   1.131 +    typedef typename Graph::EdgeIt ItemIt;
   1.132 +
   1.133 +    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
   1.134 +
   1.135 +    template <typename _Value>
   1.136 +    class Map : public Graph::template EdgeMap<_Value> {
   1.137 +    public:
   1.138 +      typedef typename Graph::template EdgeMap<_Value> Parent; 
   1.139 +      typedef typename Graph::template EdgeMap<_Value> Type; 
   1.140 +      typedef typename Parent::Value Value;
   1.141 +
   1.142 +      Map(const Graph& _digraph) : Parent(_digraph) {}
   1.143 +      Map(const Graph& _digraph, const Value& _value) 
   1.144 +	: Parent(_digraph, _value) {}
   1.145 +    };
   1.146 +
   1.147 +  };
   1.148 +
   1.149 +  template <typename Map, typename Enable = void>
   1.150 +  struct MapTraits {
   1.151 +    typedef False ReferenceMapTag;
   1.152 +
   1.153 +    typedef typename Map::Key Key;
   1.154 +    typedef typename Map::Value Value;
   1.155 +
   1.156 +    typedef const Value ConstReturnValue;
   1.157 +    typedef const Value ReturnValue;
   1.158 +  };
   1.159 +
   1.160 +  template <typename Map>
   1.161 +  struct MapTraits<
   1.162 +    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
   1.163 +  {
   1.164 +    typedef True ReferenceMapTag;
   1.165 +    
   1.166 +    typedef typename Map::Key Key;
   1.167 +    typedef typename Map::Value Value;
   1.168 +
   1.169 +    typedef typename Map::ConstReference ConstReturnValue;
   1.170 +    typedef typename Map::Reference ReturnValue;
   1.171 +
   1.172 +    typedef typename Map::ConstReference ConstReference; 
   1.173 +    typedef typename Map::Reference Reference;
   1.174 + };
   1.175 +
   1.176 +  template <typename MatrixMap, typename Enable = void>
   1.177 +  struct MatrixMapTraits {
   1.178 +    typedef False ReferenceMapTag;
   1.179 +
   1.180 +    typedef typename MatrixMap::FirstKey FirstKey;
   1.181 +    typedef typename MatrixMap::SecondKey SecondKey;
   1.182 +    typedef typename MatrixMap::Value Value;
   1.183 +
   1.184 +    typedef const Value ConstReturnValue;
   1.185 +    typedef const Value ReturnValue;
   1.186 +  };
   1.187 +
   1.188 +  template <typename MatrixMap>
   1.189 +  struct MatrixMapTraits<
   1.190 +    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
   1.191 +                                  void>::type > 
   1.192 +  {
   1.193 +    typedef True ReferenceMapTag;
   1.194 +    
   1.195 +    typedef typename MatrixMap::FirstKey FirstKey;
   1.196 +    typedef typename MatrixMap::SecondKey SecondKey;
   1.197 +    typedef typename MatrixMap::Value Value;
   1.198 +
   1.199 +    typedef typename MatrixMap::ConstReference ConstReturnValue;
   1.200 +    typedef typename MatrixMap::Reference ReturnValue;
   1.201 +
   1.202 +    typedef typename MatrixMap::ConstReference ConstReference; 
   1.203 +    typedef typename MatrixMap::Reference Reference;
   1.204 + };
   1.205 +
   1.206 +  // Indicators for the tags
   1.207 +
   1.208 +  template <typename Graph, typename Enable = void>
   1.209 +  struct NodeNumTagIndicator {
   1.210 +    static const bool value = false;
   1.211 +  };
   1.212 +
   1.213 +  template <typename Graph>
   1.214 +  struct NodeNumTagIndicator<
   1.215 +    Graph, 
   1.216 +    typename enable_if<typename Graph::NodeNumTag, void>::type
   1.217 +  > {
   1.218 +    static const bool value = true;
   1.219 +  };
   1.220 +
   1.221 +  template <typename Graph, typename Enable = void>
   1.222 +  struct ArcNumTagIndicator {
   1.223 +    static const bool value = false;
   1.224 +  };
   1.225 +
   1.226 +  template <typename Graph>
   1.227 +  struct ArcNumTagIndicator<
   1.228 +    Graph, 
   1.229 +    typename enable_if<typename Graph::ArcNumTag, void>::type
   1.230 +  > {
   1.231 +    static const bool value = true;
   1.232 +  };
   1.233 +
   1.234 +  template <typename Graph, typename Enable = void>
   1.235 +  struct FindArcTagIndicator {
   1.236 +    static const bool value = false;
   1.237 +  };
   1.238 +
   1.239 +  template <typename Graph>
   1.240 +  struct FindArcTagIndicator<
   1.241 +    Graph, 
   1.242 +    typename enable_if<typename Graph::FindArcTag, void>::type
   1.243 +  > {
   1.244 +    static const bool value = true;
   1.245 +  };
   1.246 +
   1.247 +  template <typename Graph, typename Enable = void>
   1.248 +  struct UndirectedTagIndicator {
   1.249 +    static const bool value = false;
   1.250 +  };
   1.251 +
   1.252 +  template <typename Graph>
   1.253 +  struct UndirectedTagIndicator<
   1.254 +    Graph, 
   1.255 +    typename enable_if<typename Graph::UndirectedTag, void>::type
   1.256 +  > {
   1.257 +    static const bool value = true;
   1.258 +  };
   1.259 +
   1.260 +  template <typename Graph, typename Enable = void>
   1.261 +  struct BuildTagIndicator {
   1.262 +    static const bool value = false;
   1.263 +  };
   1.264 +
   1.265 +  template <typename Graph>
   1.266 +  struct BuildTagIndicator<
   1.267 +    Graph, 
   1.268 +    typename enable_if<typename Graph::BuildTag, void>::type
   1.269 +  > {
   1.270 +    static const bool value = true;
   1.271 +  };
   1.272 +
   1.273 +}
   1.274 +
   1.275 +#endif