src/lemon/skeletons/maps.h
author marci
Fri, 01 Oct 2004 11:31:03 +0000
changeset 933 1b7c88fbb950
parent 906 17f31d280385
child 946 c94ef40a22ce
permissions -rw-r--r--
NodeSubGraphWrapper, test, and ducumentation modifications.
     1 /* -*- C++ -*-
     2  * src/lemon/skeletons/maps.h - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Combinatorial Optimization Research Group, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 #ifndef LEMON_MAPSKELETON_H
    18 #define LEMON_MAPSKELETON_H
    19 
    20 ///\ingroup skeletons
    21 ///\file
    22 ///\brief Map concepts checking classes for testing and documenting.
    23 
    24 namespace lemon {
    25 
    26   namespace skeleton {
    27   
    28     /// \addtogroup skeletons
    29     /// @{
    30 
    31     /// Readable map concept
    32     template<typename K, typename T>
    33     class ReadMap
    34     {
    35     public:
    36       /// Map's key type.
    37       typedef K KeyType;    
    38       /// Map's value type. (The type of objects associated with the keys).
    39       typedef T ValueType;
    40 
    41       /// Returns the value associated with a key.
    42       ValueType operator[](const KeyType &k) const {return ValueType();}
    43 
    44       ///Default constructor
    45       ReadMap() {}
    46     };
    47 
    48 
    49     /// Writable map concept
    50     template<typename K, typename T>
    51     class WriteMap
    52     {
    53     public:
    54       /// Map's key type.
    55       typedef K KeyType;    
    56       /// Map's value type. (The type of objects associated with the keys).
    57       typedef T ValueType;
    58 
    59       /// Sets the value associated with a key.
    60       void set(const KeyType &k,const ValueType &t) {}
    61 
    62       ///Default constructor
    63       WriteMap() {}
    64     };
    65 
    66     ///Read/Writable map concept
    67     template<typename K, typename T>
    68     class ReadWriteMap : public ReadMap<K,T>,
    69 			    public WriteMap<K,T>
    70     {
    71     public:
    72       /// Map's key type.
    73       typedef K KeyType;    
    74       /// Map's value type. (The type of objects associated with the keys).
    75       typedef T ValueType;
    76 
    77       /// Returns the value associated with a key.
    78       ValueType operator[](const KeyType &k) const {return ValueType();}
    79       /// Sets the value associated with a key.
    80       void set(const KeyType &k,const ValueType &t) {}
    81 
    82       ///Default constructor
    83       ReadWriteMap() {}
    84     };
    85   
    86   
    87     ///Dereferable map concept
    88     template<typename K, typename T>
    89     class ReferenceMap : public ReadWriteMap<K,T>
    90     {
    91     public:
    92       /// Map's key type.
    93       typedef K KeyType;    
    94       /// Map's value type. (The type of objects associated with the keys).
    95       typedef T ValueType;
    96 
    97     protected:
    98       ValueType tmp;
    99     public:
   100       typedef ValueType& ReferenceType;
   101       /// Map's const reference type.
   102       typedef const ValueType& ConstReferenceType;
   103 
   104       ///Returns a reference to the value associated to a key.
   105       ReferenceType operator[](const KeyType &i) { return tmp; }
   106       ///Returns a const reference to the value associated to a key.
   107       ConstReferenceType operator[](const KeyType &i) const
   108       { return tmp; }
   109       /// Sets the value associated with a key.
   110       void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
   111 
   112       ///Default constructor
   113       ReferenceMap() {}
   114     };
   115 
   116     // @}
   117 
   118   } //namespace skeleton
   119 } //namespace lemon
   120 #endif // LEMON_MAPSKELETON_H