deba@57: 
deba@57: /* -*- C++ -*-
deba@57:  *
deba@57:  * This file is a part of LEMON, a generic C++ optimization library
deba@57:  *
alpar@107:  * Copyright (C) 2003-2008
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: 
deba@57: #include <lemon/bits/utility.h>
deba@57: 
deba@57: ///\file
deba@57: ///\brief Traits for graphs and maps
deba@57: ///
deba@57: 
deba@57: namespace lemon {
deba@57:   template <typename _Graph, typename _Item>
deba@57:   class ItemSetTraits {};
deba@57:   
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<
deba@57:     Graph, 
deba@57:     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
deba@57:   > { 
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:
deba@57:     
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:
deba@57:       typedef typename Graph::template NodeMap<_Value> Parent; 
deba@57:       typedef typename Graph::template NodeMap<_Value> Type; 
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57:       Map(const Graph& _digraph, const Value& _value) 
deba@57: 	: 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<
deba@57:     Graph, 
deba@57:     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
deba@57:   > { 
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:
deba@57:     
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:
deba@57:       typedef typename Graph::template ArcMap<_Value> Parent; 
deba@57:       typedef typename Graph::template ArcMap<_Value> Type; 
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57:       Map(const Graph& _digraph, const Value& _value) 
deba@57: 	: 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<
deba@57:     Graph, 
deba@57:     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
deba@57:   > { 
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:
deba@57:     
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:
deba@57:       typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@57:       typedef typename Graph::template EdgeMap<_Value> Type; 
deba@57:       typedef typename Parent::Value Value;
deba@57: 
deba@57:       Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57:       Map(const Graph& _digraph, const Value& _value) 
deba@57: 	: 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: 
deba@57:     typedef const Value ConstReturnValue;
deba@57:     typedef const Value ReturnValue;
deba@57:   };
deba@57: 
deba@57:   template <typename Map>
deba@57:   struct MapTraits<
deba@57:     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@57:   {
deba@57:     typedef True ReferenceMapTag;
deba@57:     
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: 
deba@57:     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: 
deba@57:     typedef const Value ConstReturnValue;
deba@57:     typedef const Value ReturnValue;
deba@57:   };
deba@57: 
deba@57:   template <typename MatrixMap>
deba@57:   struct MatrixMapTraits<
deba@57:     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
deba@57:                                   void>::type > 
deba@57:   {
deba@57:     typedef True 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: 
deba@57:     typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57:     typedef typename MatrixMap::Reference ReturnValue;
deba@57: 
deba@57:     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<
deba@57:     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>
deba@57:   struct ArcNumTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@57:   struct ArcNumTagIndicator<
deba@57:     Graph, 
deba@57:     typename enable_if<typename Graph::ArcNumTag, 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 FindArcTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
deba@57:   template <typename Graph>
deba@57:   struct FindArcTagIndicator<
deba@57:     Graph, 
deba@57:     typename enable_if<typename Graph::FindArcTag, 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<
deba@57:     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<
deba@57:     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