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 _VECOTR2_H_
00039 #define _VECOTR2_H_
00040
00041 #include "Mbo.h"
00042
00043 #include <algorithm>
00044 #include <vector>
00045
00046 namespace std
00047 {
00048
00072 template < class _Ty
00073 , class _Alloc = allocator<_Ty>
00074 >
00075 class vector2 : public vector<_Ty, _Alloc>
00076 {
00077 public:
00078 typedef vector2<_Ty, _Alloc> _Myt;
00079 typedef vector<_Ty, _Alloc> _Mybase;
00085 virtual void limit(
00086 _IN size_type _Limit
00087 )
00088 {
00089 if (size() > _Limit)
00090 {
00091 resize(_Limit);
00092 }
00093 }
00094
00103 pair<size_type, bool> position(
00104 _IN const _Ty &_Val
00105 ) const
00106 {
00107 size_type _Index = 0;
00108 for (const_iterator iter = begin(); iter != end(); ++iter, ++_Index)
00109 {
00110 if (*iter == _Val)
00111 {
00112 return pair<size_type, bool>(_Index, true);
00113 }
00114 }
00115 return pair<size_type, bool>(-1, false);
00116 }
00117
00124 bool contains(
00125 _IN const _Ty &_Val
00126 ) const
00127 {
00128 return std::find(begin(), end(), _Val) != end();
00129 }
00130
00138 bool contains_no(
00139 _IN const _Ty &_Val
00140 ) const
00141 {
00142 return std::find(begin(), end(), _Val) == end();
00143 }
00144
00151 virtual bool add_if_new(
00152 _IN const _Ty &_Val
00153 )
00154 {
00155 if (!contains(_Val))
00156 {
00157 push_back(_Val);
00158 return true;
00159 }
00160 return false;
00161 }
00162
00167 operator bool()
00168 {
00169 return size() > 0;
00170 }
00171
00174 void sort()
00175 {
00176 if (size() > 1)
00177 {
00178 std::sort(begin(), end());
00179 }
00180 }
00181
00187 static _Myt __cdecl dyn_create(
00188 _IN size_type _Count,
00189 ...
00190 )
00191 {
00192 _Myt _Vector;
00193 va_list _Args;
00194
00195 va_start(_Args, _Count);
00196 while(_Count--)
00197 {
00198 _Vector.push_back(va_arg(_Args, const _Ty));
00199 }
00200 va_end(_Args);
00201 return _Vector;
00202 }
00203 };
00204
00220 template < class _Ty_a, class _Alloc_a
00221 , class _Ty_b, class _Alloc_b
00222 >
00223 vector2<_Ty_a, _Alloc_a> & operator += (
00224 _IN vector2<_Ty_a, _Alloc_a> & container,
00225 _IN const vector<_Ty_b, _Alloc_b> & values
00226 )
00227 {
00228
00229 for (vector<_Ty_b, _Alloc_b>::const_iterator it = values.begin(); it != values.end(); ++it)
00230 {
00231 container.push_back((_Ty_a)*it);
00232 }
00233 return container;
00234 };
00235
00251 template < class _Ty_a, class _Alloc_a
00252 , class _Ty_b, class _Alloc_b
00253 >
00254 vector2<_Ty_a, _Alloc_a> & operator << (
00255 _IN vector2<_Ty_a, _Alloc_a> & container,
00256 _IN const vector<_Ty_b, _Alloc_b> & values
00257 )
00258 {
00259 container.clear();
00260 container += values;
00261 return container;
00262 };
00263
00264 };
00265
00266 #endif //_VECTOR2_H_