# HG changeset patch # User deba # Date 1131131992 0 # Node ID 4ba7965386fb6720edd46300e4783a115af666fd # Parent a70cee06ae9ca01ceac27ee4be8237de4a49f5e8 Some just writeable bool maps. diff -r a70cee06ae9c -r 4ba7965386fb lemon/maps.h --- a/lemon/maps.h Fri Nov 04 19:07:15 2005 +0000 +++ b/lemon/maps.h Fri Nov 04 19:19:52 2005 +0000 @@ -17,6 +17,8 @@ #ifndef LEMON_MAPS_H #define LEMON_MAPS_H +#include + #include #include @@ -842,7 +844,7 @@ typedef typename Parent::Key Key; typedef typename Parent::Value Value; - ///Constructor + /// Constructor NotMap(const M &_m) : m(_m) {}; Value operator[](Key k) const {return !m[k];} }; @@ -856,6 +858,196 @@ return NotMap(m); } + /// \brief Writeable bool map for store each true assigned elements. + /// + /// Writeable bool map for store each true assigned elements. It will + /// copies all the true setted keys to the given iterator. + /// + /// \note The container of the iterator should contain for each element. + template + class StoreBoolMap { + public: + typedef _Iterator Iterator; + + typedef typename std::iterator_traits::value_type Key; + typedef bool Value; + + /// Constructor + StoreBoolMap(Iterator it) : _begin(it), _end(it) {} + + /// Gives back the given first setted iterator. + Iterator begin() const { + return _begin; + } + + /// Gives back the iterator after the last setted. + Iterator end() const { + return _end; + } + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + *_end++ = key; + } + } + + private: + Iterator _begin, _end; + }; + + /// \brief Writeable bool map for store each true assigned elements in + /// a back insertable container. + /// + /// Writeable bool map for store each true assigned elements in a back + /// insertable container. It will push back all the true setted keys into + /// the container. + template + class BackInserterBoolMap { + public: + typedef typename Container::value_type Key; + typedef bool Value; + + /// Constructor + BackInserterBoolMap(Container& _container) : container(_container) {} + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + container.push_back(key); + } + } + + private: + Container& container; + }; + + /// \brief Writeable bool map for store each true assigned elements in + /// a front insertable container. + /// + /// Writeable bool map for store each true assigned elements in a front + /// insertable container. It will push front all the true setted keys into + /// the container. + template + class FrontInserterBoolMap { + public: + typedef typename Container::value_type Key; + typedef bool Value; + + /// Constructor + FrontInserterBoolMap(Container& _container) : container(_container) {} + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + container.push_front(key); + } + } + + private: + Container& container; + }; + + /// \brief Writeable bool map for store each true assigned elements in + /// an insertable container. + /// + /// Writeable bool map for store each true assigned elements in an + /// insertable container. It will insert all the true setted keys into + /// the container. + template + class InserterBoolMap { + public: + typedef typename Container::value_type Key; + typedef bool Value; + + /// Constructor + InserterBoolMap(Container& _container) : container(_container) {} + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + container.insert(key); + } + } + + private: + Container& container; + }; + + /// \brief Fill the true setted elements with a given value. + /// + /// Writeable bool map for fill the true setted elements with a given value. + /// The value can be setted + /// the container. + template + class FillBoolMap { + public: + typedef typename Map::Key Key; + typedef bool Value; + + /// Constructor + FillBoolMap(Map& _map, const typename Map::Value& _fill) + : map(_map), fill(_fill) {} + + /// Constructor + FillBoolMap(Map& _map) + : map(_map), fill() {} + + /// Gives back the current fill value + typename Map::Value fillValue() const { + return fill; + } + + /// Sets the current fill value + void fillValue(const typename Map::Value& _fill) { + fill = _fill; + } + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + map.set(key, fill); + } + } + + private: + Map& map; + typename Map::Value fill; + }; + + + /// \brief Writeable bool map which stores for each true assigned elements + /// the setting order number. + /// + /// Writeable bool map which stores for each true assigned elements + /// the setting order number. + template + class SettingOrderBoolMap { + public: + typedef typename Map::Key Key; + typedef bool Value; + + /// Constructor + SettingOrderBoolMap(Map& _map) + : map(_map), counter(0) {} + + /// Number of setted keys. + int num() const { + return counter; + } + + /// Setter function of the map + void set(const Key& key, Value value) { + if (value) { + map.set(key, counter++); + } + } + + private: + Map& map; + int counter; + }; + /// @} }