gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Rename ValueIterator to ValueIt in graph maps (#302) but keep ValueIterator as an alias in CrossRefMap (only for reverse compatibility).
0 2 0
default
2 files changed with 42 insertions and 36 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
... ...
@@ -1814,298 +1814,301 @@
1814 1814
  /// \addtogroup graph_maps
1815 1815
  /// @{
1816 1816

	
1817 1817
  /// \brief Provides an immutable and unique id for each item in a graph.
1818 1818
  ///
1819 1819
  /// IdMap provides a unique and immutable id for each item of the
1820 1820
  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
1821 1821
  ///  - \b unique: different items get different ids,
1822 1822
  ///  - \b immutable: the id of an item does not change (even if you
1823 1823
  ///    delete other nodes).
1824 1824
  ///
1825 1825
  /// Using this map you get access (i.e. can read) the inner id values of
1826 1826
  /// the items stored in the graph, which is returned by the \c id()
1827 1827
  /// function of the graph. This map can be inverted with its member
1828 1828
  /// class \c InverseMap or with the \c operator()() member.
1829 1829
  ///
1830 1830
  /// \tparam GR The graph type.
1831 1831
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1832 1832
  /// \c GR::Edge).
1833 1833
  ///
1834 1834
  /// \see RangeIdMap
1835 1835
  template <typename GR, typename K>
1836 1836
  class IdMap : public MapBase<K, int> {
1837 1837
  public:
1838 1838
    /// The graph type of IdMap.
1839 1839
    typedef GR Graph;
1840 1840
    typedef GR Digraph;
1841 1841
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1842 1842
    typedef K Item;
1843 1843
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1844 1844
    typedef K Key;
1845 1845
    /// The value type of IdMap.
1846 1846
    typedef int Value;
1847 1847

	
1848 1848
    /// \brief Constructor.
1849 1849
    ///
1850 1850
    /// Constructor of the map.
1851 1851
    explicit IdMap(const Graph& graph) : _graph(&graph) {}
1852 1852

	
1853 1853
    /// \brief Gives back the \e id of the item.
1854 1854
    ///
1855 1855
    /// Gives back the immutable and unique \e id of the item.
1856 1856
    int operator[](const Item& item) const { return _graph->id(item);}
1857 1857

	
1858 1858
    /// \brief Gives back the \e item by its id.
1859 1859
    ///
1860 1860
    /// Gives back the \e item by its id.
1861 1861
    Item operator()(int id) { return _graph->fromId(id, Item()); }
1862 1862

	
1863 1863
  private:
1864 1864
    const Graph* _graph;
1865 1865

	
1866 1866
  public:
1867 1867

	
1868 1868
    /// \brief The inverse map type of IdMap.
1869 1869
    ///
1870 1870
    /// The inverse map type of IdMap. The subscript operator gives back
1871 1871
    /// an item by its id.
1872 1872
    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1873 1873
    /// \see inverse()
1874 1874
    class InverseMap {
1875 1875
    public:
1876 1876

	
1877 1877
      /// \brief Constructor.
1878 1878
      ///
1879 1879
      /// Constructor for creating an id-to-item map.
1880 1880
      explicit InverseMap(const Graph& graph) : _graph(&graph) {}
1881 1881

	
1882 1882
      /// \brief Constructor.
1883 1883
      ///
1884 1884
      /// Constructor for creating an id-to-item map.
1885 1885
      explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
1886 1886

	
1887 1887
      /// \brief Gives back an item by its id.
1888 1888
      ///
1889 1889
      /// Gives back an item by its id.
1890 1890
      Item operator[](int id) const { return _graph->fromId(id, Item());}
1891 1891

	
1892 1892
    private:
1893 1893
      const Graph* _graph;
1894 1894
    };
1895 1895

	
1896 1896
    /// \brief Gives back the inverse of the map.
1897 1897
    ///
1898 1898
    /// Gives back the inverse of the IdMap.
1899 1899
    InverseMap inverse() const { return InverseMap(*_graph);}
1900 1900
  };
1901 1901

	
1902 1902

	
1903 1903
  /// \brief General cross reference graph map type.
1904 1904

	
1905 1905
  /// This class provides simple invertable graph maps.
1906 1906
  /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
1907 1907
  /// and if a key is set to a new value, then stores it in the inverse map.
1908 1908
  /// The graph items can be accessed by their values either using
1909 1909
  /// \c InverseMap or \c operator()(), and the values of the map can be
1910
  /// accessed with an STL compatible forward iterator (\c ValueIterator).
1910
  /// accessed with an STL compatible forward iterator (\c ValueIt).
1911 1911
  /// 
1912 1912
  /// This map is intended to be used when all associated values are
1913 1913
  /// different (the map is actually invertable) or there are only a few
1914 1914
  /// items with the same value.
1915 1915
  /// Otherwise consider to use \c IterableValueMap, which is more 
1916 1916
  /// suitable and more efficient for such cases. It provides iterators
1917 1917
  /// to traverse the items with the same associated value, however
1918 1918
  /// it does not have \c InverseMap.
1919 1919
  ///
1920 1920
  /// This type is not reference map, so it cannot be modified with
1921 1921
  /// the subscript operator.
1922 1922
  ///
1923 1923
  /// \tparam GR The graph type.
1924 1924
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1925 1925
  /// \c GR::Edge).
1926 1926
  /// \tparam V The value type of the map.
1927 1927
  ///
1928 1928
  /// \see IterableValueMap
1929 1929
  template <typename GR, typename K, typename V>
1930 1930
  class CrossRefMap
1931 1931
    : protected ItemSetTraits<GR, K>::template Map<V>::Type {
1932 1932
  private:
1933 1933

	
1934 1934
    typedef typename ItemSetTraits<GR, K>::
1935 1935
      template Map<V>::Type Map;
1936 1936

	
1937 1937
    typedef std::multimap<V, K> Container;
1938 1938
    Container _inv_map;
1939 1939

	
1940 1940
  public:
1941 1941

	
1942 1942
    /// The graph type of CrossRefMap.
1943 1943
    typedef GR Graph;
1944 1944
    typedef GR Digraph;
1945 1945
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1946 1946
    typedef K Item;
1947 1947
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1948 1948
    typedef K Key;
1949 1949
    /// The value type of CrossRefMap.
1950 1950
    typedef V Value;
1951 1951

	
1952 1952
    /// \brief Constructor.
1953 1953
    ///
1954 1954
    /// Construct a new CrossRefMap for the given graph.
1955 1955
    explicit CrossRefMap(const Graph& graph) : Map(graph) {}
1956 1956

	
1957 1957
    /// \brief Forward iterator for values.
1958 1958
    ///
1959 1959
    /// This iterator is an STL compatible forward
1960 1960
    /// iterator on the values of the map. The values can
1961 1961
    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
1962 1962
    /// They are considered with multiplicity, so each value is
1963 1963
    /// traversed for each item it is assigned to.
1964
    class ValueIterator
1964
    class ValueIt
1965 1965
      : public std::iterator<std::forward_iterator_tag, Value> {
1966 1966
      friend class CrossRefMap;
1967 1967
    private:
1968
      ValueIterator(typename Container::const_iterator _it)
1968
      ValueIt(typename Container::const_iterator _it)
1969 1969
        : it(_it) {}
1970 1970
    public:
1971 1971

	
1972 1972
      /// Constructor
1973
      ValueIterator() {}
1973
      ValueIt() {}
1974 1974

	
1975 1975
      /// \e
1976
      ValueIterator& operator++() { ++it; return *this; }
1976
      ValueIt& operator++() { ++it; return *this; }
1977 1977
      /// \e
1978
      ValueIterator operator++(int) {
1979
        ValueIterator tmp(*this);
1978
      ValueIt operator++(int) {
1979
        ValueIt tmp(*this);
1980 1980
        operator++();
1981 1981
        return tmp;
1982 1982
      }
1983 1983

	
1984 1984
      /// \e
1985 1985
      const Value& operator*() const { return it->first; }
1986 1986
      /// \e
1987 1987
      const Value* operator->() const { return &(it->first); }
1988 1988

	
1989 1989
      /// \e
1990
      bool operator==(ValueIterator jt) const { return it == jt.it; }
1990
      bool operator==(ValueIt jt) const { return it == jt.it; }
1991 1991
      /// \e
1992
      bool operator!=(ValueIterator jt) const { return it != jt.it; }
1992
      bool operator!=(ValueIt jt) const { return it != jt.it; }
1993 1993

	
1994 1994
    private:
1995 1995
      typename Container::const_iterator it;
1996 1996
    };
1997
    
1998
    /// Alias for \c ValueIt
1999
    typedef ValueIt ValueIterator;
1997 2000

	
1998 2001
    /// \brief Returns an iterator to the first value.
1999 2002
    ///
2000 2003
    /// Returns an STL compatible iterator to the
2001 2004
    /// first value of the map. The values of the
2002 2005
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
2003 2006
    /// range.
2004
    ValueIterator beginValue() const {
2005
      return ValueIterator(_inv_map.begin());
2007
    ValueIt beginValue() const {
2008
      return ValueIt(_inv_map.begin());
2006 2009
    }
2007 2010

	
2008 2011
    /// \brief Returns an iterator after the last value.
2009 2012
    ///
2010 2013
    /// Returns an STL compatible iterator after the
2011 2014
    /// last value of the map. The values of the
2012 2015
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
2013 2016
    /// range.
2014
    ValueIterator endValue() const {
2015
      return ValueIterator(_inv_map.end());
2017
    ValueIt endValue() const {
2018
      return ValueIt(_inv_map.end());
2016 2019
    }
2017 2020

	
2018 2021
    /// \brief Sets the value associated with the given key.
2019 2022
    ///
2020 2023
    /// Sets the value associated with the given key.
2021 2024
    void set(const Key& key, const Value& val) {
2022 2025
      Value oldval = Map::operator[](key);
2023 2026
      typename Container::iterator it;
2024 2027
      for (it = _inv_map.equal_range(oldval).first;
2025 2028
           it != _inv_map.equal_range(oldval).second; ++it) {
2026 2029
        if (it->second == key) {
2027 2030
          _inv_map.erase(it);
2028 2031
          break;
2029 2032
        }
2030 2033
      }
2031 2034
      _inv_map.insert(std::make_pair(val, key));
2032 2035
      Map::set(key, val);
2033 2036
    }
2034 2037

	
2035 2038
    /// \brief Returns the value associated with the given key.
2036 2039
    ///
2037 2040
    /// Returns the value associated with the given key.
2038 2041
    typename MapTraits<Map>::ConstReturnValue
2039 2042
    operator[](const Key& key) const {
2040 2043
      return Map::operator[](key);
2041 2044
    }
2042 2045

	
2043 2046
    /// \brief Gives back an item by its value.
2044 2047
    ///
2045 2048
    /// This function gives back an item that is assigned to
2046 2049
    /// the given value or \c INVALID if no such item exists.
2047 2050
    /// If there are more items with the same associated value,
2048 2051
    /// only one of them is returned.
2049 2052
    Key operator()(const Value& val) const {
2050 2053
      typename Container::const_iterator it = _inv_map.find(val);
2051 2054
      return it != _inv_map.end() ? it->second : INVALID;
2052 2055
    }
2053 2056
    
2054 2057
    /// \brief Returns the number of items with the given value.
2055 2058
    ///
2056 2059
    /// This function returns the number of items with the given value
2057 2060
    /// associated with it.
2058 2061
    int count(const Value &val) const {
2059 2062
      return _inv_map.count(val);
2060 2063
    }
2061 2064

	
2062 2065
  protected:
2063 2066

	
2064 2067
    /// \brief Erase the key from the map and the inverse map.
2065 2068
    ///
2066 2069
    /// Erase the key from the map and the inverse map. It is called by the
2067 2070
    /// \c AlterationNotifier.
2068 2071
    virtual void erase(const Key& key) {
2069 2072
      Value val = Map::operator[](key);
2070 2073
      typename Container::iterator it;
2071 2074
      for (it = _inv_map.equal_range(val).first;
2072 2075
           it != _inv_map.equal_range(val).second; ++it) {
2073 2076
        if (it->second == key) {
2074 2077
          _inv_map.erase(it);
2075 2078
          break;
2076 2079
        }
2077 2080
      }
2078 2081
      Map::erase(key);
2079 2082
    }
2080 2083

	
2081 2084
    /// \brief Erase more keys from the map and the inverse map.
2082 2085
    ///
2083 2086
    /// Erase more keys from the map and the inverse map. It is called by the
2084 2087
    /// \c AlterationNotifier.
2085 2088
    virtual void erase(const std::vector<Key>& keys) {
2086 2089
      for (int i = 0; i < int(keys.size()); ++i) {
2087 2090
        Value val = Map::operator[](keys[i]);
2088 2091
        typename Container::iterator it;
2089 2092
        for (it = _inv_map.equal_range(val).first;
2090 2093
             it != _inv_map.equal_range(val).second; ++it) {
2091 2094
          if (it->second == keys[i]) {
2092 2095
            _inv_map.erase(it);
2093 2096
            break;
2094 2097
          }
2095 2098
        }
2096 2099
      }
2097 2100
      Map::erase(keys);
2098 2101
    }
2099 2102

	
2100 2103
    /// \brief Clear the keys from the map and the inverse map.
2101 2104
    ///
2102 2105
    /// Clear the keys from the map and the inverse map. It is called by the
2103 2106
    /// \c AlterationNotifier.
2104 2107
    virtual void clear() {
2105 2108
      _inv_map.clear();
2106 2109
      Map::clear();
2107 2110
    }
2108 2111

	
2109 2112
  public:
2110 2113

	
2111 2114
    /// \brief The inverse map type of CrossRefMap.
... ...
@@ -2930,574 +2933,578 @@
2930 2933
    /// \brief Const subscript operator of the map.
2931 2934
    ///
2932 2935
    /// Const subscript operator of the map.
2933 2936
    const Value& operator[](const Key& key) const {
2934 2937
      return Parent::operator[](key).value;
2935 2938
    }
2936 2939

	
2937 2940
    /// \brief Subscript operator of the map.
2938 2941
    ///
2939 2942
    /// Subscript operator of the map.
2940 2943
    Reference operator[](const Key& key) {
2941 2944
      return Reference(*this, key);
2942 2945
    }
2943 2946

	
2944 2947
    /// \brief Iterator for the keys with the same value.
2945 2948
    ///
2946 2949
    /// Iterator for the keys with the same value. It works
2947 2950
    /// like a graph item iterator, it can be converted to
2948 2951
    /// the item type of the map, incremented with \c ++ operator, and
2949 2952
    /// if the iterator leaves the last valid item, it will be equal to
2950 2953
    /// \c INVALID.
2951 2954
    class ItemIt : public Key {
2952 2955
    public:
2953 2956
      typedef Key Parent;
2954 2957

	
2955 2958
      /// \brief Invalid constructor \& conversion.
2956 2959
      ///
2957 2960
      /// This constructor initializes the iterator to be invalid.
2958 2961
      /// \sa Invalid for more details.
2959 2962
      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
2960 2963

	
2961 2964
      /// \brief Creates an iterator with a value.
2962 2965
      ///
2963 2966
      /// Creates an iterator with a value. It iterates on the
2964 2967
      /// keys mapped to the given value.
2965 2968
      /// \param map The IterableIntMap.
2966 2969
      /// \param value The value.
2967 2970
      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
2968 2971
        if (value < 0 || value >= int(_map->_first.size())) {
2969 2972
          Parent::operator=(INVALID);
2970 2973
        } else {
2971 2974
          Parent::operator=(_map->_first[value]);
2972 2975
        }
2973 2976
      }
2974 2977

	
2975 2978
      /// \brief Increment operator.
2976 2979
      ///
2977 2980
      /// Increment operator.
2978 2981
      ItemIt& operator++() {
2979 2982
        Parent::operator=(_map->IterableIntMap::Parent::
2980 2983
                          operator[](static_cast<Parent&>(*this)).next);
2981 2984
        return *this;
2982 2985
      }
2983 2986

	
2984 2987
    private:
2985 2988
      const IterableIntMap* _map;
2986 2989
    };
2987 2990

	
2988 2991
  protected:
2989 2992

	
2990 2993
    virtual void erase(const Key& key) {
2991 2994
      unlace(key);
2992 2995
      Parent::erase(key);
2993 2996
    }
2994 2997

	
2995 2998
    virtual void erase(const std::vector<Key>& keys) {
2996 2999
      for (int i = 0; i < int(keys.size()); ++i) {
2997 3000
        unlace(keys[i]);
2998 3001
      }
2999 3002
      Parent::erase(keys);
3000 3003
    }
3001 3004

	
3002 3005
    virtual void clear() {
3003 3006
      _first.clear();
3004 3007
      Parent::clear();
3005 3008
    }
3006 3009

	
3007 3010
  private:
3008 3011
    std::vector<Key> _first;
3009 3012
  };
3010 3013

	
3011 3014
  namespace _maps_bits {
3012 3015
    template <typename Item, typename Value>
3013 3016
    struct IterableValueMapNode {
3014 3017
      IterableValueMapNode(Value _value = Value()) : value(_value) {}
3015 3018
      Item prev, next;
3016 3019
      Value value;
3017 3020
    };
3018 3021
  }
3019 3022

	
3020 3023
  /// \brief Dynamic iterable map for comparable values.
3021 3024
  ///
3022 3025
  /// This class provides a special graph map type which can store a
3023 3026
  /// comparable value for graph items (\c Node, \c Arc or \c Edge).
3024 3027
  /// For each value it is possible to iterate on the keys mapped to
3025 3028
  /// the value (\c ItemIt), and the values of the map can be accessed
3026
  /// with an STL compatible forward iterator (\c ValueIterator).
3029
  /// with an STL compatible forward iterator (\c ValueIt).
3027 3030
  /// The map stores a linked list for each value, which contains
3028 3031
  /// the items mapped to the value, and the used values are stored
3029 3032
  /// in balanced binary tree (\c std::map).
3030 3033
  ///
3031 3034
  /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
3032 3035
  /// specialized for \c bool and \c int values, respectively.
3033 3036
  ///
3034 3037
  /// This type is not reference map, so it cannot be modified with
3035 3038
  /// the subscript operator.
3036 3039
  ///
3037 3040
  /// \tparam GR The graph type.
3038 3041
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
3039 3042
  /// \c GR::Edge).
3040 3043
  /// \tparam V The value type of the map. It can be any comparable
3041 3044
  /// value type.
3042 3045
  ///
3043 3046
  /// \see IterableBoolMap, IterableIntMap
3044 3047
  /// \see CrossRefMap
3045 3048
  template <typename GR, typename K, typename V>
3046 3049
  class IterableValueMap
3047 3050
    : protected ItemSetTraits<GR, K>::
3048 3051
        template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
3049 3052
  public:
3050 3053
    typedef typename ItemSetTraits<GR, K>::
3051 3054
      template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
3052 3055

	
3053 3056
    /// The key type
3054 3057
    typedef K Key;
3055 3058
    /// The value type
3056 3059
    typedef V Value;
3057 3060
    /// The graph type
3058 3061
    typedef GR Graph;
3059 3062

	
3060 3063
  public:
3061 3064

	
3062 3065
    /// \brief Constructor of the map with a given value.
3063 3066
    ///
3064 3067
    /// Constructor of the map with a given value.
3065 3068
    explicit IterableValueMap(const Graph& graph,
3066 3069
                              const Value& value = Value())
3067 3070
      : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
3068 3071
      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
3069 3072
        lace(it);
3070 3073
      }
3071 3074
    }
3072 3075

	
3073 3076
  protected:
3074 3077

	
3075 3078
    void unlace(const Key& key) {
3076 3079
      typename Parent::Value& node = Parent::operator[](key);
3077 3080
      if (node.prev != INVALID) {
3078 3081
        Parent::operator[](node.prev).next = node.next;
3079 3082
      } else {
3080 3083
        if (node.next != INVALID) {
3081 3084
          _first[node.value] = node.next;
3082 3085
        } else {
3083 3086
          _first.erase(node.value);
3084 3087
        }
3085 3088
      }
3086 3089
      if (node.next != INVALID) {
3087 3090
        Parent::operator[](node.next).prev = node.prev;
3088 3091
      }
3089 3092
    }
3090 3093

	
3091 3094
    void lace(const Key& key) {
3092 3095
      typename Parent::Value& node = Parent::operator[](key);
3093 3096
      typename std::map<Value, Key>::iterator it = _first.find(node.value);
3094 3097
      if (it == _first.end()) {
3095 3098
        node.prev = node.next = INVALID;
3096 3099
        _first.insert(std::make_pair(node.value, key));
3097 3100
      } else {
3098 3101
        node.prev = INVALID;
3099 3102
        node.next = it->second;
3100 3103
        if (node.next != INVALID) {
3101 3104
          Parent::operator[](node.next).prev = key;
3102 3105
        }
3103 3106
        it->second = key;
3104 3107
      }
3105 3108
    }
3106 3109

	
3107 3110
  public:
3108 3111

	
3109 3112
    /// \brief Forward iterator for values.
3110 3113
    ///
3111 3114
    /// This iterator is an STL compatible forward
3112 3115
    /// iterator on the values of the map. The values can
3113 3116
    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
3114
    class ValueIterator
3117
    class ValueIt
3115 3118
      : public std::iterator<std::forward_iterator_tag, Value> {
3116 3119
      friend class IterableValueMap;
3117 3120
    private:
3118
      ValueIterator(typename std::map<Value, Key>::const_iterator _it)
3121
      ValueIt(typename std::map<Value, Key>::const_iterator _it)
3119 3122
        : it(_it) {}
3120 3123
    public:
3121 3124

	
3122 3125
      /// Constructor
3123
      ValueIterator() {}
3126
      ValueIt() {}
3124 3127

	
3125 3128
      /// \e
3126
      ValueIterator& operator++() { ++it; return *this; }
3129
      ValueIt& operator++() { ++it; return *this; }
3127 3130
      /// \e
3128
      ValueIterator operator++(int) {
3129
        ValueIterator tmp(*this);
3131
      ValueIt operator++(int) {
3132
        ValueIt tmp(*this);
3130 3133
        operator++();
3131 3134
        return tmp;
3132 3135
      }
3133 3136

	
3134 3137
      /// \e
3135 3138
      const Value& operator*() const { return it->first; }
3136 3139
      /// \e
3137 3140
      const Value* operator->() const { return &(it->first); }
3138 3141

	
3139 3142
      /// \e
3140
      bool operator==(ValueIterator jt) const { return it == jt.it; }
3143
      bool operator==(ValueIt jt) const { return it == jt.it; }
3141 3144
      /// \e
3142
      bool operator!=(ValueIterator jt) const { return it != jt.it; }
3145
      bool operator!=(ValueIt jt) const { return it != jt.it; }
3143 3146

	
3144 3147
    private:
3145 3148
      typename std::map<Value, Key>::const_iterator it;
3146 3149
    };
3147 3150

	
3148 3151
    /// \brief Returns an iterator to the first value.
3149 3152
    ///
3150 3153
    /// Returns an STL compatible iterator to the
3151 3154
    /// first value of the map. The values of the
3152 3155
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
3153 3156
    /// range.
3154
    ValueIterator beginValue() const {
3155
      return ValueIterator(_first.begin());
3157
    ValueIt beginValue() const {
3158
      return ValueIt(_first.begin());
3156 3159
    }
3157 3160

	
3158 3161
    /// \brief Returns an iterator after the last value.
3159 3162
    ///
3160 3163
    /// Returns an STL compatible iterator after the
3161 3164
    /// last value of the map. The values of the
3162 3165
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
3163 3166
    /// range.
3164
    ValueIterator endValue() const {
3165
      return ValueIterator(_first.end());
3167
    ValueIt endValue() const {
3168
      return ValueIt(_first.end());
3166 3169
    }
3167 3170

	
3168 3171
    /// \brief Set operation of the map.
3169 3172
    ///
3170 3173
    /// Set operation of the map.
3171 3174
    void set(const Key& key, const Value& value) {
3172 3175
      unlace(key);
3173 3176
      Parent::operator[](key).value = value;
3174 3177
      lace(key);
3175 3178
    }
3176 3179

	
3177 3180
    /// \brief Const subscript operator of the map.
3178 3181
    ///
3179 3182
    /// Const subscript operator of the map.
3180 3183
    const Value& operator[](const Key& key) const {
3181 3184
      return Parent::operator[](key).value;
3182 3185
    }
3183 3186

	
3184 3187
    /// \brief Iterator for the keys with the same value.
3185 3188
    ///
3186 3189
    /// Iterator for the keys with the same value. It works
3187 3190
    /// like a graph item iterator, it can be converted to
3188 3191
    /// the item type of the map, incremented with \c ++ operator, and
3189 3192
    /// if the iterator leaves the last valid item, it will be equal to
3190 3193
    /// \c INVALID.
3191 3194
    class ItemIt : public Key {
3192 3195
    public:
3193 3196
      typedef Key Parent;
3194 3197

	
3195 3198
      /// \brief Invalid constructor \& conversion.
3196 3199
      ///
3197 3200
      /// This constructor initializes the iterator to be invalid.
3198 3201
      /// \sa Invalid for more details.
3199 3202
      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
3200 3203

	
3201 3204
      /// \brief Creates an iterator with a value.
3202 3205
      ///
3203 3206
      /// Creates an iterator with a value. It iterates on the
3204 3207
      /// keys which have the given value.
3205 3208
      /// \param map The IterableValueMap
3206 3209
      /// \param value The value
3207 3210
      ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
3208 3211
        typename std::map<Value, Key>::const_iterator it =
3209 3212
          map._first.find(value);
3210 3213
        if (it == map._first.end()) {
3211 3214
          Parent::operator=(INVALID);
3212 3215
        } else {
3213 3216
          Parent::operator=(it->second);
3214 3217
        }
3215 3218
      }
3216 3219

	
3217 3220
      /// \brief Increment operator.
3218 3221
      ///
3219 3222
      /// Increment Operator.
3220 3223
      ItemIt& operator++() {
3221 3224
        Parent::operator=(_map->IterableValueMap::Parent::
3222 3225
                          operator[](static_cast<Parent&>(*this)).next);
3223 3226
        return *this;
3224 3227
      }
3225 3228

	
3226 3229

	
3227 3230
    private:
3228 3231
      const IterableValueMap* _map;
3229 3232
    };
3230 3233

	
3231 3234
  protected:
3232 3235

	
3233 3236
    virtual void add(const Key& key) {
3234 3237
      Parent::add(key);
3235 3238
      unlace(key);
3236 3239
    }
3237 3240

	
3238 3241
    virtual void add(const std::vector<Key>& keys) {
3239 3242
      Parent::add(keys);
3240 3243
      for (int i = 0; i < int(keys.size()); ++i) {
3241 3244
        lace(keys[i]);
3242 3245
      }
3243 3246
    }
3244 3247

	
3245 3248
    virtual void erase(const Key& key) {
3246 3249
      unlace(key);
3247 3250
      Parent::erase(key);
3248 3251
    }
3249 3252

	
3250 3253
    virtual void erase(const std::vector<Key>& keys) {
3251 3254
      for (int i = 0; i < int(keys.size()); ++i) {
3252 3255
        unlace(keys[i]);
3253 3256
      }
3254 3257
      Parent::erase(keys);
3255 3258
    }
3256 3259

	
3257 3260
    virtual void build() {
3258 3261
      Parent::build();
3259 3262
      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
3260 3263
        lace(it);
3261 3264
      }
3262 3265
    }
3263 3266

	
3264 3267
    virtual void clear() {
3265 3268
      _first.clear();
3266 3269
      Parent::clear();
3267 3270
    }
3268 3271

	
3269 3272
  private:
3270 3273
    std::map<Value, Key> _first;
3271 3274
  };
3272 3275

	
3273 3276
  /// \brief Map of the source nodes of arcs in a digraph.
3274 3277
  ///
3275 3278
  /// SourceMap provides access for the source node of each arc in a digraph,
3276 3279
  /// which is returned by the \c source() function of the digraph.
3277 3280
  /// \tparam GR The digraph type.
3278 3281
  /// \see TargetMap
3279 3282
  template <typename GR>
3280 3283
  class SourceMap {
3281 3284
  public:
3282 3285

	
3283
    ///\e
3286
    /// The key type (the \c Arc type of the digraph).
3284 3287
    typedef typename GR::Arc Key;
3285
    ///\e
3288
    /// The value type (the \c Node type of the digraph).
3286 3289
    typedef typename GR::Node Value;
3287 3290

	
3288 3291
    /// \brief Constructor
3289 3292
    ///
3290 3293
    /// Constructor.
3291 3294
    /// \param digraph The digraph that the map belongs to.
3292 3295
    explicit SourceMap(const GR& digraph) : _graph(digraph) {}
3293 3296

	
3294 3297
    /// \brief Returns the source node of the given arc.
3295 3298
    ///
3296 3299
    /// Returns the source node of the given arc.
3297 3300
    Value operator[](const Key& arc) const {
3298 3301
      return _graph.source(arc);
3299 3302
    }
3300 3303

	
3301 3304
  private:
3302 3305
    const GR& _graph;
3303 3306
  };
3304 3307

	
3305 3308
  /// \brief Returns a \c SourceMap class.
3306 3309
  ///
3307 3310
  /// This function just returns an \c SourceMap class.
3308 3311
  /// \relates SourceMap
3309 3312
  template <typename GR>
3310 3313
  inline SourceMap<GR> sourceMap(const GR& graph) {
3311 3314
    return SourceMap<GR>(graph);
3312 3315
  }
3313 3316

	
3314 3317
  /// \brief Map of the target nodes of arcs in a digraph.
3315 3318
  ///
3316 3319
  /// TargetMap provides access for the target node of each arc in a digraph,
3317 3320
  /// which is returned by the \c target() function of the digraph.
3318 3321
  /// \tparam GR The digraph type.
3319 3322
  /// \see SourceMap
3320 3323
  template <typename GR>
3321 3324
  class TargetMap {
3322 3325
  public:
3323 3326

	
3324
    ///\e
3327
    /// The key type (the \c Arc type of the digraph).
3325 3328
    typedef typename GR::Arc Key;
3326
    ///\e
3329
    /// The value type (the \c Node type of the digraph).
3327 3330
    typedef typename GR::Node Value;
3328 3331

	
3329 3332
    /// \brief Constructor
3330 3333
    ///
3331 3334
    /// Constructor.
3332 3335
    /// \param digraph The digraph that the map belongs to.
3333 3336
    explicit TargetMap(const GR& digraph) : _graph(digraph) {}
3334 3337

	
3335 3338
    /// \brief Returns the target node of the given arc.
3336 3339
    ///
3337 3340
    /// Returns the target node of the given arc.
3338 3341
    Value operator[](const Key& e) const {
3339 3342
      return _graph.target(e);
3340 3343
    }
3341 3344

	
3342 3345
  private:
3343 3346
    const GR& _graph;
3344 3347
  };
3345 3348

	
3346 3349
  /// \brief Returns a \c TargetMap class.
3347 3350
  ///
3348 3351
  /// This function just returns a \c TargetMap class.
3349 3352
  /// \relates TargetMap
3350 3353
  template <typename GR>
3351 3354
  inline TargetMap<GR> targetMap(const GR& graph) {
3352 3355
    return TargetMap<GR>(graph);
3353 3356
  }
3354 3357

	
3355 3358
  /// \brief Map of the "forward" directed arc view of edges in a graph.
3356 3359
  ///
3357 3360
  /// ForwardMap provides access for the "forward" directed arc view of
3358 3361
  /// each edge in a graph, which is returned by the \c direct() function
3359 3362
  /// of the graph with \c true parameter.
3360 3363
  /// \tparam GR The graph type.
3361 3364
  /// \see BackwardMap
3362 3365
  template <typename GR>
3363 3366
  class ForwardMap {
3364 3367
  public:
3365 3368

	
3369
    /// The key type (the \c Edge type of the digraph).
3370
    typedef typename GR::Edge Key;
3371
    /// The value type (the \c Arc type of the digraph).
3366 3372
    typedef typename GR::Arc Value;
3367
    typedef typename GR::Edge Key;
3368 3373

	
3369 3374
    /// \brief Constructor
3370 3375
    ///
3371 3376
    /// Constructor.
3372 3377
    /// \param graph The graph that the map belongs to.
3373 3378
    explicit ForwardMap(const GR& graph) : _graph(graph) {}
3374 3379

	
3375 3380
    /// \brief Returns the "forward" directed arc view of the given edge.
3376 3381
    ///
3377 3382
    /// Returns the "forward" directed arc view of the given edge.
3378 3383
    Value operator[](const Key& key) const {
3379 3384
      return _graph.direct(key, true);
3380 3385
    }
3381 3386

	
3382 3387
  private:
3383 3388
    const GR& _graph;
3384 3389
  };
3385 3390

	
3386 3391
  /// \brief Returns a \c ForwardMap class.
3387 3392
  ///
3388 3393
  /// This function just returns an \c ForwardMap class.
3389 3394
  /// \relates ForwardMap
3390 3395
  template <typename GR>
3391 3396
  inline ForwardMap<GR> forwardMap(const GR& graph) {
3392 3397
    return ForwardMap<GR>(graph);
3393 3398
  }
3394 3399

	
3395 3400
  /// \brief Map of the "backward" directed arc view of edges in a graph.
3396 3401
  ///
3397 3402
  /// BackwardMap provides access for the "backward" directed arc view of
3398 3403
  /// each edge in a graph, which is returned by the \c direct() function
3399 3404
  /// of the graph with \c false parameter.
3400 3405
  /// \tparam GR The graph type.
3401 3406
  /// \see ForwardMap
3402 3407
  template <typename GR>
3403 3408
  class BackwardMap {
3404 3409
  public:
3405 3410

	
3411
    /// The key type (the \c Edge type of the digraph).
3412
    typedef typename GR::Edge Key;
3413
    /// The value type (the \c Arc type of the digraph).
3406 3414
    typedef typename GR::Arc Value;
3407
    typedef typename GR::Edge Key;
3408 3415

	
3409 3416
    /// \brief Constructor
3410 3417
    ///
3411 3418
    /// Constructor.
3412 3419
    /// \param graph The graph that the map belongs to.
3413 3420
    explicit BackwardMap(const GR& graph) : _graph(graph) {}
3414 3421

	
3415 3422
    /// \brief Returns the "backward" directed arc view of the given edge.
3416 3423
    ///
3417 3424
    /// Returns the "backward" directed arc view of the given edge.
3418 3425
    Value operator[](const Key& key) const {
3419 3426
      return _graph.direct(key, false);
3420 3427
    }
3421 3428

	
3422 3429
  private:
3423 3430
    const GR& _graph;
3424 3431
  };
3425 3432

	
3426 3433
  /// \brief Returns a \c BackwardMap class
3427 3434

	
3428 3435
  /// This function just returns a \c BackwardMap class.
3429 3436
  /// \relates BackwardMap
3430 3437
  template <typename GR>
3431 3438
  inline BackwardMap<GR> backwardMap(const GR& graph) {
3432 3439
    return BackwardMap<GR>(graph);
3433 3440
  }
3434 3441

	
3435 3442
  /// \brief Map of the in-degrees of nodes in a digraph.
3436 3443
  ///
3437 3444
  /// This map returns the in-degree of a node. Once it is constructed,
3438 3445
  /// the degrees are stored in a standard \c NodeMap, so each query is done
3439 3446
  /// in constant time. On the other hand, the values are updated automatically
3440 3447
  /// whenever the digraph changes.
3441 3448
  ///
3442 3449
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
3443 3450
  /// may provide alternative ways to modify the digraph.
3444 3451
  /// The correct behavior of InDegMap is not guarantied if these additional
3445 3452
  /// features are used. For example the functions
3446 3453
  /// \ref ListDigraph::changeSource() "changeSource()",
3447 3454
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
3448 3455
  /// \ref ListDigraph::reverseArc() "reverseArc()"
3449 3456
  /// of \ref ListDigraph will \e not update the degree values correctly.
3450 3457
  ///
3451 3458
  /// \sa OutDegMap
3452 3459
  template <typename GR>
3453 3460
  class InDegMap
3454 3461
    : protected ItemSetTraits<GR, typename GR::Arc>
3455 3462
      ::ItemNotifier::ObserverBase {
3456 3463

	
3457 3464
  public:
3458 3465

	
3459 3466
    /// The graph type of InDegMap
3460 3467
    typedef GR Graph;
3461 3468
    typedef GR Digraph;
3462 3469
    /// The key type
3463 3470
    typedef typename Digraph::Node Key;
3464 3471
    /// The value type
3465 3472
    typedef int Value;
3466 3473

	
3467 3474
    typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
3468 3475
    ::ItemNotifier::ObserverBase Parent;
3469 3476

	
3470 3477
  private:
3471 3478

	
3472 3479
    class AutoNodeMap
3473 3480
      : public ItemSetTraits<Digraph, Key>::template Map<int>::Type {
3474 3481
    public:
3475 3482

	
3476 3483
      typedef typename ItemSetTraits<Digraph, Key>::
3477 3484
      template Map<int>::Type Parent;
3478 3485

	
3479 3486
      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
3480 3487

	
3481 3488
      virtual void add(const Key& key) {
3482 3489
        Parent::add(key);
3483 3490
        Parent::set(key, 0);
3484 3491
      }
3485 3492

	
3486 3493
      virtual void add(const std::vector<Key>& keys) {
3487 3494
        Parent::add(keys);
3488 3495
        for (int i = 0; i < int(keys.size()); ++i) {
3489 3496
          Parent::set(keys[i], 0);
3490 3497
        }
3491 3498
      }
3492 3499

	
3493 3500
      virtual void build() {
3494 3501
        Parent::build();
3495 3502
        Key it;
3496 3503
        typename Parent::Notifier* nf = Parent::notifier();
3497 3504
        for (nf->first(it); it != INVALID; nf->next(it)) {
3498 3505
          Parent::set(it, 0);
3499 3506
        }
3500 3507
      }
3501 3508
    };
3502 3509

	
3503 3510
  public:
Ignore white space 6 line context
... ...
@@ -433,213 +433,212 @@
433 433
    check(nrmap.size() == 3 && armap.size() == 4,
434 434
          "Wrong RangeIdMap::size()");
435 435

	
436 436
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
437 437
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
438 438
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
439 439
    
440 440
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
441 441
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
442 442
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
443 443
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
444 444

	
445 445
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
446 446
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
447 447
    
448 448
    gr.erase(n1);
449 449
    
450 450
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
451 451
    nrmap.swap(n2, n0);
452 452
    if (armap[a1] == 1) armap.swap(a1, a3);
453 453
    armap.swap(a3, a1);
454 454
    
455 455
    check(nrmap.size() == 2 && armap.size() == 2,
456 456
          "Wrong RangeIdMap::size()");
457 457

	
458 458
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
459 459
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
460 460
    
461 461
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
462 462
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
463 463

	
464 464
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
465 465
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
466 466
  }
467 467
  
468 468
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
469 469
  {
470 470
    typedef ListGraph Graph;
471 471
    GRAPH_TYPEDEFS(Graph);
472 472
    
473 473
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
474 474
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
475 475
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
476 476
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
477 477
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
478 478
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
479 479

	
480 480
    Graph gr;
481 481
    Node n0 = gr.addNode();
482 482
    Node n1 = gr.addNode();
483 483
    Node n2 = gr.addNode();
484 484
    
485 485
    gr.addEdge(n0,n1);
486 486
    gr.addEdge(n1,n2);
487 487
    gr.addEdge(n0,n2);
488 488
    gr.addEdge(n2,n1);
489 489
    gr.addEdge(n1,n2);
490 490
    gr.addEdge(n0,n1);
491 491
    
492 492
    for (EdgeIt e(gr); e != INVALID; ++e) {
493 493
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
494 494
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
495 495
    }
496 496
    
497 497
    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
498 498
               targetMap(orienter(gr, constMap<Edge, bool>(false))),
499 499
               EdgeIt(gr));
500 500

	
501 501
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
502 502
    Digraph dgr(gr, constMap<Edge, bool>(true));
503 503
    OutDegMap<Digraph> odm(dgr);
504 504
    InDegMap<Digraph> idm(dgr);
505 505
    
506 506
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
507 507
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
508 508
   
509 509
    gr.addEdge(n2, n0);
510 510

	
511 511
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
512 512
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
513 513
  }
