1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/lemon/skeletons/maps.h Wed Sep 29 15:30:04 2004 +0000
1.3 @@ -0,0 +1,120 @@
1.4 +/* -*- C++ -*-
1.5 + * src/lemon/skeletons/maps.h - Part of LEMON, a generic C++ optimization library
1.6 + *
1.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
1.9 + *
1.10 + * Permission to use, modify and distribute this software is granted
1.11 + * provided that this copyright notice appears in all copies. For
1.12 + * precise terms see the accompanying LICENSE file.
1.13 + *
1.14 + * This software is provided "AS IS" with no warranty of any kind,
1.15 + * express or implied, and with no claim as to its suitability for any
1.16 + * purpose.
1.17 + *
1.18 + */
1.19 +
1.20 +#ifndef LEMON_MAPSKELETON_H
1.21 +#define LEMON_MAPSKELETON_H
1.22 +
1.23 +///\ingroup skeletons
1.24 +///\file
1.25 +///\brief Map concepts checking classes for testing and documenting.
1.26 +
1.27 +namespace lemon {
1.28 +
1.29 + namespace skeleton {
1.30 +
1.31 + /// \addtogroup skeletons
1.32 + /// @{
1.33 +
1.34 + /// Readable map concept
1.35 + template<typename K, typename T>
1.36 + class ReadMap
1.37 + {
1.38 + public:
1.39 + /// Map's key type.
1.40 + typedef K KeyType;
1.41 + /// Map's value type. (The type of objects associated with the keys).
1.42 + typedef T ValueType;
1.43 +
1.44 + /// Returns the value associated with a key.
1.45 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.46 +
1.47 + ///Default constructor
1.48 + ReadMap() {}
1.49 + };
1.50 +
1.51 +
1.52 + /// Writable map concept
1.53 + template<typename K, typename T>
1.54 + class WriteMap
1.55 + {
1.56 + public:
1.57 + /// Map's key type.
1.58 + typedef K KeyType;
1.59 + /// Map's value type. (The type of objects associated with the keys).
1.60 + typedef T ValueType;
1.61 +
1.62 + /// Sets the value associated with a key.
1.63 + void set(const KeyType &k,const ValueType &t) {}
1.64 +
1.65 + ///Default constructor
1.66 + WriteMap() {}
1.67 + };
1.68 +
1.69 + ///Read/Writable map concept
1.70 + template<typename K, typename T>
1.71 + class ReadWriteMap : public ReadMap<K,T>,
1.72 + public WriteMap<K,T>
1.73 + {
1.74 + public:
1.75 + /// Map's key type.
1.76 + typedef K KeyType;
1.77 + /// Map's value type. (The type of objects associated with the keys).
1.78 + typedef T ValueType;
1.79 +
1.80 + /// Returns the value associated with a key.
1.81 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.82 + /// Sets the value associated with a key.
1.83 + void set(const KeyType &k,const ValueType &t) {}
1.84 +
1.85 + ///Default constructor
1.86 + ReadWriteMap() {}
1.87 + };
1.88 +
1.89 +
1.90 + ///Dereferable map concept
1.91 + template<typename K, typename T>
1.92 + class ReferenceMap : public ReadWriteMap<K,T>
1.93 + {
1.94 + public:
1.95 + /// Map's key type.
1.96 + typedef K KeyType;
1.97 + /// Map's value type. (The type of objects associated with the keys).
1.98 + typedef T ValueType;
1.99 +
1.100 + protected:
1.101 + ValueType tmp;
1.102 + public:
1.103 + typedef ValueType& ReferenceType;
1.104 + /// Map's const reference type.
1.105 + typedef const ValueType& ConstReferenceType;
1.106 +
1.107 + ///Returns a reference to the value associated to a key.
1.108 + ReferenceType operator[](const KeyType &i) { return tmp; }
1.109 + ///Returns a const reference to the value associated to a key.
1.110 + ConstReferenceType operator[](const KeyType &i) const
1.111 + { return tmp; }
1.112 + /// Sets the value associated with a key.
1.113 + void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
1.114 +
1.115 + ///Default constructor
1.116 + ReferenceMap() {}
1.117 + };
1.118 +
1.119 + // @}
1.120 +
1.121 + } //namespace skeleton
1.122 +} //namespace lemon
1.123 +#endif // LEMON_MAPSKELETON_H