lemon/bits/default_map.h
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 08 Dec 2008 21:47:15 +0000
branch1.0
changeset 348 a07eb292dd95
parent 317 64f8f7cc6168
child 372 7992dcb0d0e6
permissions -rw-r--r--
Merge bugfix #193
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_BITS_DEFAULT_MAP_H
    20 #define LEMON_BITS_DEFAULT_MAP_H
    21 
    22 #include <lemon/bits/array_map.h>
    23 #include <lemon/bits/vector_map.h>
    24 //#include <lemon/bits/debug_map.h>
    25 
    26 //\ingroup graphbits
    27 //\file
    28 //\brief Graph maps that construct and destruct their elements dynamically.
    29 
    30 namespace lemon {
    31 
    32 
    33   //#ifndef LEMON_USE_DEBUG_MAP
    34 
    35   template <typename _Graph, typename _Item, typename _Value>
    36   struct DefaultMapSelector {
    37     typedef ArrayMap<_Graph, _Item, _Value> Map;
    38   };
    39 
    40   // bool
    41   template <typename _Graph, typename _Item>
    42   struct DefaultMapSelector<_Graph, _Item, bool> {
    43     typedef VectorMap<_Graph, _Item, bool> Map;
    44   };
    45 
    46   // char
    47   template <typename _Graph, typename _Item>
    48   struct DefaultMapSelector<_Graph, _Item, char> {
    49     typedef VectorMap<_Graph, _Item, char> Map;
    50   };
    51 
    52   template <typename _Graph, typename _Item>
    53   struct DefaultMapSelector<_Graph, _Item, signed char> {
    54     typedef VectorMap<_Graph, _Item, signed char> Map;
    55   };
    56 
    57   template <typename _Graph, typename _Item>
    58   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
    59     typedef VectorMap<_Graph, _Item, unsigned char> Map;
    60   };
    61 
    62 
    63   // int
    64   template <typename _Graph, typename _Item>
    65   struct DefaultMapSelector<_Graph, _Item, signed int> {
    66     typedef VectorMap<_Graph, _Item, signed int> Map;
    67   };
    68 
    69   template <typename _Graph, typename _Item>
    70   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
    71     typedef VectorMap<_Graph, _Item, unsigned int> Map;
    72   };
    73 
    74 
    75   // short
    76   template <typename _Graph, typename _Item>
    77   struct DefaultMapSelector<_Graph, _Item, signed short> {
    78     typedef VectorMap<_Graph, _Item, signed short> Map;
    79   };
    80 
    81   template <typename _Graph, typename _Item>
    82   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
    83     typedef VectorMap<_Graph, _Item, unsigned short> Map;
    84   };
    85 
    86 
    87   // long
    88   template <typename _Graph, typename _Item>
    89   struct DefaultMapSelector<_Graph, _Item, signed long> {
    90     typedef VectorMap<_Graph, _Item, signed long> Map;
    91   };
    92 
    93   template <typename _Graph, typename _Item>
    94   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
    95     typedef VectorMap<_Graph, _Item, unsigned long> Map;
    96   };
    97 
    98 
    99 #if defined __GNUC__ && !defined __STRICT_ANSI__
   100 
   101   // long long
   102   template <typename _Graph, typename _Item>
   103   struct DefaultMapSelector<_Graph, _Item, signed long long> {
   104     typedef VectorMap<_Graph, _Item, signed long long> Map;
   105   };
   106 
   107   template <typename _Graph, typename _Item>
   108   struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
   109     typedef VectorMap<_Graph, _Item, unsigned long long> Map;
   110   };
   111 
   112 #endif
   113 
   114 
   115   // float
   116   template <typename _Graph, typename _Item>
   117   struct DefaultMapSelector<_Graph, _Item, float> {
   118     typedef VectorMap<_Graph, _Item, float> Map;
   119   };
   120 
   121 
   122   // double
   123   template <typename _Graph, typename _Item>
   124   struct DefaultMapSelector<_Graph, _Item, double> {
   125     typedef VectorMap<_Graph, _Item,  double> Map;
   126   };
   127 
   128 
   129   // long double
   130   template <typename _Graph, typename _Item>
   131   struct DefaultMapSelector<_Graph, _Item, long double> {
   132     typedef VectorMap<_Graph, _Item, long double> Map;
   133   };
   134 
   135 
   136   // pointer
   137   template <typename _Graph, typename _Item, typename _Ptr>
   138   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
   139     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   140   };
   141 
   142 // #else
   143 
   144 //   template <typename _Graph, typename _Item, typename _Value>
   145 //   struct DefaultMapSelector {
   146 //     typedef DebugMap<_Graph, _Item, _Value> Map;
   147 //   };
   148 
   149 // #endif
   150 
   151   // DefaultMap class
   152   template <typename _Graph, typename _Item, typename _Value>
   153   class DefaultMap
   154     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
   155   public:
   156     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
   157     typedef DefaultMap<_Graph, _Item, _Value> Map;
   158 
   159     typedef typename Parent::Graph Graph;
   160     typedef typename Parent::Value Value;
   161 
   162     explicit DefaultMap(const Graph& graph) : Parent(graph) {}
   163     DefaultMap(const Graph& graph, const Value& value)
   164       : Parent(graph, value) {}
   165 
   166     DefaultMap& operator=(const DefaultMap& cmap) {
   167       return operator=<DefaultMap>(cmap);
   168     }
   169 
   170     template <typename CMap>
   171     DefaultMap& operator=(const CMap& cmap) {
   172       Parent::operator=(cmap);
   173       return *this;
   174     }
   175 
   176   };
   177 
   178 }
   179 
   180 #endif