514 514
  
515 515
  // CrossRefMap
516 516
  {
517 517
    typedef ListDigraph Graph;
518 518
    DIGRAPH_TYPEDEFS(Graph);
519 519

	
520 520
    checkConcept<ReadWriteMap<Node, int>,
521 521
                 CrossRefMap<Graph, Node, int> >();
522 522
    checkConcept<ReadWriteMap<Node, bool>,
523 523
                 CrossRefMap<Graph, Node, bool> >();
524 524
    checkConcept<ReadWriteMap<Node, double>,
525 525
                 CrossRefMap<Graph, Node, double> >();
526 526
    
527 527
    Graph gr;
528 528
    typedef CrossRefMap<Graph, Node, char> CRMap;
529
    typedef CRMap::ValueIterator ValueIt;
530 529
    CRMap map(gr);
531 530
    
532 531
    Node n0 = gr.addNode();
533 532
    Node n1 = gr.addNode();
534 533
    Node n2 = gr.addNode();
535 534
    
536 535
    map.set(n0, 'A');
537 536
    map.set(n1, 'B');
538 537
    map.set(n2, 'C');
539 538
    
540 539
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
541 540
          "Wrong CrossRefMap");
542 541
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
543 542
          "Wrong CrossRefMap");
544 543
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
545 544
          "Wrong CrossRefMap");
