COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/maps.h @ 732:33cbc0635e92

Last change on this file since 732:33cbc0635e92 was 732:33cbc0635e92, checked in by Alpar Juttner, 16 years ago

Skeletons have been simplified.
"Optional features" have been deleted.
Map skeletons have been renamed.

File size: 2.7 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    /// Readable map concept
14    template<typename K, typename T>
15    class ReadMap
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      /// Returns the value associated with a key.
24      ValueType operator[](const KeyType &k) const {return ValueType();}
25
26      ///Default constructor
27      ReadMap() {}
28    };
29
30
31    /// Writable map concept
32    template<typename K, typename T>
33    class WriteMap
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      /// Sets the value associated with a key.
42      void set(const KeyType &k,const ValueType &t) {}
43
44      ///Default constructor
45      WriteMap() {}
46    };
47
48    ///Read/Writeable map concept
49    template<typename K, typename T>
50    class ReadWriteMap : public ReadMap<K,T>,
51                            public WriteMap<K,T>
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      /// Returns the value associated with a key.
60      ValueType operator[](const KeyType &k) const {return ValueType();}
61      /// Sets the value associated with a key.
62      void set(const KeyType &k,const ValueType &t) {}
63
64      ///Default constructor
65      ReadWriteMap() {}
66    };
67 
68 
69    ///Dereferable map concept
70    template<typename K, typename T>
71    class ReferenceMap : public ReadWriteMap<K,T>
72    {
73    public:
74      /// Map's key type.
75      typedef K KeyType;   
76      /// Map's value type. (The type of objects associated with the keys).
77      typedef T ValueType;
78
79    protected:
80      ValueType tmp;
81    public:
82      typedef ValueType& ReferenceType;
83      /// Map's const reference type.
84      typedef const ValueType& ConstReferenceType;
85
86      ///Returns a reference to the value associated to a key.
87      ReferenceType operator[](const KeyType &i) { return tmp; }
88      ///Returns a const reference to the value associated to a key.
89      ConstReferenceType operator[](const KeyType &i) const
90      { return tmp; }
91      /// Sets the value associated with a key.
92      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
93
94      ///Default constructor
95      ReferenceMap() {}
96    };
97  } //namespace skeleton
98} //namespace hugo
99#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.