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@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: ///\file deba@57: ///\brief Traits for graphs and maps deba@57: /// deba@57: deba@220: #include deba@220: deba@57: namespace lemon { deba@220: deba@220: struct InvalidType {}; deba@220: deba@57: template deba@57: class ItemSetTraits {}; alpar@209: deba@57: deba@57: template deba@57: struct NodeNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; deba@57: template deba@57: struct NodeNotifierIndicator< alpar@209: Graph, deba@57: typename enable_if::type alpar@209: > { deba@57: typedef typename Graph::NodeNotifier Type; deba@57: }; deba@57: deba@57: template 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::Type ItemNotifier; deba@57: deba@57: template 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 deba@57: struct ArcNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; deba@57: template deba@57: struct ArcNotifierIndicator< alpar@209: Graph, deba@57: typename enable_if::type alpar@209: > { deba@57: typedef typename Graph::ArcNotifier Type; deba@57: }; deba@57: deba@57: template 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::Type ItemNotifier; deba@57: deba@57: template 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 deba@57: struct EdgeNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; deba@57: template deba@57: struct EdgeNotifierIndicator< alpar@209: Graph, deba@57: typename enable_if::type alpar@209: > { deba@57: typedef typename Graph::EdgeNotifier Type; deba@57: }; deba@57: deba@57: template 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::Type ItemNotifier; deba@57: deba@57: template 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 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 deba@57: struct MapTraits< alpar@209: Map, typename enable_if::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 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 deba@57: struct MatrixMapTraits< alpar@209: MatrixMap, typename enable_if::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 deba@57: struct NodeNumTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: deba@57: template deba@57: struct NodeNumTagIndicator< alpar@209: Graph, deba@57: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: template deba@139: struct EdgeNumTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: deba@57: template deba@139: struct EdgeNumTagIndicator< alpar@209: Graph, deba@139: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: template deba@139: struct FindEdgeTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: deba@57: template deba@139: struct FindEdgeTagIndicator< alpar@209: Graph, deba@139: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: template deba@57: struct UndirectedTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: deba@57: template deba@57: struct UndirectedTagIndicator< alpar@209: Graph, deba@57: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: template deba@57: struct BuildTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: deba@57: template deba@57: struct BuildTagIndicator< alpar@209: Graph, deba@57: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: } deba@57: deba@57: #endif