546 545
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
547 546
          "Wrong CrossRefMap::count()");
548 547
    
549
    ValueIt it = map.beginValue();
548
    CRMap::ValueIt it = map.beginValue();
550 549
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
551 550
          it == map.endValue(), "Wrong value iterator");
552 551
    
553 552
    map.set(n2, 'A');
554 553

	
555 554
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
556 555
          "Wrong CrossRefMap");
557 556
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
558 557
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
559 558
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
560 559
          "Wrong CrossRefMap");
561 560
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
562 561
          "Wrong CrossRefMap::count()");
563 562

	
564 563
    it = map.beginValue();
565 564
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
566 565
          it == map.endValue(), "Wrong value iterator");
567 566

	
568 567
    map.set(n0, 'C');
569 568

	
570 569
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
571 570
          "Wrong CrossRefMap");
572 571
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
573 572
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
574 573
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
575 574
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
576 575
          "Wrong CrossRefMap::count()");
577 576

	
578 577
    it = map.beginValue();
579 578
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
580 579
          it == map.endValue(), "Wrong value iterator");
581 580
  }
582 581

	
583 582
  // Iterable bool map
584 583
  {
585 584
    typedef SmartGraph Graph;
586 585
    typedef SmartGraph::Node Item;
587 586

	
588 587
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
589 588
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
590 589

	
591 590
    const int num = 10;
592 591
    Graph g;
593 592
    std::vector<Item> items;
594 593
    for (int i = 0; i < num; ++i) {
595 594
      items.push_back(g.addNode());
596 595
    }
597 596

	
598 597
    Ibm map1(g, true);
599 598
    int n = 0;
600 599
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
601 600
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
602 601
      ++n;
603 602
    }
