COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/maps.h @ 880:9d0bfd35b97c

Last change on this file since 880:9d0bfd35b97c was 809:ea5ae5266285, checked in by Alpar Juttner, 20 years ago

Spell checking.

File size: 2.8 KB
Line 
1// -*- c++ -*-
2#ifndef HUGO_MAPSKELETON_H
3#define HUGO_MAPSKELETON_H
4
5///\ingroup skeletons
6///\file
7///\brief Map concepts checking classes for testing and documenting.
8
9namespace hugo {
10
11  /// The namespace of HUGOlib concepts and concept checking classes
12  namespace skeleton {
13 
14    /// \addtogroup skeletons
15    /// @{
16
17    /// Readable map concept
18    template<typename K, typename T>
19    class ReadMap
20    {
21    public:
22      /// Map's key type.
23      typedef K KeyType;   
24      /// Map's value type. (The type of objects associated with the keys).
25      typedef T ValueType;
26
27      /// Returns the value associated with a key.
28      ValueType operator[](const KeyType &k) const {return ValueType();}
29
30      ///Default constructor
31      ReadMap() {}
32    };
33
34
35    /// Writable map concept
36    template<typename K, typename T>
37    class WriteMap
38    {
39    public:
40      /// Map's key type.
41      typedef K KeyType;   
42      /// Map's value type. (The type of objects associated with the keys).
43      typedef T ValueType;
44
45      /// Sets the value associated with a key.
46      void set(const KeyType &k,const ValueType &t) {}
47
48      ///Default constructor
49      WriteMap() {}
50    };
51
52    ///Read/Writable map concept
53    template<typename K, typename T>
54    class ReadWriteMap : public ReadMap<K,T>,
55                            public WriteMap<K,T>
56    {
57    public:
58      /// Map's key type.
59      typedef K KeyType;   
60      /// Map's value type. (The type of objects associated with the keys).
61      typedef T ValueType;
62
63      /// Returns the value associated with a key.
64      ValueType operator[](const KeyType &k) const {return ValueType();}
65      /// Sets the value associated with a key.
66      void set(const KeyType &k,const ValueType &t) {}
67
68      ///Default constructor
69      ReadWriteMap() {}
70    };
71 
72 
73    ///Dereferable map concept
74    template<typename K, typename T>
75    class ReferenceMap : public ReadWriteMap<K,T>
76    {
77    public:
78      /// Map's key type.
79      typedef K KeyType;   
80      /// Map's value type. (The type of objects associated with the keys).
81      typedef T ValueType;
82
83    protected:
84      ValueType tmp;
85    public:
86      typedef ValueType& ReferenceType;
87      /// Map's const reference type.
88      typedef const ValueType& ConstReferenceType;
89
90      ///Returns a reference to the value associated to a key.
91      ReferenceType operator[](const KeyType &i) { return tmp; }
92      ///Returns a const reference to the value associated to a key.
93      ConstReferenceType operator[](const KeyType &i) const
94      { return tmp; }
95      /// Sets the value associated with a key.
96      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
97
98      ///Default constructor
99      ReferenceMap() {}
100    };
101
102    // @}
103
104  } //namespace skeleton
105} //namespace hugo
106#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.