#ifndef VP_INTEGER_MAP_H_14112001 #define VP_INTEGER_MAP_H_14112001 #include #include #include #include namespace boost { /** Implements [0, max_int] -> T mapping. What is implemented is conceptually what is said. It is mapping from all the integers to T, where mapped value is initially T(). It does not conforms to any of SGI STL concepts. */ template > class integer_map { public: // All but one of Container typedef are not defined. typedef typename std::vector::size_type size_type; // Associative Container has not much do offer, too. typedef typename std::vector::size_type key_type; // Pair Associative Container -- likewise. typedef T data_type; data_type& operator[](key_type k); const data_type& operator[](key_type k) const; void swap(integer_map& other); private: mutable std::vector data; }; template class property_traits< integer_map > { typedef T value_type; // Is it OK? Seems like property_map concept don't support // const/nonconst []. typedef const T& reference; typedef typename integer_map::key_type key_type; typedef lvalue_property_map_tag category; }; template integer_map::data_type& integer_map::operator[](key_type k) { if (k >= data.size()) data.resize(std::max(data.size()*2, k+1)); return data[k]; } template const integer_map::data_type& integer_map::operator[](key_type k) const { if (k >= data.size()) data.resize(std::max(data.size()*2, k+1)); return data[k]; } template void integer_map::swap(integer_map& other) { this->data.swap(other.data); } template typename property_traits< integer_map >::reference get(const integer_map& pmap, typename integer_map::key_type key) { return pmap[key]; } template void put(integer_map& pmap, typename integer_map::key_type key, const typename integer_map::data_type& value) { pmap[key] = value; } } #endif