alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57:  *
alpar@209:  * This file is a part of LEMON, a generic C++ optimization library.
deba@57:  *
alpar@440:  * Copyright (C) 2003-2009
deba@57:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57:  *
deba@57:  * Permission to use, modify and distribute this software is granted
deba@57:  * provided that this copyright notice appears in all copies. For
deba@57:  * precise terms see the accompanying LICENSE file.
deba@57:  *
deba@57:  * This software is provided "AS IS" with no warranty of any kind,
deba@57:  * express or implied, and with no claim as to its suitability for any
deba@57:  * purpose.
deba@57:  *
deba@57:  */
deba@57: 
deba@57: #ifndef LEMON_BITS_TRAITS_H
deba@57: #define LEMON_BITS_TRAITS_H
deba@57: 
kpeter@314: //\file
kpeter@314: //\brief Traits for graphs and maps
kpeter@314: //
deba@57: 
deba@220: #include <lemon/bits/enable_if.h>
deba@220: 
deba@57: namespace lemon {
deba@220: 
deba@220:   struct InvalidType {};
deba@220: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   class ItemSetTraits {};
alpar@209: 
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct NodeNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
deba@57:   template <typename Graph>
deba@57:   struct NodeNotifierIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
alpar@209:   > {
deba@57:     typedef typename Graph::NodeNotifier Type;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph>
deba@57:   class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@57:   public:
alpar@209: 
deba@57:     typedef _Graph Graph;
deba@57: 
deba@57:     typedef typename Graph::Node Item;
deba@57:     typedef typename Graph::NodeIt ItemIt;
deba@57: 
deba@57:     typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57: 
deba@57:     template <typename _Value>
deba@57:     class Map : public Graph::template NodeMap<_Value> {
deba@57:     public:
alpar@209:       typedef typename Graph::template NodeMap<_Value> Parent;
alpar@209:       typedef typename Graph::template NodeMap<_Value> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209:       Map(const Graph& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57: 
deba@57:      };
deba@57: 
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct ArcNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
deba@57:   template <typename Graph>
deba@57:   struct ArcNotifierIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
alpar@209:   > {
deba@57:     typedef typename Graph::ArcNotifier Type;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph>
deba@57:   class ItemSetTraits<_Graph, typename _Graph::Arc> {
deba@57:   public:
alpar@209: 
deba@57:     typedef _Graph Graph;
deba@57: 
deba@57:     typedef typename Graph::Arc Item;
deba@57:     typedef typename Graph::ArcIt ItemIt;
deba@57: 
deba@57:     typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
deba@57: 
deba@57:     template <typename _Value>
deba@57:     class Map : public Graph::template ArcMap<_Value> {
deba@57:     public:
alpar@209:       typedef typename Graph::template ArcMap<_Value> Parent;
alpar@209:       typedef typename Graph::template ArcMap<_Value> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209:       Map(const Graph& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57:     };
deba@57: 
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct EdgeNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
deba@57:   template <typename Graph>
deba@57:   struct EdgeNotifierIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
alpar@209:   > {
deba@57:     typedef typename Graph::EdgeNotifier Type;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph>
deba@57:   class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@57:   public:
alpar@209: 
deba@57:     typedef _Graph Graph;
deba@57: 
deba@57:     typedef typename Graph::Edge Item;
deba@57:     typedef typename Graph::EdgeIt ItemIt;
deba@57: 
deba@57:     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57: 
deba@57:     template <typename _Value>
deba@57:     class Map : public Graph::template EdgeMap<_Value> {
deba@57:     public:
alpar@209:       typedef typename Graph::template EdgeMap<_Value> Parent;
alpar@209:       typedef typename Graph::template EdgeMap<_Value> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209:       Map(const Graph& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57:     };
deba@57: 
deba@57:   };
deba@57: 
deba@57:   template <typename Map, typename Enable = void>
deba@57:   struct MapTraits {
deba@57:     typedef False ReferenceMapTag;
deba@57: 
deba@57:     typedef typename Map::Key Key;
deba@57:     typedef typename Map::Value Value;
deba@57: 
alpar@184:     typedef Value ConstReturnValue;
alpar@184:     typedef Value ReturnValue;
deba@57:   };
deba@57: 
deba@57:   template <typename Map>
deba@57:   struct MapTraits<
alpar@209:     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
deba@57:   {
deba@57:     typedef True ReferenceMapTag;
alpar@209: 
deba@57:     typedef typename Map::Key Key;
deba@57:     typedef typename Map::Value Value;
deba@57: 
deba@57:     typedef typename Map::ConstReference ConstReturnValue;
deba@57:     typedef typename Map::Reference ReturnValue;
deba@57: 
alpar@209:     typedef typename Map::ConstReference ConstReference;
deba@57:     typedef typename Map::Reference Reference;
deba@57:  };
deba@57: 
deba@57:   template <typename MatrixMap, typename Enable = void>
deba@57:   struct MatrixMapTraits {
deba@57:     typedef False ReferenceMapTag;
deba@57: 
deba@57:     typedef typename MatrixMap::FirstKey FirstKey;
deba@57:     typedef typename MatrixMap::SecondKey SecondKey;
deba@57:     typedef typename MatrixMap::Value Value;
deba@57: 
alpar@184:     typedef Value ConstReturnValue;
alpar@184:     typedef Value ReturnValue;
deba@57:   };
deba@57: 
deba@57:   template <typename MatrixMap>
deba@57:   struct MatrixMapTraits<
alpar@209:     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
alpar@209:                                   void>::type >
deba@57:   {
deba@57:     typedef True ReferenceMapTag;
alpar@209: 
deba@57:     typedef typename MatrixMap::FirstKey FirstKey;
deba@57:     typedef typename MatrixMap::SecondKey SecondKey;
deba@57:     typedef typename MatrixMap::Value Value;
deba@57: 
deba@57:     typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57:     typedef typename MatrixMap::Reference ReturnValue;
deba@57: 
alpar@209:     typedef typename MatrixMap::ConstReference ConstReference;
deba@57:     typedef typename MatrixMap::Reference Reference;
deba@57:  };
deba@57: 
deba@57:   // Indicators for the tags
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct NodeNumTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@57:   struct NodeNumTagIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::NodeNumTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
kpeter@360:   struct ArcNumTagIndicator {
kpeter@360:     static const bool value = false;
kpeter@360:   };
kpeter@360: 
kpeter@360:   template <typename Graph>
kpeter@360:   struct ArcNumTagIndicator<
kpeter@360:     Graph,
kpeter@360:     typename enable_if<typename Graph::ArcNumTag, void>::type
kpeter@360:   > {
kpeter@360:     static const bool value = true;
kpeter@360:   };
kpeter@360: 
kpeter@360:   template <typename Graph, typename Enable = void>
deba@139:   struct EdgeNumTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@139:   struct EdgeNumTagIndicator<
alpar@209:     Graph,
deba@139:     typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
kpeter@360:   struct FindArcTagIndicator {
kpeter@360:     static const bool value = false;
kpeter@360:   };
kpeter@360: 
kpeter@360:   template <typename Graph>
kpeter@360:   struct FindArcTagIndicator<
kpeter@360:     Graph,
kpeter@360:     typename enable_if<typename Graph::FindArcTag, void>::type
kpeter@360:   > {
kpeter@360:     static const bool value = true;
kpeter@360:   };
kpeter@360: 
kpeter@360:   template <typename Graph, typename Enable = void>
deba@139:   struct FindEdgeTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@139:   struct FindEdgeTagIndicator<
alpar@209:     Graph,
deba@139:     typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct UndirectedTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@57:   struct UndirectedTagIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::UndirectedTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph, typename Enable = void>
deba@57:   struct BuildTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@57:   struct BuildTagIndicator<
alpar@209:     Graph,
deba@57:     typename enable_if<typename Graph::BuildTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57: }
deba@57: 
deba@57: #endif