00001 #ifndef SGE_LINEAR_MAP_HPP_INCLUDED
00002 #define SGE_LINEAR_MAP_HPP_INCLUDED
00003
00004
00005 #include <functional>
00006
00007 #include <memory>
00008
00009 #include <list>
00010
00011 #include <utility>
00012
00013 namespace sge
00014 {
00015 template<
00016 class Key,
00017 class T,
00018 class Compare = std::less<Key>,
00019 class Allocator = std::allocator<std::pair<const Key,T> > >
00020 class linear_map
00021 {
00022 public:
00023 typedef Key key_type;
00024 typedef T mapped_type;
00025 typedef std::pair<const Key,T> value_type;
00026 typedef Compare key_compare;
00027 typedef Allocator allocator_type;
00028 typedef typename Allocator::reference reference;
00029 typedef typename Allocator::const_reference const_reference;
00030 typedef std::list<value_type> container_type;
00031 typedef typename container_type::iterator iterator;
00032 typedef typename container_type::const_iterator const_iterator;
00033 typedef typename container_type::size_type size_type;
00034 typedef typename container_type::difference_type difference_type;
00035 typedef typename Allocator::pointer pointer;
00036 typedef typename Allocator::const_pointer const_pointer;
00037
00038 typedef typename container_type::reverse_iterator reverse_iterator;
00039 typedef typename container_type::const_reverse_iterator const_reverse_iterator;
00040
00041 class value_compare
00042 : public std::binary_function<value_type,value_type,bool>
00043 {
00044 friend class linear_map;
00045 private:
00046 Compare comp;
00047 value_compare(Compare);
00048 public:
00049 bool operator()(value_type const &x,value_type const &y) const;
00050 };
00051
00052 explicit linear_map(Compare const & = Compare(),Allocator const & = Allocator());
00053 template<class InputIterator>
00054 linear_map(InputIterator begin,InputIterator last,Compare const & = Compare(),Allocator const & = Allocator());
00055 linear_map(linear_map const &);
00056
00057 linear_map &operator=(linear_map const &);
00058
00059 iterator begin();
00060 iterator end();
00061 const_iterator begin() const;
00062 const_iterator end() const;
00063 reverse_iterator rbegin();
00064 reverse_iterator rend();
00065 const_reverse_iterator rbegin() const;
00066 const_reverse_iterator rend() const;
00067
00068 bool empty() const;
00069 size_type size() const;
00070 size_type max_size() const;
00071 T& operator[](key_type const &);
00072
00073 std::pair<iterator,bool> insert(value_type const &);
00074 iterator insert(iterator position,value_type const &);
00075 template<class InputIterator>
00076 void insert(InputIterator begin,InputIterator last);
00077
00078 void erase(iterator position);
00079 size_type erase(key_type const &);
00080 void erase(iterator begin,iterator last);
00081 void swap(linear_map &);
00082 void clear();
00083
00084 key_compare key_comp() const;
00085 value_compare value_comp() const;
00086
00087 iterator find(key_type const &);
00088 const_iterator find(key_type const &) const;
00089 size_type count(key_type const &) const;
00090
00091 iterator lower_bound(key_type const &);
00092 const_iterator lower_bound(key_type const &) const;
00093 iterator upper_bound(key_type const &);
00094 const_iterator upper_bound(key_type const &) const;
00095
00096 std::pair<iterator,iterator> equal_range(key_type const &);
00097 std::pair<const_iterator,const_iterator> equal_range(key_type const &) const;
00098 private:
00099 value_compare comp_;
00100 container_type container_;
00101 };
00102 }
00103
00104 template<class Key,class T,class Compare,class Allocator>
00105 bool operator==(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00106
00107 template<class Key,class T,class Compare,class Allocator>
00108 bool operator!=(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00109
00110 template<class Key,class T,class Compare,class Allocator>
00111 bool operator<(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00112
00113 template<class Key,class T,class Compare,class Allocator>
00114 bool operator>(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00115
00116 template<class Key,class T,class Compare,class Allocator>
00117 bool operator>=(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00118
00119 template<class Key,class T,class Compare,class Allocator>
00120 bool operator<=(sge::linear_map<Key,T,Compare,Allocator> const &,sge::linear_map<Key,T,Compare,Allocator> const &);
00121
00122 template<class Key,class T,class Compare,class Allocator>
00123 void swap(sge::linear_map<Key,T,Compare,Allocator> &,sge::linear_map<Key,T,Compare,Allocator> &);
00124
00125 #endif