[906] | 1 | /* -*- C++ -*- |
---|
| 2 | * src/hugo/skeletons/maps.h - Part of HUGOlib, 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 | |
---|
[186] | 17 | #ifndef HUGO_MAPSKELETON_H |
---|
| 18 | #define HUGO_MAPSKELETON_H |
---|
| 19 | |
---|
[794] | 20 | ///\ingroup skeletons |
---|
[242] | 21 | ///\file |
---|
| 22 | ///\brief Map concepts checking classes for testing and documenting. |
---|
| 23 | |
---|
[186] | 24 | namespace hugo { |
---|
[282] | 25 | |
---|
| 26 | namespace skeleton { |
---|
[186] | 27 | |
---|
[794] | 28 | /// \addtogroup skeletons |
---|
| 29 | /// @{ |
---|
| 30 | |
---|
[282] | 31 | /// Readable map concept |
---|
| 32 | template<typename K, typename T> |
---|
[732] | 33 | class ReadMap |
---|
[282] | 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; |
---|
[186] | 40 | |
---|
[282] | 41 | /// Returns the value associated with a key. |
---|
| 42 | ValueType operator[](const KeyType &k) const {return ValueType();} |
---|
[186] | 43 | |
---|
[732] | 44 | ///Default constructor |
---|
| 45 | ReadMap() {} |
---|
[282] | 46 | }; |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /// Writable map concept |
---|
| 50 | template<typename K, typename T> |
---|
[732] | 51 | class WriteMap |
---|
[282] | 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 | |
---|
[732] | 62 | ///Default constructor |
---|
| 63 | WriteMap() {} |
---|
[282] | 64 | }; |
---|
| 65 | |
---|
[809] | 66 | ///Read/Writable map concept |
---|
[282] | 67 | template<typename K, typename T> |
---|
[732] | 68 | class ReadWriteMap : public ReadMap<K,T>, |
---|
| 69 | public WriteMap<K,T> |
---|
[282] | 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 | |
---|
[732] | 82 | ///Default constructor |
---|
| 83 | ReadWriteMap() {} |
---|
[282] | 84 | }; |
---|
[186] | 85 | |
---|
| 86 | |
---|
[282] | 87 | ///Dereferable map concept |
---|
| 88 | template<typename K, typename T> |
---|
[732] | 89 | class ReferenceMap : public ReadWriteMap<K,T> |
---|
[282] | 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; |
---|
[732] | 96 | |
---|
| 97 | protected: |
---|
| 98 | ValueType tmp; |
---|
| 99 | public: |
---|
[282] | 100 | typedef ValueType& ReferenceType; |
---|
| 101 | /// Map's const reference type. |
---|
| 102 | typedef const ValueType& ConstReferenceType; |
---|
[186] | 103 | |
---|
[282] | 104 | ///Returns a reference to the value associated to a key. |
---|
[732] | 105 | ReferenceType operator[](const KeyType &i) { return tmp; } |
---|
[282] | 106 | ///Returns a const reference to the value associated to a key. |
---|
[732] | 107 | ConstReferenceType operator[](const KeyType &i) const |
---|
| 108 | { return tmp; } |
---|
[282] | 109 | /// Sets the value associated with a key. |
---|
| 110 | void set(const KeyType &k,const ValueType &t) { operator[](k)=t; } |
---|
[186] | 111 | |
---|
[732] | 112 | ///Default constructor |
---|
| 113 | ReferenceMap() {} |
---|
[282] | 114 | }; |
---|
[794] | 115 | |
---|
| 116 | // @} |
---|
| 117 | |
---|
[732] | 118 | } //namespace skeleton |
---|
| 119 | } //namespace hugo |
---|
[186] | 120 | #endif // HUGO_MAPSKELETON_H |
---|