alpar@25: /* -*- C++ -*- alpar@25: * alpar@25: * This file is a part of LEMON, a generic C++ optimization library alpar@25: * alpar@39: * Copyright (C) 2003-2008 alpar@25: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@25: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@25: * alpar@25: * Permission to use, modify and distribute this software is granted alpar@25: * provided that this copyright notice appears in all copies. For alpar@25: * precise terms see the accompanying LICENSE file. alpar@25: * alpar@25: * This software is provided "AS IS" with no warranty of any kind, alpar@25: * express or implied, and with no claim as to its suitability for any alpar@25: * purpose. alpar@25: * alpar@25: */ alpar@25: alpar@25: #ifndef LEMON_CONCEPT_MAPS_H alpar@25: #define LEMON_CONCEPT_MAPS_H alpar@25: alpar@25: #include alpar@25: #include alpar@25: alpar@25: ///\ingroup concept alpar@25: ///\file alpar@25: ///\brief Map concepts checking classes for testing and documenting. alpar@25: alpar@25: namespace lemon { alpar@25: alpar@25: namespace concepts { kpeter@79: alpar@25: /// \addtogroup concept alpar@25: /// @{ alpar@25: alpar@25: /// Readable map concept kpeter@28: kpeter@28: /// Readable map concept. kpeter@28: /// alpar@25: template alpar@25: class ReadMap alpar@25: { alpar@25: public: kpeter@35: /// The key type of the map. kpeter@79: typedef K Key; kpeter@35: /// The value type of the map. (The type of objects associated with the keys). alpar@25: typedef T Value; alpar@25: kpeter@79: /// Returns the value associated with the given key. kpeter@94: Value operator[](const Key &) const { kpeter@94: return *static_cast(0); kpeter@94: } alpar@25: alpar@25: template alpar@25: struct Constraints { alpar@25: void constraints() { alpar@25: Value val = m[key]; alpar@25: val = m[key]; kpeter@79: typename _ReadMap::Value own_val = m[own_key]; kpeter@79: own_val = m[own_key]; alpar@25: kpeter@79: ignore_unused_variable_warning(key); alpar@25: ignore_unused_variable_warning(val); kpeter@79: ignore_unused_variable_warning(own_key); alpar@25: ignore_unused_variable_warning(own_val); alpar@25: } kpeter@79: const Key& key; kpeter@79: const typename _ReadMap::Key& own_key; kpeter@79: const _ReadMap& m; alpar@25: }; kpeter@79: alpar@25: }; alpar@25: alpar@25: alpar@25: /// Writable map concept kpeter@79: kpeter@28: /// Writable map concept. kpeter@28: /// alpar@25: template alpar@25: class WriteMap alpar@25: { alpar@25: public: kpeter@35: /// The key type of the map. kpeter@79: typedef K Key; kpeter@35: /// The value type of the map. (The type of objects associated with the keys). alpar@25: typedef T Value; alpar@25: kpeter@79: /// Sets the value associated with the given key. kpeter@79: void set(const Key &, const Value &) {} alpar@25: kpeter@79: /// Default constructor. alpar@25: WriteMap() {} alpar@25: alpar@25: template alpar@25: struct Constraints { alpar@25: void constraints() { alpar@25: m.set(key, val); alpar@25: m.set(own_key, own_val); kpeter@79: alpar@25: ignore_unused_variable_warning(key); alpar@25: ignore_unused_variable_warning(val); alpar@25: ignore_unused_variable_warning(own_key); alpar@25: ignore_unused_variable_warning(own_val); alpar@25: } kpeter@79: const Key& key; kpeter@79: const Value& val; kpeter@79: const typename _WriteMap::Key& own_key; kpeter@79: const typename _WriteMap::Value own_val; alpar@25: _WriteMap& m; alpar@25: }; alpar@25: }; alpar@25: kpeter@48: /// Read/writable map concept kpeter@79: kpeter@28: /// Read/writable map concept. kpeter@28: /// alpar@25: template alpar@25: class ReadWriteMap : public ReadMap, kpeter@35: public WriteMap alpar@25: { alpar@25: public: kpeter@35: /// The key type of the map. kpeter@79: typedef K Key; kpeter@35: /// The value type of the map. (The type of objects associated with the keys). alpar@25: typedef T Value; alpar@25: kpeter@79: /// Returns the value associated with the given key. kpeter@94: Value operator[](const Key &) const { kpeter@94: return *static_cast(0); kpeter@94: } kpeter@79: kpeter@79: /// Sets the value associated with the given key. kpeter@79: void set(const Key &, const Value &) {} alpar@25: alpar@25: template alpar@25: struct Constraints { alpar@25: void constraints() { alpar@25: checkConcept, _ReadWriteMap >(); alpar@25: checkConcept, _ReadWriteMap >(); alpar@25: } alpar@25: }; alpar@25: }; kpeter@79: kpeter@79: kpeter@28: /// Dereferable map concept kpeter@79: kpeter@28: /// Dereferable map concept. kpeter@28: /// alpar@25: template alpar@25: class ReferenceMap : public ReadWriteMap alpar@25: { alpar@25: public: alpar@25: /// Tag for reference maps. alpar@25: typedef True ReferenceMapTag; kpeter@35: /// The key type of the map. kpeter@79: typedef K Key; kpeter@35: /// The value type of the map. (The type of objects associated with the keys). alpar@25: typedef T Value; kpeter@35: /// The reference type of the map. alpar@25: typedef R Reference; kpeter@35: /// The const reference type of the map. alpar@25: typedef CR ConstReference; alpar@25: alpar@25: public: alpar@25: kpeter@79: /// Returns a reference to the value associated with the given key. kpeter@94: Reference operator[](const Key &) { kpeter@94: return *static_cast(0); kpeter@94: } kpeter@79: kpeter@79: /// Returns a const reference to the value associated with the given key. kpeter@94: ConstReference operator[](const Key &) const { kpeter@94: return *static_cast(0); kpeter@94: } kpeter@79: kpeter@79: /// Sets the value associated with the given key. alpar@25: void set(const Key &k,const Value &t) { operator[](k)=t; } alpar@25: alpar@25: template kpeter@74: struct Constraints { alpar@25: void constraints() { kpeter@74: checkConcept, _ReferenceMap >(); kpeter@79: ref = m[key]; alpar@25: m[key] = val; alpar@25: m[key] = ref; kpeter@79: m[key] = cref; kpeter@79: own_ref = m[own_key]; alpar@25: m[own_key] = own_val; alpar@25: m[own_key] = own_ref; kpeter@79: m[own_key] = own_cref; kpeter@79: m[key] = m[own_key]; kpeter@79: m[own_key] = m[key]; alpar@25: } kpeter@79: const Key& key; kpeter@79: Value& val; kpeter@79: Reference ref; kpeter@79: ConstReference cref; kpeter@79: const typename _ReferenceMap::Key& own_key; alpar@25: typename _ReferenceMap::Value& own_val; kpeter@74: typename _ReferenceMap::Reference own_ref; kpeter@79: typename _ReferenceMap::ConstReference own_cref; alpar@25: _ReferenceMap& m; alpar@25: }; alpar@25: }; alpar@25: alpar@25: // @} alpar@25: alpar@25: } //namespace concepts kpeter@28: alpar@25: } //namespace lemon kpeter@28: alpar@25: #endif // LEMON_CONCEPT_MAPS_H