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_DEFAULT_MAP_H
deba@57: #define LEMON_BITS_DEFAULT_MAP_H
deba@57: 
alpar@491: #include <lemon/config.h>
deba@57: #include <lemon/bits/array_map.h>
deba@57: #include <lemon/bits/vector_map.h>
deba@57: //#include <lemon/bits/debug_map.h>
deba@57: 
kpeter@314: //\ingroup graphbits
kpeter@314: //\file
kpeter@314: //\brief Graph maps that construct and destruct their elements dynamically.
deba@57: 
deba@57: namespace lemon {
alpar@209: 
alpar@209: 
deba@57:   //#ifndef LEMON_USE_DEBUG_MAP
deba@57: 
deba@57:   template <typename _Graph, typename _Item, typename _Value>
deba@57:   struct DefaultMapSelector {
deba@57:     typedef ArrayMap<_Graph, _Item, _Value> Map;
deba@57:   };
deba@57: 
deba@57:   // bool
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, bool> {
deba@57:     typedef VectorMap<_Graph, _Item, bool> Map;
deba@57:   };
deba@57: 
deba@57:   // char
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, char> {
deba@57:     typedef VectorMap<_Graph, _Item, char> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, signed char> {
deba@57:     typedef VectorMap<_Graph, _Item, signed char> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
deba@57:     typedef VectorMap<_Graph, _Item, unsigned char> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // int
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, signed int> {
deba@57:     typedef VectorMap<_Graph, _Item, signed int> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
deba@57:     typedef VectorMap<_Graph, _Item, unsigned int> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // short
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, signed short> {
deba@57:     typedef VectorMap<_Graph, _Item, signed short> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
deba@57:     typedef VectorMap<_Graph, _Item, unsigned short> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // long
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, signed long> {
deba@57:     typedef VectorMap<_Graph, _Item, signed long> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
deba@57:     typedef VectorMap<_Graph, _Item, unsigned long> Map;
deba@57:   };
deba@57: 
deba@57: 
alpar@485: #if defined HAVE_LONG_LONG
deba@57: 
deba@57:   // long long
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, signed long long> {
deba@57:     typedef VectorMap<_Graph, _Item, signed long long> Map;
deba@57:   };
deba@57: 
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
deba@57:     typedef VectorMap<_Graph, _Item, unsigned long long> Map;
deba@57:   };
deba@57: 
deba@57: #endif
deba@57: 
deba@57: 
deba@57:   // float
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, float> {
deba@57:     typedef VectorMap<_Graph, _Item, float> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // double
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, double> {
deba@57:     typedef VectorMap<_Graph, _Item,  double> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // long double
deba@57:   template <typename _Graph, typename _Item>
deba@57:   struct DefaultMapSelector<_Graph, _Item, long double> {
deba@57:     typedef VectorMap<_Graph, _Item, long double> Map;
deba@57:   };
deba@57: 
deba@57: 
deba@57:   // pointer
deba@57:   template <typename _Graph, typename _Item, typename _Ptr>
deba@57:   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
deba@57:     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
deba@57:   };
deba@57: 
alpar@209: // #else
deba@57: 
deba@57: //   template <typename _Graph, typename _Item, typename _Value>
deba@57: //   struct DefaultMapSelector {
deba@57: //     typedef DebugMap<_Graph, _Item, _Value> Map;
deba@57: //   };
deba@57: 
alpar@209: // #endif
deba@57: 
kpeter@314:   // DefaultMap class
deba@57:   template <typename _Graph, typename _Item, typename _Value>
alpar@209:   class DefaultMap
deba@57:     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
deba@57:   public:
deba@57:     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
deba@57:     typedef DefaultMap<_Graph, _Item, _Value> Map;
alpar@209: 
deba@57:     typedef typename Parent::Graph Graph;
deba@57:     typedef typename Parent::Value Value;
deba@57: 
deba@57:     explicit DefaultMap(const Graph& graph) : Parent(graph) {}
alpar@209:     DefaultMap(const Graph& graph, const Value& value)
deba@57:       : Parent(graph, value) {}
deba@57: 
deba@57:     DefaultMap& operator=(const DefaultMap& cmap) {
deba@57:       return operator=<DefaultMap>(cmap);
deba@57:     }
deba@57: 
deba@57:     template <typename CMap>
deba@57:     DefaultMap& operator=(const CMap& cmap) {
deba@57:       Parent::operator=(cmap);
deba@57:       return *this;
deba@57:     }
deba@57: 
deba@57:   };
deba@57: 
deba@57: }
deba@57: 
deba@57: #endif