604 603
    check(n == num, "Wrong number");
605 604

	
606 605
    n = 0;
607 606
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
608 607
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
609 608
        ++n;
610 609
    }
611 610
    check(n == num, "Wrong number");
612 611
    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
613 612
    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
614 613

	
615 614
    map1[items[5]] = true;
616 615

	
617 616
    n = 0;
618 617
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
619 618
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
620 619
        ++n;
621 620
    }
622 621
    check(n == num, "Wrong number");
623 622

	
624 623
    map1[items[num / 2]] = false;
625 624
    check(map1[items[num / 2]] == false, "Wrong map value");
626 625

	
627 626
    n = 0;
628 627
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
629 628
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
630 629
        ++n;
631 630
    }
632 631
    check(n == num - 1, "Wrong number");
633 632

	
634 633
    n = 0;
635 634
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
636 635
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
637 636
        ++n;
638 637
    }
639 638
    check(n == 1, "Wrong number");
640 639

	
641 640
    map1[items[0]] = false;
642 641
    check(map1[items[0]] == false, "Wrong map value");
643 642

	
644 643
    map1[items[num - 1]] = false;
645 644
    check(map1[items[num - 1]] == false, "Wrong map value");
... ...
@@ -649,123 +648,123 @@
649 648
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
650 649
        ++n;
