58 lines
1.2 KiB
Plaintext
58 lines
1.2 KiB
Plaintext
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
|
// See the file tools.license for terms.
|
|
|
|
#ifndef tools_vfind
|
|
#define tools_vfind
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
namespace tools {
|
|
|
|
template <class T>
|
|
inline T* find_named(const std::vector<T*>& a_vec,const std::string& a_name) {
|
|
typedef typename std::vector<T*>::const_iterator it_t;
|
|
it_t it;
|
|
for(it=a_vec.begin();it!=a_vec.end();++it) {
|
|
if((*it)->name()==a_name) return *it;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
template <class T>
|
|
inline const T* find_named_(const std::vector<T>& a_vec,const std::string& a_name) {
|
|
typedef typename std::vector<T>::const_iterator it_t;
|
|
it_t it;
|
|
for(it=a_vec.begin();it!=a_vec.end();++it) {
|
|
if((*it).name()==a_name) return &(*it);
|
|
}
|
|
return 0;
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
#include "touplow"
|
|
|
|
namespace tools {
|
|
|
|
template <class T>
|
|
inline T* find_named_case_insensitive(const std::vector<T*>& a_vec,const std::string& a_name) {
|
|
std::string low_a_name = a_name;
|
|
tolowercase(low_a_name);
|
|
std::string low_name;
|
|
typedef typename std::vector<T*>::const_iterator it_t;
|
|
it_t it;
|
|
for(it=a_vec.begin();it!=a_vec.end();++it) {
|
|
low_name = (*it)->name();
|
|
tolowercase(low_name);
|
|
if(low_name==low_a_name) return *it;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|