COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/maps.h @ 881:a9f19f38970b

Last change on this file since 881:a9f19f38970b was 881:a9f19f38970b, checked in by Alpar Juttner, 20 years ago

Right (but still too short) documentation of the namespaces.

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