27 #include <Ice/Properties.h>
29 #include <SimoxUtility/algorithm/string/string_tools.h>
31 #include <boost/regex.hpp>
32 #include <boost/lexical_cast.hpp>
38 template class PropertyDefinition<int>;
39 template class PropertyDefinition<float>;
40 template class PropertyDefinition<double>;
41 template class PropertyDefinition<std::string>;
42 template class PropertyDefinition<bool>;
46 return simox::alg::to_lower(
input);
51 boost::regex expr(regex);
52 return boost::regex_match(
value, expr);
57 std::map<std::string, std::string> result;
59 for (
auto& elem : splits)
61 simox::alg::trim(elem);
63 if (
split.size() == 2)
65 result[simox::alg::trim_copy(
split[0])] = simox::alg::trim_copy(
split[1]);
73 std::vector<std::string> args;
75 const boost::regex re(
",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
77 boost::match_results<std::string::const_iterator> what;
78 boost::match_flag_type flags = boost::match_default;
79 std::string::const_iterator
s =
input.begin();
80 std::string::const_iterator e =
input.end();
82 while (boost::regex_search(
s, e, what, re, flags))
84 int pos = what.position();
85 auto arg =
input.substr(begin, pos);
86 simox::alg::trim(arg);
91 std::string::difference_type l = what.length();
92 std::string::difference_type p = what.position();
96 std::string lastArg =
input.substr(begin);
97 simox::alg::trim(lastArg);
100 args.push_back(lastArg);
107 std::regex re_number{
"^[0-9]*\\.?[0-9]+"};
108 std::regex re_unit{
"[a-zµ]+$"};
109 std::smatch number_match;
110 std::smatch unit_match;
112 if (not std::regex_search(
input.begin(),
input.end(), number_match, re_number))
116 <<
"Could not parse Time (number invalid).";
119 if (not std::regex_search(
input.begin(),
input.end(), unit_match, re_unit))
123 <<
"Could not parse Time (unit invalid).";
126 const double value = boost::lexical_cast<double>(number_match[0]);
128 static constexpr
long h2us = 1000l * 1000 * 60 * 60;
129 static constexpr
long m2us = 1000 * 1000 * 60;
130 static constexpr
long s2us = 1000 * 1000;
131 static constexpr
long ms2us = 1000;
132 static constexpr
long us = 1;
134 static std::map<std::string, long> conv_map;
136 conv_map[
"h"] = h2us;
137 conv_map[
"hrs"] = h2us;
138 conv_map[
"hour"] = h2us;
139 conv_map[
"hours"] = h2us;
141 conv_map[
"m"] = m2us;
142 conv_map[
"min"] = m2us;
143 conv_map[
"minute"] = m2us;
144 conv_map[
"minutes"] = m2us;
146 conv_map[
"s"] = s2us;
147 conv_map[
"sec"] = s2us;
148 conv_map[
"second"] = s2us;
149 conv_map[
"seconds"] = s2us;
151 conv_map[
"ms"] = ms2us;
152 conv_map[
"msec"] = ms2us;
153 conv_map[
"millisecond"] = ms2us;
154 conv_map[
"milliseconds"] = ms2us;
158 conv_map[
"µsec"] = us;
159 conv_map[
"usec"] = us;
160 conv_map[
"microsecond"] = us;
161 conv_map[
"microseconds"] = us;
163 if (conv_map.find(unit_match[0]) == conv_map.end())
167 <<
"Invalid/unknown unit `" << unit_match[0] <<
"`.";
170 const long int to_microseconds_mult = conv_map[unit_match[0]];
171 return IceUtil::Time::microSeconds(
value * to_microseconds_mult);
176 std::locale::global(std::locale::classic());
177 return boost::lexical_cast<std::string>(
input);
182 std::locale::global(std::locale::classic());
183 return boost::lexical_cast<std::string>(
input);
188 return boost::lexical_cast<std::string>(
input);
193 return boost::lexical_cast<std::string>(
input);
198 return boost::lexical_cast<std::string>(
input);
203 return boost::lexical_cast<std::string>(
input);
214 std::locale::global(std::locale::classic());
215 return boost::lexical_cast<double>(
input);
221 std::locale::global(std::locale::classic());
222 return boost::lexical_cast<float>(
input);
228 return boost::lexical_cast<long>(
input);
234 return boost::lexical_cast<int>(
input);
240 return boost::lexical_cast<unsigned long>(
input);
246 return boost::lexical_cast<unsigned int>(
input);
252 return boost::lexical_cast<char>(
input);
258 return boost::lexical_cast<unsigned char>(
input);
264 return boost::lexical_cast<bool>(
input);
269 return iceProperties->getProperty(key);
279 return iceProperties->getPropertyWithDefault(prefix + propertyName,
"::NOT-SET::")
280 .compare(
"::NOT-SET::") != 0;