19 typedef typename std::vector<T*>::iterator it_t;
20 while(!a_vec.empty()) {
21 it_t it = a_vec.begin();
32 typedef typename std::vector<T*>::iterator it_t;
33 while(!a_vec.empty()) {
34 it_t it = a_vec.end();
42 #ifdef TOOLS_DEPRECATED
43 template <
class T>
inline void clear(std::vector<T*>& a_vec){safe_clear<T>(a_vec);}
48 typedef typename std::vector<T*>::iterator it_t;
49 for(it_t it = a_vec.begin();it!=a_vec.end();++it)
delete *it;
54 inline void copy(std::vector<T*>& a_to,
const std::vector<T*>& a_from){
56 typedef typename std::vector<T*>::const_iterator it_t;
57 for(it_t it = a_from.begin();it!=a_from.end();++it) {
58 a_to.push_back((*it)->copy());
63 inline void vcopy(std::vector<T*>& a_to,
const std::vector<T*>& a_from) {
return copy<T>(a_to,a_from);}
66 inline void append(std::vector<T>& a_vec,
const std::vector<T>& a_from) {
67 typedef typename std::vector<T>::size_type sz_t;
68 sz_t number = a_from.size();
69 sz_t offset = a_vec.size();
70 a_vec.resize(offset+number);
71 for(sz_t index=0;index<number;index++,offset++) {
72 a_vec[offset] = a_from[index];
77 inline void append(std::vector<T>& a_vec,
typename std::vector<T>::size_type a_num,
const T* a_from) {
78 typedef typename std::vector<T>::size_type sz_t;
79 sz_t vsize = a_vec.size();
80 a_vec.resize(vsize+a_num);
82 for(sz_t index=0;index<a_num;index++,offset++) {
83 a_vec[offset] = a_from[index];
88 inline void removep(std::vector<T*>& a_vec,
const T* a_elem) {
89 typedef typename std::vector<T*>::iterator it_t;
90 for(it_t it=a_vec.begin();it!=a_vec.end();) {
100 inline bool is_inp(
const std::vector<T*>& a_vec,
const T* a_item){
101 typedef typename std::vector<T*>::const_iterator it_t;
102 for(it_t it=a_vec.begin();it!=a_vec.end();++it) {
103 if(*it==a_item)
return true;
113 typedef typename std::vector<T>::const_iterator it_t;
114 for(it_t it=a_vec.begin();it!=a_vec.end();++it) {
if(*it==a_v)
return;}
115 a_vec.push_back(a_v);
119 inline bool remove(std::vector<T>& a_vals,
const T& a_elem){
120 bool found_some =
false;
132 typedef typename std::vector<T>::iterator it_t;
133 for(it_t it=a_vals.begin();it!=a_vals.end();++it) {
145 inline void vfilter(std::vector<T>& a_vals,
bool(*a_filter_func)(
const T& a_elem)){
147 typedef typename std::vector<T>::iterator it_t;
148 for(it_t it=a_vals.begin();it!=a_vals.end();++it) {
149 if(a_filter_func(*it)) vs.push_back(*it);
155 inline void unique(std::vector<T>& a_vec) {
156 typedef typename std::vector<T>::iterator it_t;
158 for(it=a_vec.begin();it!=a_vec.end();++it) {
160 for(;it2!=a_vec.end();) {
162 it2 = a_vec.erase(it2);
171 inline bool is_in(
const std::vector<T>& a_vec,
const T& a_item){
172 typedef typename std::vector<T>::const_iterator it_t;
174 for(it=a_vec.begin();it!=a_vec.end();++it) {
175 if(*it==a_item)
return true;
181 inline bool item_index(
const std::vector<T>& a_vec,
const T& a_item,
unsigned int& a_index){
183 typedef typename std::vector<T>::const_iterator it_t;
185 for(it=a_vec.begin();it!=a_vec.end();++it,a_index++) {
186 if(*it==a_item)
return true;
193 inline bool belong(
const std::vector<T>& a_vec,
const T& a_item){
194 typedef typename std::vector<T>::const_iterator it_t;
196 for(it=a_vec.begin();it!=a_vec.end();++it) {
197 if(*it==a_item)
return true;
203 inline bool minimum(
const std::vector<T>& a_vec,T& a_value) {
204 if(a_vec.empty()) {a_value = T();
return false;}
206 typedef typename std::vector<T>::const_iterator it_t;
207 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
208 a_value = (a_value<(*it)?a_value:(*it));
214 inline bool maximum(
const std::vector<T>& a_vec,T& a_value) {
215 if(a_vec.empty()) {a_value = T();
return false;}
217 typedef typename std::vector<T>::const_iterator it_t;
218 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
219 a_value = (a_value>(*it)?a_value:(*it));
225 inline T
sum(
const std::vector<T>& a_vec) {
227 typedef typename std::vector<T>::const_iterator it_t;
228 for(it_t it = a_vec.begin();it!=a_vec.end();++it)
sum += *it;
233 inline void filter(std::vector<T>& a_vec,
unsigned int a_min,
unsigned int a_max){
234 unsigned int imx = a_vec.size()-1;
235 unsigned int mx = a_max<imx?a_max:imx;
237 for(
unsigned int index=a_min;index<=
mx;index++) {
238 a_vec[i] = a_vec[index];i++;
244 inline void steps(std::vector<T>& a_vec,
unsigned int a_number){
245 a_vec.resize(a_number);
246 for(
unsigned int index=0;index<a_number;index++) a_vec[index] = T(index);
250 inline bool add(std::vector<T>& a_vec,
const std::vector<T>& a_v){
251 if(a_vec.size()!=a_v.size())
return false;
252 typedef typename std::vector<T>::iterator it_t;
253 typedef typename std::vector<T>::const_iterator cit_t;
254 it_t it = a_vec.begin();
255 cit_t vit = a_v.begin();
256 for(;it!=a_vec.end();++it,++vit) *it += *vit;
261 inline bool vequ(
const std::vector<T>& a_vec,
const std::vector<T>& a_v){
262 if(a_vec.size()!=a_v.size())
return false;
263 typedef typename std::vector<T>::const_iterator it_t;
264 typedef typename std::vector<T>::const_iterator cit_t;
265 it_t it = a_vec.begin();
266 cit_t vit = a_v.begin();
268 for(;it!=a_vec.end();++it,++vit
280 inline bool vadd(std::vector<T>& a_vec,
const std::vector<T>& a_v) {
return add<T>(a_vec,a_v);}
283 inline bool sub(std::vector<T>& a_vec,
const std::vector<T>& a_v){
284 if(a_vec.size()!=a_v.size())
return false;
285 typedef typename std::vector<T>::iterator it_t;
286 typedef typename std::vector<T>::const_iterator cit_t;
287 it_t it = a_vec.begin();
288 cit_t vit = a_v.begin();
289 for(;it!=a_vec.end();++it,++vit) *it -= *vit;
294 inline bool div(std::vector<T>& a_vec,
const std::vector<T>& a_v){
295 if(a_vec.size()!=a_v.size())
return false;
296 typedef typename std::vector<T>::iterator it_t;
297 typedef typename std::vector<T>::const_iterator cit_t;
298 it_t it = a_vec.begin();
299 cit_t vit = a_v.begin();
301 for(;it!=a_vec.end();++it,++vit) {
312 inline void add(std::vector<T>& a_vec,
const T& a_v){
313 typedef typename std::vector<T>::iterator it_t;
314 for(it_t it=a_vec.begin();it!=a_vec.end();++it) *it += a_v;
318 inline void sub(std::vector<T>& a_vec,
const T& a_v){
319 typedef typename std::vector<T>::iterator it_t;
320 for(it_t it=a_vec.begin();it!=a_vec.end();++it) *it -= a_v;
324 inline void mul(std::vector<T>& a_vec,
const T& a_v){
325 typedef typename std::vector<T>::iterator it_t;
326 for(it_t it=a_vec.begin();it!=a_vec.end();++it) *it *= a_v;
329 inline bool vmul(std::vector<T>& a_vec,
const std::vector<T>& a_v) {
return vmul<T>(a_vec,a_v);}
332 inline void div(std::vector<T>& a_vec,
const T& a_v){
333 typedef typename std::vector<T>::iterator it_t;
334 for(it_t it=a_vec.begin();it!=a_vec.end();++it) *it /= a_v;
349 template <
class FROM,
class TO>
350 inline void convert(
const std::vector<FROM>& a_from,std::vector<TO>& a_to) {
351 typedef typename std::vector<FROM>::const_iterator const_it_t;
352 typedef typename std::vector<TO>::iterator it_t;
353 a_to.resize(a_from.size());
354 const_it_t ait = a_from.begin();
355 it_t toit = a_to.begin();
356 for(;ait!=a_from.end();++ait,++toit) {*toit = (TO)*ait;}
360 inline bool min_max(
const std::vector<T>& a_vec,T& a_min,T& a_max) {
361 if(a_vec.empty()) {a_min=T();a_max=T();
return false;}
362 a_min = *(a_vec.begin());
364 typedef typename std::vector<T>::const_iterator it_t;
365 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
366 a_min = *it<a_min?*it:a_min;
367 a_max = *it>a_max?*it:a_max;
376 inline bool mean_rms(
const std::vector<T>& a_vec,T& a_mean,T& a_rms,T(*a_sqrt)(T),T(*a_fabs)(T)) {
377 if(a_vec.empty()) {a_mean=T();a_rms=T();
return false;}
380 typedef typename std::vector<T>::const_iterator it_t;
381 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
385 a_mean = S/T(a_vec.size());
386 a_rms = a_sqrt(a_fabs(S2/T(a_vec.size()) - a_mean * a_mean));
391 inline bool min_max_mean_rms(
const std::vector<T>& a_vec,T& a_min,T& a_max,T& a_mean,T& a_rms,
392 T(*a_sqrt)(T),T(*a_fabs)(T)) {
393 if(a_vec.empty()) {a_min=T();a_max=T();a_mean=T();a_rms=T();
return false;}
394 a_min = *(a_vec.begin());
398 typedef typename std::vector<T>::const_iterator it_t;
399 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
400 a_min = *it<a_min?*it:a_min;
401 a_max = *it>a_max?*it:a_max;
405 a_mean = S/T(a_vec.size());
406 a_rms = a_sqrt(a_fabs(S2/T(a_vec.size()) - a_mean * a_mean));
414 inline bool mean_rms(
const std::vector<T>& a_vec,T& a_mean,T& a_rms,T(*a_sqrt)(
const T&),T(*a_fabs)(
const T&)) {
415 if(a_vec.empty()) {a_mean=T();a_rms=T();
return false;}
418 typedef typename std::vector<T>::const_iterator it_t;
419 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
423 a_mean = S/T(a_vec.size());
424 a_rms = a_sqrt(a_fabs(S2/T(a_vec.size()) - a_mean * a_mean));
429 inline bool min_max_mean_rms(
const std::vector<T>& a_vec,T& a_min,T& a_max,T& a_mean,T& a_rms,
430 T(*a_sqrt)(
const T&),T(*a_fabs)(
const T&)) {
431 if(a_vec.empty()) {a_min=T();a_max=T();a_mean=T();a_rms=T();
return false;}
432 a_min = *(a_vec.begin());
436 typedef typename std::vector<T>::const_iterator it_t;
437 for(it_t it = a_vec.begin();it!=a_vec.end();++it) {
438 a_min = *it<a_min?*it:a_min;
439 a_max = *it>a_max?*it:a_max;
443 a_mean = S/T(a_vec.size());
444 a_rms = a_sqrt(a_fabs(S2/T(a_vec.size()) - a_mean * a_mean));
459 inline void dump(
const std::vector<T>& a_vec,std::ostream& a_out){
460 typedef typename std::vector<T>::const_iterator it_t;
462 for(it=a_vec.begin();it!=a_vec.end();++it) {
463 a_out << *it << std::endl;