12#ifndef _EXPORT_VALUE_VEC_H_
13#define _EXPORT_VALUE_VEC_H_
23 Value_Vec(
const std::string&
str,
bool error_out_of_bound =
false, T out_of_bound_val = 0);
25 Value_Vec(
const YAML::Node& node,
bool error_out_of_bound =
false, T out_of_bound_val = 0);
33 std::string
asStr(
bool quoted =
false)
const;
35 size_t size()
const noexcept;
50 : _error_out_of_bound(error_out_of_bound), _out_of_bound_val(out_of_bound_val) {
51 std::vector<std::string> tokens;
56 std::getline(ss, buf,
',');
57 tokens.push_back(buf);
59 for (
auto&& token : tokens) {
parseToken(token); }
64 : _error_out_of_bound(error_out_of_bound), _out_of_bound_val(out_of_bound_val) {
65 if (node.IsScalar()) {
66 std::vector<std::string> tokens;
71 std::getline(ss, buf,
',');
72 tokens.push_back(buf);
74 for (
auto&& token : tokens) {
parseToken(token); }
76 for (
auto&& token : node) {
parseToken(token.as<std::string>()); }
82 if (
str.size() < 2)
return str;
83 if (
str[0] ==
'[' && *(
str.end() - 1) ==
']')
return str.substr(1,
str.length() - 2);
90 size_t first_colon = s.find(
':');
91 size_t second_colon = std::string::npos;
92 if (first_colon != std::string::npos) {
93 second_colon = s.find(
':', first_colon + 1);
94 if (second_colon != std::string::npos) {
96 T v1 = strAs<T>(s.substr(0, first_colon));
97 T v_ = strAs<T>(s.substr(first_colon + 1, second_colon - first_colon));
98 T v2 = strAs<T>(s.substr(second_colon + 1, s.size() - 1 - second_colon));
101 _data.push_back(strAs<T>(s));
105 assert(
"step size as 0 in 2 colons specification.");
108 for (T v = v1; v <= v2 + 1E-12; v += v_) { _data.push_back(v); }
110 for (T v = v1; v + 1E-12 >= v2; v += v_) { _data.push_back(v); }
114 T v1 = strAs<T>(s.substr(0, first_colon));
115 T v2 = strAs<T>(s.substr(first_colon + 1, s.size() - 1 - first_colon));
117 for (T v = v1; v <= v2 + 1E-12; v += 1) { _data.push_back(v); }
120 for (T v = v2 + 1; v + 1E-12 >= v1 + 1; v -= 1) { _data.push_back(v - 1); }
124 _data.push_back(strAs<T>(s));
131 if (index < _data.size()) {
134 if (_error_out_of_bound) {
136 assert(
false &&
"Out of bound for a value_vec!");
139 return _out_of_bound_val;
148 if (_data.size() == 0)
return 0;
150 for (
auto&& v : _data) {
151 if (v > max) max = v;
158 if (_data.size() == 0)
return 0;
160 for (
auto&& v : _data) {
161 if (v < min) min = v;
168 if (_data.size() == 0)
return "";
170 for (
auto i = _data.cbegin(); i + 1 != _data.end(); ++i) {
Definition: value_vec.h:21
std::string removeBracket(const std::string &str)
Definition: value_vec.h:81
Value_Vec(const std::string &str, bool error_out_of_bound=false, T out_of_bound_val=0)
Definition: value_vec.h:49
bool _error_out_of_bound
Definition: value_vec.h:44
T min() const
Definition: value_vec.h:157
void parseToken(const std::string &s)
Definition: value_vec.h:88
T max() const
Definition: value_vec.h:147
T operator[](size_t index) const
Definition: value_vec.h:129
std::vector< T > _data
Definition: value_vec.h:43
size_t size() const noexcept
Definition: value_vec.h:180
std::string asStr(bool quoted=false) const
Definition: value_vec.h:167
T _out_of_bound_val
Definition: value_vec.h:45
static std::string to_string(const T &x)
Change a number to string.
Definition: utils.h:203
str
Definition: version_bump.py:14
Wrapper for yaml-cpp for static linking.