29 #include <boost/lexical_cast.hpp>
30 #include <boost/regex.hpp>
32 #include <Ice/Properties.h>
34 #include <SimoxUtility/algorithm/string/string_tools.h>
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>;
47 return simox::alg::to_lower(
input);
53 boost::regex expr(regex);
54 return boost::regex_match(
value, expr);
57 std::map<std::string, std::string>
60 std::map<std::string, std::string> result;
62 for (
auto& elem : splits)
64 simox::alg::trim(elem);
66 if (
split.size() == 2)
68 result[simox::alg::trim_copy(
split[0])] = simox::alg::trim_copy(
split[1]);
74 std::vector<std::string>
77 std::vector<std::string> args;
79 const boost::regex re(
",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
81 boost::match_results<std::string::const_iterator> what;
82 boost::match_flag_type flags = boost::match_default;
83 std::string::const_iterator
s =
input.begin();
84 std::string::const_iterator e =
input.end();
86 while (boost::regex_search(
s, e, what, re, flags))
88 int pos = what.position();
89 auto arg =
input.substr(begin, pos);
90 simox::alg::trim(arg);
95 std::string::difference_type l = what.length();
96 std::string::difference_type p = what.position();
100 std::string lastArg =
input.substr(begin);
101 simox::alg::trim(lastArg);
102 if (!lastArg.empty())
104 args.push_back(lastArg);
112 std::regex re_number{
"^[0-9]*\\.?[0-9]+"};
113 std::regex re_unit{
"[a-zµ]+$"};
114 std::smatch number_match;
115 std::smatch unit_match;
117 if (not std::regex_search(
input.begin(),
input.end(), number_match, re_number))
121 <<
"Could not parse Time (number invalid).";
124 if (not std::regex_search(
input.begin(),
input.end(), unit_match, re_unit))
128 <<
"Could not parse Time (unit invalid).";
131 const double value = boost::lexical_cast<double>(number_match[0]);
133 static constexpr
long h2us = 1000l * 1000 * 60 * 60;
134 static constexpr
long m2us = 1000 * 1000 * 60;
135 static constexpr
long s2us = 1000 * 1000;
136 static constexpr
long ms2us = 1000;
137 static constexpr
long us = 1;
139 static std::map<std::string, long> conv_map;
141 conv_map[
"h"] = h2us;
142 conv_map[
"hrs"] = h2us;
143 conv_map[
"hour"] = h2us;
144 conv_map[
"hours"] = h2us;
146 conv_map[
"m"] = m2us;
147 conv_map[
"min"] = m2us;
148 conv_map[
"minute"] = m2us;
149 conv_map[
"minutes"] = m2us;
151 conv_map[
"s"] = s2us;
152 conv_map[
"sec"] = s2us;
153 conv_map[
"second"] = s2us;
154 conv_map[
"seconds"] = s2us;
156 conv_map[
"ms"] = ms2us;
157 conv_map[
"msec"] = ms2us;
158 conv_map[
"millisecond"] = ms2us;
159 conv_map[
"milliseconds"] = ms2us;
163 conv_map[
"µsec"] = us;
164 conv_map[
"usec"] = us;
165 conv_map[
"microsecond"] = us;
166 conv_map[
"microseconds"] = us;
168 if (conv_map.find(unit_match[0]) == conv_map.end())
172 <<
"Invalid/unknown unit `" << unit_match[0] <<
"`.";
175 const long int to_microseconds_mult = conv_map[unit_match[0]];
176 return IceUtil::Time::microSeconds(
value * to_microseconds_mult);
182 std::locale::global(std::locale::classic());
183 return boost::lexical_cast<std::string>(
input);
189 std::locale::global(std::locale::classic());
190 return boost::lexical_cast<std::string>(
input);
196 return boost::lexical_cast<std::string>(
input);
202 return boost::lexical_cast<std::string>(
input);
208 return boost::lexical_cast<std::string>(
input);
214 return boost::lexical_cast<std::string>(
input);
227 std::locale::global(std::locale::classic());
228 return boost::lexical_cast<double>(
input);
235 std::locale::global(std::locale::classic());
236 return boost::lexical_cast<float>(
input);
243 return boost::lexical_cast<long>(
input);
250 return boost::lexical_cast<int>(
input);
257 return boost::lexical_cast<unsigned long>(
input);
264 return boost::lexical_cast<unsigned int>(
input);
271 return boost::lexical_cast<char>(
input);
278 return boost::lexical_cast<unsigned char>(
input);
285 return boost::lexical_cast<bool>(
input);
290 const std::string& key)
292 return iceProperties->getProperty(key);
297 std::string
const& propertyName,
305 return iceProperties->getPropertyWithDefault(prefix + propertyName,
"::NOT-SET::")
306 .compare(
"::NOT-SET::") != 0;