library of assembled shared sources

http://lass.cocamware.com

vector_map.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 /** @class lass::stde::vector_map
00044  *  @brief a map-like container built on a sorted vector (write-rarely, read-many)
00045  *  @author Bram de Greve [Bramz]
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 // EOF

Generated on Mon Nov 10 14:22:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo