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@1092:  * Copyright (C) 2003-2013
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: 
kpeter@616:   template <typename GR, typename _Item>
deba@57:   class ItemSetTraits {};
alpar@209: 
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct NodeNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
kpeter@616:   template <typename GR>
deba@57:   struct NodeNotifierIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::NodeNotifier::Notifier, void>::type
alpar@209:   > {
kpeter@616:     typedef typename GR::NodeNotifier Type;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
kpeter@616:   class ItemSetTraits<GR, typename GR::Node> {
deba@57:   public:
alpar@209: 
kpeter@616:     typedef GR Graph;
kpeter@616:     typedef GR Digraph;
deba@57: 
kpeter@616:     typedef typename GR::Node Item;
kpeter@616:     typedef typename GR::NodeIt ItemIt;
deba@57: 
kpeter@616:     typedef typename NodeNotifierIndicator<GR>::Type ItemNotifier;
deba@57: 
kpeter@616:     template <typename V>
kpeter@616:     class Map : public GR::template NodeMap<V> {
kpeter@616:       typedef typename GR::template NodeMap<V> Parent;
kpeter@616: 
deba@57:     public:
kpeter@616:       typedef typename GR::template NodeMap<V> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
kpeter@616:       Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616:       Map(const GR& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57: 
deba@57:      };
deba@57: 
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct ArcNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
kpeter@616:   template <typename GR>
deba@57:   struct ArcNotifierIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::ArcNotifier::Notifier, void>::type
alpar@209:   > {
kpeter@616:     typedef typename GR::ArcNotifier Type;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
kpeter@616:   class ItemSetTraits<GR, typename GR::Arc> {
deba@57:   public:
alpar@209: 
kpeter@616:     typedef GR Graph;
kpeter@616:     typedef GR Digraph;
deba@57: 
kpeter@616:     typedef typename GR::Arc Item;
kpeter@616:     typedef typename GR::ArcIt ItemIt;
deba@57: 
kpeter@616:     typedef typename ArcNotifierIndicator<GR>::Type ItemNotifier;
deba@57: 
kpeter@616:     template <typename V>
kpeter@616:     class Map : public GR::template ArcMap<V> {
kpeter@616:       typedef typename GR::template ArcMap<V> Parent;
kpeter@616: 
deba@57:     public:
kpeter@616:       typedef typename GR::template ArcMap<V> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
kpeter@616:       Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616:       Map(const GR& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57:     };
deba@57: 
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct EdgeNotifierIndicator {
deba@57:     typedef InvalidType Type;
deba@57:   };
kpeter@616:   template <typename GR>
deba@57:   struct EdgeNotifierIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::EdgeNotifier::Notifier, void>::type
alpar@209:   > {
kpeter@616:     typedef typename GR::EdgeNotifier Type;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
kpeter@616:   class ItemSetTraits<GR, typename GR::Edge> {
deba@57:   public:
alpar@209: 
kpeter@616:     typedef GR Graph;
kpeter@616:     typedef GR Digraph;
deba@57: 
kpeter@616:     typedef typename GR::Edge Item;
kpeter@616:     typedef typename GR::EdgeIt ItemIt;
deba@57: 
kpeter@616:     typedef typename EdgeNotifierIndicator<GR>::Type ItemNotifier;
deba@57: 
kpeter@616:     template <typename V>
kpeter@616:     class Map : public GR::template EdgeMap<V> {
kpeter@616:       typedef typename GR::template EdgeMap<V> Parent;
kpeter@616: 
deba@57:     public:
kpeter@616:       typedef typename GR::template EdgeMap<V> Type;
deba@57:       typedef typename Parent::Value Value;
deba@57: 
kpeter@616:       Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616:       Map(const GR& _digraph, const Value& _value)
alpar@209:         : Parent(_digraph, _value) {}
deba@57:     };
deba@57: 
deba@57:   };
deba@57: 
deba@1019:   template <typename GR, typename Enable = void>
deba@1019:   struct RedNodeNotifierIndicator {
deba@1019:     typedef InvalidType Type;
deba@1019:   };
deba@1019:   template <typename GR>
deba@1019:   struct RedNodeNotifierIndicator<
deba@1019:     GR,
deba@1019:     typename enable_if<typename GR::RedNodeNotifier::Notifier, void>::type
deba@1019:   > {
deba@1019:     typedef typename GR::RedNodeNotifier Type;
deba@1019:   };
deba@1019: 
deba@1019:   template <typename GR>
deba@1019:   class ItemSetTraits<GR, typename GR::RedNode> {
deba@1019:   public:
deba@1019: 
deba@1019:     typedef GR BpGraph;
deba@1019:     typedef GR Graph;
deba@1019:     typedef GR Digraph;
deba@1019: 
deba@1019:     typedef typename GR::RedNode Item;
deba@1026:     typedef typename GR::RedNodeIt ItemIt;
deba@1019: 
deba@1019:     typedef typename RedNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1019: 
deba@1019:     template <typename V>
deba@1026:     class Map : public GR::template RedNodeMap<V> {
deba@1026:       typedef typename GR::template RedNodeMap<V> Parent;
deba@1019: 
deba@1019:     public:
deba@1026:       typedef typename GR::template RedNodeMap<V> Type;
deba@1019:       typedef typename Parent::Value Value;
deba@1019: 
deba@1019:       Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1019:       Map(const GR& _bpgraph, const Value& _value)
deba@1019:         : Parent(_bpgraph, _value) {}
deba@1019: 
deba@1019:      };
deba@1019: 
deba@1019:   };
deba@1019: 
deba@1019:   template <typename GR, typename Enable = void>
deba@1019:   struct BlueNodeNotifierIndicator {
deba@1019:     typedef InvalidType Type;
deba@1019:   };
deba@1019:   template <typename GR>
deba@1019:   struct BlueNodeNotifierIndicator<
deba@1019:     GR,
deba@1019:     typename enable_if<typename GR::BlueNodeNotifier::Notifier, void>::type
deba@1019:   > {
deba@1019:     typedef typename GR::BlueNodeNotifier Type;
deba@1019:   };
deba@1019: 
deba@1019:   template <typename GR>
deba@1019:   class ItemSetTraits<GR, typename GR::BlueNode> {
deba@1019:   public:
deba@1019: 
deba@1019:     typedef GR BpGraph;
deba@1019:     typedef GR Graph;
deba@1019:     typedef GR Digraph;
deba@1019: 
deba@1019:     typedef typename GR::BlueNode Item;
deba@1026:     typedef typename GR::BlueNodeIt ItemIt;
deba@1019: 
deba@1019:     typedef typename BlueNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1019: 
deba@1019:     template <typename V>
deba@1026:     class Map : public GR::template BlueNodeMap<V> {
deba@1026:       typedef typename GR::template BlueNodeMap<V> Parent;
deba@1019: 
deba@1019:     public:
deba@1026:       typedef typename GR::template BlueNodeMap<V> Type;
deba@1019:       typedef typename Parent::Value Value;
deba@1019: 
deba@1019:       Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1019:       Map(const GR& _bpgraph, const Value& _value)
deba@1019:         : Parent(_bpgraph, _value) {}
deba@1019: 
deba@1019:      };
deba@1019: 
deba@1019:   };
deba@1019: 
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: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct NodeNumTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
deba@57:   struct NodeNumTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::NodeNumTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
kpeter@360:   struct ArcNumTagIndicator {
kpeter@360:     static const bool value = false;
kpeter@360:   };
kpeter@360: 
kpeter@616:   template <typename GR>
kpeter@360:   struct ArcNumTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::ArcNumTag, void>::type
kpeter@360:   > {
kpeter@360:     static const bool value = true;
kpeter@360:   };
kpeter@360: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@139:   struct EdgeNumTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
deba@139:   struct EdgeNumTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::EdgeNumTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
kpeter@360:   struct FindArcTagIndicator {
kpeter@360:     static const bool value = false;
kpeter@360:   };
kpeter@360: 
kpeter@616:   template <typename GR>
kpeter@360:   struct FindArcTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::FindArcTag, void>::type
kpeter@360:   > {
kpeter@360:     static const bool value = true;
kpeter@360:   };
kpeter@360: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@139:   struct FindEdgeTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
deba@139:   struct FindEdgeTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::FindEdgeTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct UndirectedTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
deba@57:   struct UndirectedTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::UndirectedTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR, typename Enable = void>
deba@57:   struct BuildTagIndicator {
deba@57:     static const bool value = false;
deba@57:   };
deba@57: 
kpeter@616:   template <typename GR>
deba@57:   struct BuildTagIndicator<
kpeter@616:     GR,
kpeter@616:     typename enable_if<typename GR::BuildTag, void>::type
deba@57:   > {
deba@57:     static const bool value = true;
deba@57:   };
deba@57: 
deba@57: }
deba@57: 
deba@57: #endif