COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/maps.h @ 539:fb261e3a9a0f

Last change on this file since 539:fb261e3a9a0f was 539:fb261e3a9a0f, checked in by Akos Ladanyi, 19 years ago

Rename 'include' to 'hugo' (for automake)

File size: 4.0 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>
[284]15    class ReadableMap
[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
[282]26      /// Copy contsructor. (optional)
27      ReadableMap(const ReadableMap&) {}
28      /// Assignment operator. (optional)
29      ReadableMap& operator=(const ReadableMap&) {return *this;}
[186]30
[282]31      ReadableMap() {}
32    };
33
34
35    /// Writable map concept
36    template<typename K, typename T>
[284]37    class WritableMap
[282]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      WritableMap() {}
49    };
50
51    ///Read/Writeable map concept
52    template<typename K, typename T>
53    class ReadWritableMap : public ReadableMap<K,T>,
54                            public WritableMap<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      /// Copy contsructor. (optional)
68      ReadWritableMap(const ReadWritableMap&) {}
69      /// Assignment operator. (optional)
70      ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
71
72      /// Facility to define a map with an other value type (optional)
73      template<typename T1>
74      struct rebind {
75        /// The type of a map with the given value type
76        typedef ReadWritableMap<K,T1> other;
77      };
78      /// @brief Constructor that copies all keys from the other map and
79      /// assigns to them a default value (optional)
80      template<typename T1>
[286]81      ReadWritableMap(const ReadWritableMap<K,T1> &map, const ValueType &v) {}
[282]82
83      ReadWritableMap() {}
84    };
[186]85 
86 
[282]87    ///Dereferable map concept
88    template<typename K, typename T>
89    class DereferableMap : public ReadWritableMap<K,T>
90    {
91    public:
92      /// Map's key type.
93      typedef K KeyType;   
94      /// Map's value type. (The type of objects associated with the keys).
95      typedef T ValueType;
96      /// Map's reference type. (Reference to an object associated with a key)
97      typedef ValueType& ReferenceType;
98      /// Map's const reference type.
99      typedef const ValueType& ConstReferenceType;
[186]100
[282]101      ///Returns a reference to the value associated to a key.
102      ReferenceType operator[](const KeyType &i);
103      ///Returns a const reference to the value associated to a key.
104      ConstReferenceType operator[](const KeyType &i) const;
105      /// Sets the value associated with a key.
106      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
[186]107
[282]108      /// Copy contsructor. (optional)
109      DereferableMap(const DereferableMap&) {}
110      /// Assignment operator. (optional)
111      DereferableMap& operator=(const DereferableMap&) {return *this;}
[186]112
[282]113      /// Facility to define a map with an other value type (optional)
114      template<typename T1>
115      struct rebind {
116        /// The type of a map with the given value type
117        typedef DereferableMap<K,T1> other;
118      };
119      /// @brief Constructor that copies all keys from the other map and
120      /// assigns to them a default value (optional)
121      template<typename T1>
[286]122      DereferableMap(const DereferableMap<K,T1> &map, const ValueType &v) {}
[186]123
[282]124      DereferableMap() {}
125    };
[186]126
[282]127
128  }
[186]129}
130#endif // HUGO_MAPSKELETON_H
Note: See TracBrowser for help on using the repository browser.