lemon/bits/default_map.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sat, 09 May 2009 16:39:59 +0200
changeset 657 bf7928412136
parent 617 4137ef9aacc6
parent 500 8a144437db7d
child 877 141f9c0db4a3
permissions -rw-r--r--
Change Graph::Edge -> Graph::Arc inheritance to conversion (#283)
     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-2009
     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/config.h>
    23 #include <lemon/bits/array_map.h>
    24 #include <lemon/bits/vector_map.h>
    25 //#include <lemon/bits/debug_map.h>
    26 
    27 //\ingroup graphbits
    28 //\file
    29 //\brief Graph maps that construct and destruct their elements dynamically.
    30 
    31 namespace lemon {
    32 
    33 
    34   //#ifndef LEMON_USE_DEBUG_MAP
    35 
    36   template <typename _Graph, typename _Item, typename _Value>
    37   struct DefaultMapSelector {
    38     typedef ArrayMap<_Graph, _Item, _Value> Map;
    39   };
    40 
    41   // bool
    42   template <typename _Graph, typename _Item>
    43   struct DefaultMapSelector<_Graph, _Item, bool> {
    44     typedef VectorMap<_Graph, _Item, bool> Map;
    45   };
    46 
    47   // char
    48   template <typename _Graph, typename _Item>
    49   struct DefaultMapSelector<_Graph, _Item, char> {
    50     typedef VectorMap<_Graph, _Item, char> Map;
    51   };
    52 
    53   template <typename _Graph, typename _Item>
    54   struct DefaultMapSelector<_Graph, _Item, signed char> {
    55     typedef VectorMap<_Graph, _Item, signed char> Map;
    56   };
    57 
    58   template <typename _Graph, typename _Item>
    59   struct DefaultMapSelector<_Graph, _Item, unsigned char> {
    60     typedef VectorMap<_Graph, _Item, unsigned char> Map;
    61   };
    62 
    63 
    64   // int
    65   template <typename _Graph, typename _Item>
    66   struct DefaultMapSelector<_Graph, _Item, signed int> {
    67     typedef VectorMap<_Graph, _Item, signed int> Map;
    68   };
    69 
    70   template <typename _Graph, typename _Item>
    71   struct DefaultMapSelector<_Graph, _Item, unsigned int> {
    72     typedef VectorMap<_Graph, _Item, unsigned int> Map;
    73   };
    74 
    75 
    76   // short
    77   template <typename _Graph, typename _Item>
    78   struct DefaultMapSelector<_Graph, _Item, signed short> {
    79     typedef VectorMap<_Graph, _Item, signed short> Map;
    80   };
    81 
    82   template <typename _Graph, typename _Item>
    83   struct DefaultMapSelector<_Graph, _Item, unsigned short> {
    84     typedef VectorMap<_Graph, _Item, unsigned short> Map;
    85   };
    86 
    87 
    88   // long
    89   template <typename _Graph, typename _Item>
    90   struct DefaultMapSelector<_Graph, _Item, signed long> {
    91     typedef VectorMap<_Graph, _Item, signed long> Map;
    92   };
    93 
    94   template <typename _Graph, typename _Item>
    95   struct DefaultMapSelector<_Graph, _Item, unsigned long> {
    96     typedef VectorMap<_Graph, _Item, unsigned long> Map;
    97   };
    98 
    99 
   100 #if defined LEMON_HAVE_LONG_LONG
   101 
   102   // long long
   103   template <typename _Graph, typename _Item>
   104   struct DefaultMapSelector<_Graph, _Item, signed long long> {
   105     typedef VectorMap<_Graph, _Item, signed long long> Map;
   106   };
   107 
   108   template <typename _Graph, typename _Item>
   109   struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
   110     typedef VectorMap<_Graph, _Item, unsigned long long> Map;
   111   };
   112 
   113 #endif
   114 
   115 
   116   // float
   117   template <typename _Graph, typename _Item>
   118   struct DefaultMapSelector<_Graph, _Item, float> {
   119     typedef VectorMap<_Graph, _Item, float> Map;
   120   };
   121 
   122 
   123   // double
   124   template <typename _Graph, typename _Item>
   125   struct DefaultMapSelector<_Graph, _Item, double> {
   126     typedef VectorMap<_Graph, _Item,  double> Map;
   127   };
   128 
   129 
   130   // long double
   131   template <typename _Graph, typename _Item>
   132   struct DefaultMapSelector<_Graph, _Item, long double> {
   133     typedef VectorMap<_Graph, _Item, long double> Map;
   134   };
   135 
   136 
   137   // pointer
   138   template <typename _Graph, typename _Item, typename _Ptr>
   139   struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
   140     typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   141   };
   142 
   143 // #else
   144 
   145 //   template <typename _Graph, typename _Item, typename _Value>
   146 //   struct DefaultMapSelector {
   147 //     typedef DebugMap<_Graph, _Item, _Value> Map;
   148 //   };
   149 
   150 // #endif
   151 
   152   // DefaultMap class
   153   template <typename _Graph, typename _Item, typename _Value>
   154   class DefaultMap
   155     : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
   156     typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
   157 
   158   public:
   159     typedef DefaultMap<_Graph, _Item, _Value> Map;
   160     
   161     typedef typename Parent::GraphType GraphType;
   162     typedef typename Parent::Value Value;
   163 
   164     explicit DefaultMap(const GraphType& graph) : Parent(graph) {}
   165     DefaultMap(const GraphType& graph, const Value& value)
   166       : Parent(graph, value) {}
   167 
   168     DefaultMap& operator=(const DefaultMap& cmap) {
   169       return operator=<DefaultMap>(cmap);
   170     }
   171 
   172     template <typename CMap>
   173     DefaultMap& operator=(const CMap& cmap) {
   174       Parent::operator=(cmap);
   175       return *this;
   176     }
   177 
   178   };
   179 
   180 }
   181 
   182 #endif