1 #ifndef __FLASHMATCHBASE_PARSER_CXX__
2 #define __FLASHMATCHBASE_PARSER_CXX__
10 std::string res(value);
11 if(res.empty())
return res;
13 if(res.find(
"\"") == 0) res = res.substr(1);
14 if(res.empty())
return res;
16 if(res.rfind(
"\"") == (res.length()-1)) res = res.substr(0,res.length()-1);
21 {
return std::stof(value); }
24 {
return std::stod(value); }
27 {
return std::stoul(value); }
30 {
return std::stoul(value); }
33 {
return std::stoul(value); }
36 {
return std::stoi(value); }
39 {
return std::stoi(value); }
42 {
return std::stol(value); }
46 std::string tmp=
value;
48 if( value ==
"true" || value ==
"1" )
return true;
49 if( value ==
"false" || value ==
"0" )
return false;
50 std::cerr <<
"Invalid bool expression: " << tmp << std::endl;
51 throw std::exception();
58 std::vector<std::string> res;
59 if(value.find(
"[") != 0 || (value.rfind(
"]")+1) != value.size()) {
61 std::cerr <<
"Invalid vector expression: " << value << std::endl;
62 throw std::exception();
65 while((index+1) < value.size()) {
66 size_t next_index = value.find(
",",index);
67 if(next_index >= value.size())
break;
68 std::string cand = value.substr(index,next_index-index);
69 res.emplace_back(cand);
70 index = next_index + 1;
72 if( (index+1) < value.size() )
73 res.push_back(value.substr(index,value.size()-index-1));
76 if(
s.find(
"\"")==0)
s=
s.substr(1,
s.size()-1);
77 if(
s.rfind(
"\"")+1 ==
s.size())
s =
s.substr(0,
s.size()-1);
83 template<> std::vector< float > FromString< std::vector< float > > (
const std::string&
value )
85 auto str_v = FromString<std::vector<std::string> >(
value);
86 std::vector<float> res;
87 res.reserve(str_v.size());
88 for(
auto const& v : str_v)
93 template<> std::vector< double > FromString< std::vector< double > > (
const std::string&
value )
95 auto str_v = FromString<std::vector<std::string> >(
value);
96 std::vector<double> res;
97 res.reserve(str_v.size());
98 for(
auto const& v : str_v)
103 template<> std::vector< short > FromString< std::vector< short > > (
const std::string&
value )
105 auto str_v = FromString<std::vector<std::string> >(
value);
106 std::vector<short> res;
107 res.reserve(str_v.size());
108 for(
auto const& v : str_v)
113 template<> std::vector< int > FromString< std::vector< int > > (
const std::string&
value )
115 auto str_v = FromString<std::vector<std::string> >(
value);
116 std::vector<int> res;
117 res.reserve(str_v.size());
118 for(
auto const& v : str_v)
123 template<> std::vector< long > FromString< std::vector< long > > (
const std::string&
value )
125 auto str_v = FromString<std::vector<std::string> >(
value);
126 std::vector<long> res;
127 res.reserve(str_v.size());
128 for(
auto const& v : str_v)
133 template<> std::vector< unsigned short > FromString< std::vector< unsigned short > > (
const std::string&
value )
135 auto str_v = FromString<std::vector<std::string> >(
value);
136 std::vector<unsigned short> res;
137 res.reserve(str_v.size());
138 for(
auto const& v : str_v)
143 template<> std::vector< unsigned int > FromString< std::vector< unsigned int > > (
const std::string&
value )
145 auto str_v = FromString<std::vector<std::string> >(
value);
146 std::vector<unsigned int> res;
147 res.reserve(str_v.size());
148 for(
auto const& v : str_v)
153 template<> std::vector< unsigned long > FromString< std::vector< unsigned long > > (
const std::string&
value )
155 auto str_v = FromString<std::vector<std::string> >(
value);
156 std::vector<unsigned long> res;
157 res.reserve(str_v.size());
158 for(
auto const& v : str_v)
163 template<> std::vector< bool > FromString< std::vector< bool > > (
const std::string&
value )
165 auto str_v = FromString<std::vector<std::string> >(
value);
166 std::vector<bool> res;
167 res.reserve(str_v.size());
168 for(
auto const& v : str_v)
173 template<> std::string ToString<std::string>(
const std::string&
value)
175 std::string res(
value);
176 if(res.empty())
return res;
178 if(res.find(
"\"") == 0) res = res.substr(1);
179 if(res.empty())
return res;
181 if(res.rfind(
"\"") == (res.length()-1)) res = res.substr(0,res.length()-1);
BEGIN_PROLOG could also be cerr
bool FromString< bool >(const std::string &value)
Parse flashmatch::PSet configuration file content.
float FromString< float >(const std::string &value)
Parse flashmatch::PSet configuration file content.
std::string FromString(const std::string &value)
int FromString< int >(const std::string &value)
Parse flashmatch::PSet configuration file content.
unsigned int FromString< unsigned int >(const std::string &value)
Parse flashmatch::PSet configuration file content.
Utility functions in Base/PSet.
long FromString< long >(const std::string &value)
Parse flashmatch::PSet configuration file content.
double FromString< double >(const std::string &value)
Parse flashmatch::PSet configuration file content.
then echo File list $list not found else cat $list while read file do echo $file sed s
unsigned short FromString< unsigned short >(const std::string &value)
Parse flashmatch::PSet configuration file content.
unsigned long FromString< unsigned long >(const std::string &value)
Parse flashmatch::PSet configuration file content.
short FromString< short >(const std::string &value)
Parse flashmatch::PSet configuration file content.