COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/include/skeletons/maps.h @ 283:91e78d9b78f4

Last change on this file since 283:91e78d9b78f4 was 282:7f85e99502db, checked in by Mihaly Barasz, 21 years ago

Bit more elaborated map concepts

File size: 5.6 KB
Line 
1// -*- c++ -*-
2#ifndef HUGO_MAPSKELETON_H
3#define HUGO_MAPSKELETON_H
4
5///\file
6///\brief Map concepts checking classes for testing and documenting.
7
8namespace hugo {
9
10  /// The namespace of HUGOlib concepts and concept checking classes
11  namespace skeleton {
12 
13    /// Null map concept
14    template<typename K, typename T>
15    class NullMap
16    {
17    public:
18      /// Map's key type.
19      typedef K KeyType;   
20      /// Map's value type. (The type of objects associated with the keys).
21      typedef T ValueType;
22
23      /// Facility to define a map with an other value type
24      template<typename T1>
25      struct rebind {
26        /// The type of a map with the given value type
27        typedef NullMap<K,T1> other;
28      };
29
30      NullMap() {}
31    };
32   
33    /// Readable map concept
34    template<typename K, typename T>
35    class ReadableMap : public NullMap<K,T>
36    {
37    public:
38      /// Map's key type.
39      typedef K KeyType;   
40      /// Map's value type. (The type of objects associated with the keys).
41      typedef T ValueType;
42
43      /// Returns the value associated with a key.
44      ValueType operator[](const KeyType &k) const {return ValueType();}
45
46      /// Copy contsructor. (optional)
47      ReadableMap(const ReadableMap&) {}
48      /// Assignment operator. (optional)
49      ReadableMap& operator=(const ReadableMap&) {return *this;}
50
51      /// Facility to define a map with an other value type (optional)
52      template<typename T1>
53      struct rebind {
54        /// The type of a map with the given value type
55        typedef ReadableMap<K,T1> other;
56      };
57      /// @brief Constructor that copies all keys from the other map and
58      /// assigns to them a default value (optional)
59      template<typename T1>
60      ReadableMap(const ReadableMap<K,T1> &map, const T1 &v) {}
61
62      ReadableMap() {}
63    };
64
65
66    /// Writable map concept
67    template<typename K, typename T>
68    class WritableMap : public NullMap<K,T>
69    {
70    public:
71      /// Map's key type.
72      typedef K KeyType;   
73      /// Map's value type. (The type of objects associated with the keys).
74      typedef T ValueType;
75
76      /// Sets the value associated with a key.
77      void set(const KeyType &k,const ValueType &t) {}
78
79      /// Copy contsructor. (optional)
80      WritableMap(const WritableMap&) {}
81      /// Assignment operator. (optional)
82      WritableMap& operator=(const WritableMap&) {return *this;}
83
84      /// Facility to define a map with an other value type (optional)
85      template<typename T1>
86      struct rebind {
87        /// The type of a map with the given value type
88        typedef WritableMap<K,T1> other;
89      };
90      /// @brief Constructor that copies all keys from the other map and
91      /// assigns to them a default value (optional)
92      template<typename T1>
93      WritableMap(const WritableMap<K,T1> &map, const T1 &v) {}
94
95      WritableMap() {}
96    };
97
98    ///Read/Writeable map concept
99    template<typename K, typename T>
100    class ReadWritableMap : public ReadableMap<K,T>,
101                            public WritableMap<K,T>
102    {
103    public:
104      /// Map's key type.
105      typedef K KeyType;   
106      /// Map's value type. (The type of objects associated with the keys).
107      typedef T ValueType;
108
109      /// Returns the value associated with a key.
110      ValueType operator[](const KeyType &k) const {return ValueType();}
111      /// Sets the value associated with a key.
112      void set(const KeyType &k,const ValueType &t) {}
113
114      /// Copy contsructor. (optional)
115      ReadWritableMap(const ReadWritableMap&) {}
116      /// Assignment operator. (optional)
117      ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
118
119      /// Facility to define a map with an other value type (optional)
120      template<typename T1>
121      struct rebind {
122        /// The type of a map with the given value type
123        typedef ReadWritableMap<K,T1> other;
124      };
125      /// @brief Constructor that copies all keys from the other map and
126      /// assigns to them a default value (optional)
127      template<typename T1>
128      ReadWritableMap(const ReadWritableMap<K,T1> &map, const T1 &v) {}
129
130      ReadWritableMap() {}
131    };
132 
133 
134    ///Dereferable map concept
135    template<typename K, typename T>
136    class DereferableMap : public ReadWritableMap<K,T>
137    {
138    public:
139      /// Map's key type.
140      typedef K KeyType;   
141      /// Map's value type. (The type of objects associated with the keys).
142      typedef T ValueType;
143      /// Map's reference type. (Reference to an object associated with a key)
144      typedef ValueType& ReferenceType;
145      /// Map's const reference type.
146      typedef const ValueType& ConstReferenceType;
147
148      ///Returns a reference to the value associated to a key.
149      ReferenceType operator[](const KeyType &i);
150      ///Returns a const reference to the value associated to a key.
151      ConstReferenceType operator[](const KeyType &i) const;
152      /// Sets the value associated with a key.
153      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
154
155      /// Copy contsructor. (optional)
156      DereferableMap(const DereferableMap&) {}
157      /// Assignment operator. (optional)
158      DereferableMap& operator=(const DereferableMap&) {return *this;}
159
160      /// Facility to define a map with an other value type (optional)
161      template<typename T1>
162      struct rebind {
163        /// The type of a map with the given value type
164        typedef DereferableMap<K,T1> other;
165      };
166      /// @brief Constructor that copies all keys from the other map and
167      /// assigns to them a default value (optional)
168      template<typename T1>
169      DereferableMap(const DereferableMap<K,T1> &map, const T1 &v) {}
170
171      DereferableMap() {}
172    };
173
174
175  }
176}
177#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.