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
RevLine 
[186]1// -*- c++ -*-
2#ifndef HUGO_MAPSKELETON_H
3#define HUGO_MAPSKELETON_H
4
[794]5///\ingroup skeletons
[242]6///\file
7///\brief Map concepts checking classes for testing and documenting.
8
[186]9namespace hugo {
[282]10
11  namespace skeleton {
[186]12 
[794]13    /// \addtogroup skeletons
14    /// @{
15
[282]16    /// Readable map concept
17    template<typename K, typename T>
[732]18    class ReadMap
[282]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;
[186]25
[282]26      /// Returns the value associated with a key.
27      ValueType operator[](const KeyType &k) const {return ValueType();}
[186]28
[732]29      ///Default constructor
30      ReadMap() {}
[282]31    };
32
33
34    /// Writable map concept
35    template<typename K, typename T>
[732]36    class WriteMap
[282]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
[732]47      ///Default constructor
48      WriteMap() {}
[282]49    };
50
[809]51    ///Read/Writable map concept
[282]52    template<typename K, typename T>
[732]53    class ReadWriteMap : public ReadMap<K,T>,
54                            public WriteMap<K,T>
[282]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
[732]67      ///Default constructor
68      ReadWriteMap() {}
[282]69    };
[186]70 
71 
[282]72    ///Dereferable map concept
73    template<typename K, typename T>
[732]74    class ReferenceMap : public ReadWriteMap<K,T>
[282]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;
[732]81
82    protected:
83      ValueType tmp;
84    public:
[282]85      typedef ValueType& ReferenceType;
86      /// Map's const reference type.
87      typedef const ValueType& ConstReferenceType;
[186]88
[282]89      ///Returns a reference to the value associated to a key.
[732]90      ReferenceType operator[](const KeyType &i) { return tmp; }
[282]91      ///Returns a const reference to the value associated to a key.
[732]92      ConstReferenceType operator[](const KeyType &i) const
93      { return tmp; }
[282]94      /// Sets the value associated with a key.
95      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
[186]96
[732]97      ///Default constructor
98      ReferenceMap() {}
[282]99    };
[794]100
101    // @}
102
[732]103  } //namespace skeleton
104} //namespace hugo
[186]105#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.