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 deba@220: deba@57: namespace lemon { deba@220: deba@220: struct InvalidType {}; deba@220: kpeter@616: template deba@57: class ItemSetTraits {}; alpar@209: deba@57: kpeter@616: template deba@57: struct NodeNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; kpeter@616: template deba@57: struct NodeNotifierIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type alpar@209: > { kpeter@616: typedef typename GR::NodeNotifier Type; deba@57: }; deba@57: kpeter@616: template kpeter@616: class ItemSetTraits { 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::Type ItemNotifier; deba@57: kpeter@616: template kpeter@616: class Map : public GR::template NodeMap { kpeter@616: typedef typename GR::template NodeMap Parent; kpeter@616: deba@57: public: kpeter@616: typedef typename GR::template NodeMap 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 deba@57: struct ArcNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; kpeter@616: template deba@57: struct ArcNotifierIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type alpar@209: > { kpeter@616: typedef typename GR::ArcNotifier Type; deba@57: }; deba@57: kpeter@616: template kpeter@616: class ItemSetTraits { 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::Type ItemNotifier; deba@57: kpeter@616: template kpeter@616: class Map : public GR::template ArcMap { kpeter@616: typedef typename GR::template ArcMap Parent; kpeter@616: deba@57: public: kpeter@616: typedef typename GR::template ArcMap 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 deba@57: struct EdgeNotifierIndicator { deba@57: typedef InvalidType Type; deba@57: }; kpeter@616: template deba@57: struct EdgeNotifierIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type alpar@209: > { kpeter@616: typedef typename GR::EdgeNotifier Type; deba@57: }; deba@57: kpeter@616: template kpeter@616: class ItemSetTraits { 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::Type ItemNotifier; deba@57: kpeter@616: template kpeter@616: class Map : public GR::template EdgeMap { kpeter@616: typedef typename GR::template EdgeMap Parent; kpeter@616: deba@57: public: kpeter@616: typedef typename GR::template EdgeMap 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: 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: kpeter@616: template deba@57: struct NodeNumTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: kpeter@616: template deba@57: struct NodeNumTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: kpeter@616: template kpeter@360: struct ArcNumTagIndicator { kpeter@360: static const bool value = false; kpeter@360: }; kpeter@360: kpeter@616: template kpeter@360: struct ArcNumTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type kpeter@360: > { kpeter@360: static const bool value = true; kpeter@360: }; kpeter@360: kpeter@616: template deba@139: struct EdgeNumTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: kpeter@616: template deba@139: struct EdgeNumTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: kpeter@616: template kpeter@360: struct FindArcTagIndicator { kpeter@360: static const bool value = false; kpeter@360: }; kpeter@360: kpeter@616: template kpeter@360: struct FindArcTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type kpeter@360: > { kpeter@360: static const bool value = true; kpeter@360: }; kpeter@360: kpeter@616: template deba@139: struct FindEdgeTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: kpeter@616: template deba@139: struct FindEdgeTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: kpeter@616: template deba@57: struct UndirectedTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: kpeter@616: template deba@57: struct UndirectedTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: kpeter@616: template deba@57: struct BuildTagIndicator { deba@57: static const bool value = false; deba@57: }; deba@57: kpeter@616: template deba@57: struct BuildTagIndicator< kpeter@616: GR, kpeter@616: typename enable_if::type deba@57: > { deba@57: static const bool value = true; deba@57: }; deba@57: deba@57: } deba@57: deba@57: #endif