alpar@906: /* -*- C++ -*-
ladanyi@1435:  * lemon/default_map.h - Part of LEMON, a generic C++ optimization library
alpar@906:  *
alpar@1164:  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906:  *
alpar@906:  * Permission to use, modify and distribute this software is granted
alpar@906:  * provided that this copyright notice appears in all copies. For
alpar@906:  * precise terms see the accompanying LICENSE file.
alpar@906:  *
alpar@906:  * This software is provided "AS IS" with no warranty of any kind,
alpar@906:  * express or implied, and with no claim as to its suitability for any
alpar@906:  * purpose.
alpar@906:  *
alpar@906:  */
alpar@906: 
alpar@921: #ifndef LEMON_DEFAULT_MAP_H
alpar@921: #define LEMON_DEFAULT_MAP_H
deba@822: 
deba@822: 
deba@1307: #include <lemon/bits/array_map.h>
deba@1307: #include <lemon/bits/vector_map.h>
deba@822: 
deba@822: ///\ingroup graphmaps
deba@822: ///\file
klao@946: ///\brief Graph maps that construct and destruct
deba@822: ///their elements dynamically.
deba@822: 
alpar@921: namespace lemon {
deba@822: 
deba@822: /// \addtogroup graphmaps
deba@822: /// @{
deba@822: 
deba@822:   /** The ArrayMap template class is graph map structure what
deba@822:    *  automatically updates the map when a key is added to or erased from
alpar@987:    *  the map. This map uses the VectorMap if the Value is a primitive
deba@822:    *  type and the ArrayMap for the other cases.
deba@822:    *
deba@822:    *  The template parameter is the MapRegistry that the maps
alpar@987:    *  will belong to and the Value.
deba@822:    */
deba@822: 
deba@822: 
deba@822: 
deba@1267:   template <typename _Graph, typename _Item, typename _Value>
klao@946:   struct DefaultMapSelector {
deba@1267:     typedef ArrayMap<_Graph, _Item, _Value> Map;
klao@946:   };
deba@822: 
klao@946:   // bool
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, bool> {
deba@980:     typedef VectorMap<_Graph, _Item, bool> Map;
klao@946:   };
deba@822: 
klao@946:   // char
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, char> {
deba@980:     typedef VectorMap<_Graph, _Item, char> Map;
klao@946:   };
deba@822: 
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, signed char> {
deba@980:     typedef VectorMap<_Graph, _Item, signed char> Map;
klao@946:   };
deba@822: 
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
deba@980:     typedef VectorMap<_Graph, _Item, unsigned char> Map;
klao@946:   };
deba@822: 
deba@822: 
klao@946:   // int
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, signed int> {
deba@980:     typedef VectorMap<_Graph, _Item, signed int> Map;
klao@946:   };
deba@822: 
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
deba@980:     typedef VectorMap<_Graph, _Item, unsigned int> Map;
klao@946:   };
deba@822: 
deba@822: 
klao@946:   // short
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, signed short> {
deba@980:     typedef VectorMap<_Graph, _Item, signed short> Map;
klao@946:   };
deba@822: 
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
deba@980:     typedef VectorMap<_Graph, _Item, unsigned short> Map;
klao@946:   };
klao@946: 
klao@946: 
klao@946:   // long
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, signed long> {
deba@980:     typedef VectorMap<_Graph, _Item, signed long> Map;
klao@946:   };
klao@946: 
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
deba@980:     typedef VectorMap<_Graph, _Item, unsigned long> Map;
klao@946:   };
klao@946: 
klao@946:   // \todo handling long long type
klao@946: 
klao@946: 
klao@946:   // float
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, float> {
deba@980:     typedef VectorMap<_Graph, _Item, float> Map;
klao@946:   };
klao@946: 
klao@946: 
klao@946:   // double
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, double> {
deba@980:     typedef VectorMap<_Graph, _Item,  double> Map;
klao@946:   };
klao@946: 
klao@946: 
klao@946:   // long double
deba@1267:   template <typename _Graph, typename _Item>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, long double> {
deba@980:     typedef VectorMap<_Graph, _Item, long double> Map;
klao@946:   };
klao@946: 
klao@946: 
klao@946:   // pointer
deba@1267:   template <typename _Graph, typename _Item, typename _Ptr>
deba@1267:   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
deba@980:     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
klao@946:   };
klao@946: 
klao@946: 
klao@946: 
deba@1267:   template <
deba@1267:     typename _Graph, 
deba@1267:     typename _Item,
deba@1267:     typename _Value>
deba@1267:   class DefaultMap 
deba@1267:     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
klao@946:   public:
deba@1267:     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
deba@1267:     typedef DefaultMap<_Graph, _Item, _Value> Map;
klao@946:     
klao@946:     typedef typename Parent::Graph Graph;
alpar@987:     typedef typename Parent::Value Value;
klao@946: 
deba@980:     DefaultMap(const Graph& _g) : Parent(_g) {}
alpar@987:     DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
klao@946:   };
klao@946: 
klao@946: 
klao@946: 
klao@946:   template <typename _Base> 
klao@946:   class DefaultMappableGraphExtender : public _Base {
klao@946:   public:
klao@946: 
klao@946:     typedef DefaultMappableGraphExtender<_Base> Graph;
klao@946:     typedef _Base Parent;
klao@946: 
klao@946:     typedef typename Parent::Node Node;
klao@946:     typedef typename Parent::NodeIt NodeIt;
klao@946: 
klao@946:     typedef typename Parent::Edge Edge;
klao@946:     typedef typename Parent::EdgeIt EdgeIt;
klao@946: 
klao@946:     
klao@946:     template <typename _Value>
deba@1267:     class NodeMap 
deba@1267:       : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
klao@946:     public:
klao@1022:       typedef DefaultMappableGraphExtender Graph;
deba@1267:       typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
klao@946: 
deba@980:       NodeMap(const Graph& _g) 
deba@980: 	: Parent(_g) {}
klao@1022:       NodeMap(const Graph& _g, const _Value& _v) 
deba@980: 	: Parent(_g, _v) {}
klao@946:     };
klao@946: 
klao@946:     template <typename _Value>
deba@1267:     class EdgeMap 
deba@1267:       : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
klao@946:     public:
klao@1022:       typedef DefaultMappableGraphExtender Graph;
deba@1267:       typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
klao@946: 
deba@980:       EdgeMap(const Graph& _g) 
deba@980: 	: Parent(_g) {}
klao@1022:       EdgeMap(const Graph& _g, const _Value& _v) 
deba@980: 	: Parent(_g, _v) {}
klao@946:     };
klao@946:     
klao@946:   };
klao@946: 
klao@1022:   template <typename _Base> 
klao@1022:   class MappableUndirGraphExtender : 
klao@1022:     public DefaultMappableGraphExtender<_Base> {
klao@1022:   public:
klao@1022: 
klao@1022:     typedef MappableUndirGraphExtender Graph;
klao@1022:     typedef DefaultMappableGraphExtender<_Base> Parent;
klao@1022: 
klao@1022:     typedef typename Parent::UndirEdge UndirEdge;
klao@1022: 
klao@1022:     template <typename _Value>
deba@1267:     class UndirEdgeMap 
deba@1267:       : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
klao@1022:     public:
klao@1022:       typedef MappableUndirGraphExtender Graph;
deba@1267:       typedef IterableMapExtender<
deba@1267: 	DefaultMap<Graph, UndirEdge, _Value> > Parent;
klao@1022: 
klao@1022:       UndirEdgeMap(const Graph& _g) 
klao@1022: 	: Parent(_g) {}
klao@1022:       UndirEdgeMap(const Graph& _g, const _Value& _v) 
klao@1022: 	: Parent(_g, _v) {}
klao@1022:     };
klao@1022: 
klao@1022: 
klao@1022:   };
deba@822: 
deba@822: }
deba@822: 
deba@822: #endif