00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef LASS_GUARDIAN_OF_INCLUSION_STDE_LINEAR_MAP_H
00049 #define LASS_GUARDIAN_OF_INCLUSION_STDE_LINEAR_MAP_H
00050
00051 #include "stde_common.h"
00052
00053 namespace lass
00054 {
00055 namespace stde
00056 {
00057
00058 template
00059 <
00060 typename Key,
00061 typename T,
00062 typename Compare = std::less<Key>,
00063 typename Allocator = std::allocator< std::pair<const Key, T> >
00064 >
00065 class vector_map
00066 {
00067 public:
00068
00069 typedef Key key_type;
00070 typedef T mapped_type;
00071 typedef std::pair<const Key, T> value_type;
00072 typedef Compare key_compare;
00073
00074 typedef typename Allocator::template rebind<value_type>::other allocator_type;
00075 typedef typename Allocator::reference reference;
00076 typedef typename Allocator::const_reference const_reference;
00077 typedef typename Allocator::pointer pointer;
00078 typedef typename Allocator::const_pointer const_pointer;
00079 typedef typename Allocator::size_type size_type;
00080 typedef typename Allocator::difference_type difference_type;
00081
00082 typedef std::vector<value_type, Allocator> vector_type;
00083 typedef typename vector_type::iterator iterator;
00084 typedef typename vector_type::const_iterator const_iterator;
00085 typedef typename vector_type::reverse_iterator reverse_iterator;
00086 typedef typename vector_type::const_reverse_iterator const_reverse_iterator;
00087
00088 class value_compare: public std::binary_function<value_type, value_type, bool>
00089 {
00090 public:
00091 bool operator()(const value_type& a, const value_type& b) const
00092 {
00093 return key_comp_(a.first, b.first);
00094 }
00095 private:
00096 friend class vector_map;
00097 value_compare(const key_compare& key_comp): key_comp_(key_comp) {}
00098 key_compare key_comp_;
00099 };
00100
00101 explicit vector_map(const key_compare& key_comp, const allocator_type& allocator = Allocator());
00102 template <typename InputIterator>
00103 vector_map(InputIterator first, InputIterator last,
00104 const key_compare& key_comp, const allocator_type& allocator = Allocator());
00105 vector_map(const vector_map<Key, T, Compare, Allocator>& other);
00106 ~vector_map();
00107
00108 vector_map<Key, T, Compare, Allocator>& operator=(
00109 const vector_map<Key, T, Compare, Allocator>& other);
00110
00111 iterator begin();
00112 const_iterator begin() const;
00113 iterator end();
00114 const_iterator end() const;
00115 reverse_iterator rbegin();
00116 const_reverse_iterator rbegin() const;
00117 reverse_iterator rend();
00118 const_reverse_iterator rend() const;
00119
00120 bool empty() const;
00121 size_type size() const;
00122 size_type max_size() const;
00123
00124 mapped_type& operator[](const key_type& x);
00125
00126 std::pair<iterator, pool> insert(const value_type& x);
00127 iterator insert(iterator position, const value_type& x);
00128 template <typename InputIterator> void insert(InputIterator first, InputIterator last);
00129
00130 void erase(iterator position);
00131 size_type erase(const key_type& x);
00132 void erase(iterator first, iterator last);
00133 void swap(vector_map<Key, T, Compare, Allocator>& other);
00134 void clear();
00135
00136 key_compare key_comp() const;
00137 value_compare value_comp() const;
00138
00139 iterator find(const key_type& x);
00140 const_iterator find(const key_type& x) const;
00141 size_type count(const key_type& x) const;
00142
00143 iterator lower_bound(const key_type& x);
00144 const_iterator lower_bound(const key_type& x) const;
00145 iterator upper_bound(const key_type& x);
00146 const_iterator upper_bound(const key_type& x) const;
00147
00148 std::pair<iterator, iterator> equal_range(const key_type& x);
00149 std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
00150
00151 private:
00152
00153 vector_type data_;
00154 key_compare key_comp_;
00155 };
00156
00157 template <typename Key, typename T, typename Compare, typename Allocator>
00158 bool operator==(const vector_map<Key, T, Compare, Allocator>& a,
00159 const vector_map<Key, T, Compare, Allocator>& b);
00160
00161 template <typename Key, typename T, typename Compare, typename Allocator>
00162 bool operator<(const vector_map<Key, T, Compare, Allocator>& a,
00163 const vector_map<Key, T, Compare, Allocator>& b);
00164
00165 template <typename Key, typename T, typename Compare, typename Allocator>
00166 bool operator!=(const vector_map<Key, T, Compare, Allocator>& a,
00167 const vector_map<Key, T, Compare, Allocator>& b);
00168
00169 template <typename Key, typename T, typename Compare, typename Allocator>
00170 bool operator>(const vector_map<Key, T, Compare, Allocator>& a,
00171 const vector_map<Key, T, Compare, Allocator>& b);
00172
00173 template <typename Key, typename T, typename Compare, typename Allocator>
00174 bool operator>=(const vector_map<Key, T, Compare, Allocator>& a,
00175 const vector_map<Key, T, Compare, Allocator>& b);
00176
00177 template <typename Key, typename T, typename Compare, typename Allocator>
00178 bool operator<=(const vector_map<Key, T, Compare, Allocator>& a,
00179 const vector_map<Key, T, Compare, Allocator>& b);
00180
00181 template <typename Key, typename T, typename Compare, typename Allocator, typename Char, typename Traits>
00182 std::basic_ostream<Char, Traits>&
00183 operator<<(std::basic_ostream<Char, Traits>& o_stream,
00184 const vector_map<Key, T, Compare, Allocator>& container);
00185 template <typename Key, typename T, typename Compare, typename Allocator, typename Char, typename Traits>
00186 std::basic_istream<Char, Traits>&
00187 operator>>(std::basic_istream<Char, Traits>& i_stream,
00188 vector_map<Key, T, Compare, Allocator>& container);
00189
00190 }
00191 }
00192
00193 namespace std
00194 {
00195
00196 template <typename Key, typename T, typename Compare, typename Allocator>
00197 void swap(vector_map<Key, T, Compare, Allocator>& a, vector_map<Key, T, Compare, Allocator>& b);
00198
00199 }
00200
00201 #include "vector_map.inl"
00202
00203 #endif
00204
00205