00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00036
00037
00038 #ifndef _DEQUE2_H_
00039 #define _DEQUE2_H_
00040
00041 #include "Mbo.h"
00042
00043 #include <algorithm>
00044 #include <deque>
00045
00046 namespace std
00047 {
00048
00064 template <class _Ty, class _Alloc = allocator<_Ty> >
00065 class deque2 : public deque<_Ty, _Alloc>
00066 {
00067 public:
00068 typedef deque2<_Ty, _Alloc> _Myt;
00069 typedef deque<_Ty, _Alloc> _Mybase;
00075 virtual void limit(
00076 _IN size_type _Limit
00077 )
00078 {
00079 if (size() > _Limit)
00080 {
00081 resize(_Limit);
00082 }
00083 }
00084
00093 pair<size_type, bool> position(
00094 _IN const _Ty &_Val
00095 ) const
00096 {
00097 size_type _Index = 0;
00098 for (const_iterator iter = begin(); iter != end(); ++iter, ++_Index)
00099 {
00100 if (*iter == _Val)
00101 {
00102 return pair<size_type, bool>(_Index, true);
00103 }
00104 }
00105 return pair<size_type,bool>(static_cast<size_type>(-1), false);
00106 }
00107
00114 bool contains(
00115 _IN const _Ty &_Val
00116 ) const
00117 {
00118 return std::find(begin(), end(), _Val) != end();
00119 }
00120
00128 bool contains_no(
00129 _IN const _Ty &_Val
00130 ) const
00131 {
00132 return std::find(begin(), end(), _Val) == end();
00133 }
00134
00141 virtual bool add_if_new(
00142 _IN const _Ty &_Val
00143 )
00144 {
00145 if (!contains(_Val))
00146 {
00147 push_back(_Val);
00148 return true;
00149 }
00150 return false;
00151 }
00152
00157 operator bool()
00158 {
00159 return size() > 0;
00160 }
00161
00166 void sort()
00167 {
00168 if (size()>1)
00169 {
00170 std::sort(begin(), end());
00171 }
00172 }
00173
00180 static _Myt __cdecl dyn_create(
00181 _IN size_type _Count,
00182 ...
00183 )
00184 {
00185 _Myt _Deque;
00186 va_list _Args;
00187
00188 va_start(_Args, _Count);
00189 while(_Count--)
00190 {
00191 _Deque.push_back(va_arg(_Args, const _Ty));
00192 }
00193 va_end(_Args);
00194 return _Deque;
00195 }
00196 };
00197
00213 template < class _Ty_a, class _Alloc_a
00214 , class _Ty_b, class _Alloc_b
00215 >
00216 deque2<_Ty_a, _Alloc_a> & operator += (
00217 _IN deque2<_Ty_a, _Alloc_a> & container,
00218 _IN const deque<_Ty_b, _Alloc_b> & values
00219 )
00220 {
00221
00222 for (deque2<_Ty_b, _Alloc_b>::const_iterator it = values.begin(); it != values.end(); ++it)
00223 {
00224 container.push_back((_Ty_a)*it);
00225 }
00226 return container;
00227 };
00228
00244 template < class _Ty_a, class _Alloc_a
00245 , class _Ty_b, class _Alloc_b
00246 >
00247 deque2<_Ty_a, _Alloc_a> & operator << (
00248 _IN deque2<_Ty_a, _Alloc_a> & container,
00249 _IN const deque<_Ty_b, _Alloc_b> & values
00250 )
00251 {
00252 container.clear();
00253 container += values;
00254 return container;
00255 };
00256
00257 };
00258
00259 #endif //_DEQUE2_H_