651 650
    }
652 651
    check(n == num - 3, "Wrong number");
653 652
    check(map1.trueNum() == num - 3, "Wrong number");
654 653

	
655 654
    n = 0;
656 655
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
657 656
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
658 657
        ++n;
659 658
    }
660 659
    check(n == 3, "Wrong number");
661 660
    check(map1.falseNum() == 3, "Wrong number");
662 661
  }
663 662

	
664 663
  // Iterable int map
665 664
  {
666 665
    typedef SmartGraph Graph;
667 666
    typedef SmartGraph::Node Item;
668 667
    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
669 668

	
670 669
    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
671 670

	
672 671
    const int num = 10;
673 672
    Graph g;
674 673
    std::vector<Item> items;
675 674
    for (int i = 0; i < num; ++i) {
676 675
      items.push_back(g.addNode());
677 676
    }
678 677

	
679 678
    Iim map1(g);
680 679
    check(map1.size() == 0, "Wrong size");
681 680

	
682 681
    for (int i = 0; i < num; ++i) {
683 682
      map1[items[i]] = i;
684 683
    }
685 684
    check(map1.size() == num, "Wrong size");
686 685

	
687 686
    for (int i = 0; i < num; ++i) {
688 687
      Iim::ItemIt it(map1, i);
689 688
      check(static_cast<Item>(it) == items[i], "Wrong value");
690 689
      ++it;
691 690
      check(static_cast<Item>(it) == INVALID, "Wrong value");
692 691
    }
693 692

	
694 693
    for (int i = 0; i < num; ++i) {
695 694
      map1[items[i]] = i % 2;
696 695
    }
697 696
    check(map1.size() == 2, "Wrong size");
698 697

	
699 698
    int n = 0;
700 699
    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
701 700
      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
702 701
      ++n;
703 702
    }
