00001
00002 #ifndef __REFLIST__
00003 #define __REFLIST__
00004
00005 #include <list>
00006 #include <base/ref>
00007
00008 namespace base {
00009
00010 template <class _Tp, class _Alloc = std::allocator<_Tp> >
00011 class reflist
00012 {
00013 protected:
00014 typedef std::list< ref<_Tp>, _Alloc > reflist_type;
00015 typedef std::list< ref<const _Tp>, _Alloc > reflist_const_type;
00016 typedef const std::list< ref<_Tp>, _Alloc > const_reflist_type;
00017 typedef const std::list< ref<const _Tp>, _Alloc > const_reflist_const_type;
00018 reflist_type l;
00019 reflist_const_type& l_const() { return reinterpret_cast<reflist_const_type&>(l); }
00020 const_reflist_type& const_l() const { return reinterpret_cast<const_reflist_type&>(l); }
00021 const_reflist_const_type& const_l_const() const { return reinterpret_cast<const_reflist_const_type&>(l); }
00022
00023 public:
00024 typedef ref<_Tp> value_type;
00025 typedef value_type* pointer;
00026 typedef const value_type* const_pointer;
00027 typedef value_type& reference;
00028 typedef const value_type& const_reference;
00029 typedef size_t size_type;
00030 typedef ptrdiff_t difference_type;
00031 typedef _Alloc allocator_type;
00032
00033 typedef typename reflist_type::iterator iterator;
00034 typedef typename reflist_const_type::iterator iterator_const;
00035 typedef typename const_reflist_type::const_iterator const_iterator;
00036 typedef typename const_reflist_const_type::const_iterator const_iterator_const;
00037
00038 typedef std::reverse_iterator<iterator> reverse_iterator;
00039 typedef std::reverse_iterator<iterator_const> reverse_iterator_const;
00040 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00041 typedef std::reverse_iterator<const_iterator_const> const_reverse_iterator_const;
00042
00043
00044 public:
00045 iterator begin() { return l.begin(); }
00046 const_iterator begin() const { return const_l().begin(); }
00047 const_iterator_const const_begin() const { return const_l_const().begin(); }
00048
00049 iterator end() { return l.end(); }
00050 const_iterator end() const { return const_l().end(); }
00051 const_iterator_const const_end() const { return const_l_const().end(); }
00052
00053 reverse_iterator rbegin()
00054 { return reverse_iterator(end()); }
00055 const_reverse_iterator rbegin() const
00056 { return const_reverse_iterator(end()); }
00057 const_reverse_iterator_const const_rbegin() const
00058 { return const_reverse_iterator(const_end()); }
00059
00060 reverse_iterator rend()
00061 { return reverse_iterator(begin()); }
00062 const_reverse_iterator rend() const
00063 { return const_reverse_iterator(begin()); }
00064 const_reverse_iterator_const const_rend() const
00065 { return const_reverse_iterator(const_begin()); }
00066
00067 bool empty() const { return l.empty(); }
00068 size_type size() const {
00069 return l.size();
00070 }
00071 size_type max_size() const { return l.max_size(); }
00072
00073 reference front() { return *begin(); }
00074 const_reference front() const { return *begin(); }
00075 reference back() { return *(--end()); }
00076 const_reference back() const { return *(--end()); }
00077
00078 void swap(reflist<_Tp, _Alloc>& __x) { l.swap(__x); }
00079
00080 iterator insert(iterator __position, ref<_Tp> __x) {
00081 return l.insert(__position,__x);
00082 }
00083 iterator insert(iterator __position) { return insert(__position, ref<_Tp>()); }
00084
00085
00086 template <class _InputIterator>
00087 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
00088 l.insert(__pos, __first, __list);
00089 }
00090
00091 void insert(iterator __pos, size_type __n, ref<_Tp> __x)
00092 { l.insert(__pos, __n, __x); }
00093
00094 void push_front(ref<_Tp> __x) { insert(begin(), __x); }
00095 void push_front() {insert(begin());}
00096 void push_back(ref<_Tp> __x) { insert(end(), __x); }
00097 void push_back() {insert(end());}
00098
00099 iterator erase(iterator __position) {
00100 return l.erase(__position);
00101 }
00102 iterator erase(iterator __first, iterator __last) { return l.erase(__first, __last); }
00103 void clear() { l.clear(); }
00104
00105 void resize(size_type __new_size, ref<const _Tp> __x) { l_const().resize(__new_size, __x); }
00106 void resize(size_type __new_size, ref<_Tp> __x) { l.resize(__new_size, __x); }
00107 void resize(size_type __new_size) { resize(__new_size, ref<_Tp>()); }
00108
00109 void pop_front() { erase(begin()); }
00110 void pop_back() {
00111 l.pop_back();
00112 }
00113
00114 reflist() {}
00115 reflist(size_type __n, ref<_Tp> __value)
00116 : l(__n, __value) {}
00117
00118 explicit reflist(size_type __n)
00119 : l(__n) {}
00120
00121
00122 template <class _InputIterator>
00123 reflist(_InputIterator __first, _InputIterator __last)
00124 : l(__first, __last) {}
00125
00126 reflist(const reflist<_Tp, _Alloc>& __x) : l(__x.l) {}
00127
00128 ~reflist() { }
00129
00130 reflist<_Tp, _Alloc>& operator=(const reflist<_Tp, _Alloc>& __x) { l = __x.l; return *this; }
00131
00132 public:
00133
00134
00135
00136
00137
00138 void assign(size_type __n, ref<_Tp> __val) { l.assign(__n, __val); }
00139
00140
00141 template <class _InputIterator>
00142 void assign(_InputIterator __first, _InputIterator __last) {
00143 l.assign(__first, __last);
00144 }
00145
00146
00147 void splice(iterator __position, reflist& __x) {
00148 l.splice(__position, __x);
00149 }
00150 void splice(iterator __position, reflist& __x, iterator __i) {
00151 l.splice(__position, __x, __i);
00152 }
00153 void splice(iterator __position, reflist& __x, iterator __first, iterator __last) {
00154 l.splice(__position, __x, __first, __last);
00155 }
00156
00157 void remove(ref<const _Tp> __value) { l_const().remove(__value); }
00158 void unique() { l.unique(); }
00159 void merge(reflist& __x) { l.merge(__x); }
00160 void reverse() { l.reverse(); }
00161 void sort() { l.sort(); }
00162
00163 template <class _Predicate> void remove_if(_Predicate p) { l.remove_if(p); }
00164 template <class _BinaryPredicate> void unique(_BinaryPredicate bp) { l.unique(bp); }
00165 template <class _StrictWeakOrdering> void merge(reflist& __x, _StrictWeakOrdering swo) { l.merge(__x, swo); }
00166 template <class _StrictWeakOrdering> void sort(_StrictWeakOrdering swo) { l.sort(swo); }
00167
00168 };
00169
00170
00171 }
00172
00173 #endif
00174
00175