COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/maps.h @ 739:3bb5553ec41b

Last change on this file since 739:3bb5553ec41b was 732:33cbc0635e92, checked in by Alpar Juttner, 20 years ago

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

File size: 2.7 KB
RevLine 
[186]1// -*- c++ -*-
2#ifndef HUGO_MAPSKELETON_H
3#define HUGO_MAPSKELETON_H
4
[242]5///\file
6///\brief Map concepts checking classes for testing and documenting.
7
[186]8namespace hugo {
[282]9
10  /// The namespace of HUGOlib concepts and concept checking classes
11  namespace skeleton {
[186]12 
[282]13    /// Readable map concept
14    template<typename K, typename T>
[732]15    class ReadMap
[282]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;
[186]22
[282]23      /// Returns the value associated with a key.
24      ValueType operator[](const KeyType &k) const {return ValueType();}
[186]25
[732]26      ///Default constructor
27      ReadMap() {}
[282]28    };
29
30
31    /// Writable map concept
32    template<typename K, typename T>
[732]33    class WriteMap
[282]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
[732]44      ///Default constructor
45      WriteMap() {}
[282]46    };
47
48    ///Read/Writeable map concept
49    template<typename K, typename T>
[732]50    class ReadWriteMap : public ReadMap<K,T>,
51                            public WriteMap<K,T>
[282]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
[732]64      ///Default constructor
65      ReadWriteMap() {}
[282]66    };
[186]67 
68 
[282]69    ///Dereferable map concept
70    template<typename K, typename T>
[732]71    class ReferenceMap : public ReadWriteMap<K,T>
[282]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;
[732]78
79    protected:
80      ValueType tmp;
81    public:
[282]82      typedef ValueType& ReferenceType;
83      /// Map's const reference type.
84      typedef const ValueType& ConstReferenceType;
[186]85
[282]86      ///Returns a reference to the value associated to a key.
[732]87      ReferenceType operator[](const KeyType &i) { return tmp; }
[282]88      ///Returns a const reference to the value associated to a key.
[732]89      ConstReferenceType operator[](const KeyType &i) const
90      { return tmp; }
[282]91      /// Sets the value associated with a key.
92      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
[186]93
[732]94      ///Default constructor
95      ReferenceMap() {}
[282]96    };
[732]97  } //namespace skeleton
98} //namespace hugo
[186]99#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.