704 703
    check(n == (num + 1) / 2, "Wrong number");
705 704

	
706 705
    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
707 706
      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
708 707
      ++n;
709 708
    }
710 709
    check(n == num, "Wrong number");
711 710

	
712 711
  }
713 712

	
714 713
  // Iterable value map
715 714
  {
716 715
    typedef SmartGraph Graph;
717 716
    typedef SmartGraph::Node Item;
718 717
    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
719 718

	
720 719
    checkConcept<ReadWriteMap<Item, double>, Ivm>();
721 720

	
722 721
    const int num = 10;
723 722
    Graph g;
724 723
    std::vector<Item> items;
725 724
    for (int i = 0; i < num; ++i) {
726 725
      items.push_back(g.addNode());
727 726
    }
728 727

	
729 728
    Ivm map1(g, 0.0);
730 729
    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
731 730
    check(*map1.beginValue() == 0.0, "Wrong value");
732 731

	
733 732
    for (int i = 0; i < num; ++i) {
734 733
      map1.set(items[i], static_cast<double>(i));
735 734
    }
736 735
    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
737 736

	
738 737
    for (int i = 0; i < num; ++i) {
739 738
      Ivm::ItemIt it(map1, static_cast<double>(i));
740 739
      check(static_cast<Item>(it) == items[i], "Wrong value");
741 740
      ++it;
742 741
      check(static_cast<Item>(it) == INVALID, "Wrong value");
743 742
    }
744 743

	
745
    for (Ivm::ValueIterator vit = map1.beginValue();
744
    for (Ivm::ValueIt vit = map1.beginValue();
746 745
         vit != map1.endValue(); ++vit) {
747 746
      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
748
            "Wrong ValueIterator");
747
            "Wrong ValueIt");
749 748
    }
750 749

	
751 750
    for (int i = 0; i < num; ++i) {
752 751
      map1.set(items[i], static_cast<double>(i % 2));
753 752
    }
754 753
    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
755 754

	
756 755
    int n = 0;
757 756
    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
758 757
      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
759 758
      ++n;
760 759
    }
761 760
    check(n == (num + 1) / 2, "Wrong number");
762 761

	
763 762
    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
764 763
      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
765 764
      ++n;
766 765
    }
767 766
    check(n == num, "Wrong number");
768 767

	
769 768
  }
770 769
  return 0;
771 770
}
0 comments (0 inline)