34
RangeInputFilterImpl::RangeInputFilterImpl(std::string const& id, std::string const& start_label, std::string const& end_label, std::string const& unit_label)
34
RangeInputFilterImpl::RangeInputFilterImpl(std::string const& id,
35
Variant const& default_start_value, Variant const& default_end_value,
36
std::string const& start_prefix_label, std::string const& start_postfix_label,
37
std::string const& central_label,
38
std::string const& end_prefix_label, std::string const& end_postfix_label)
35
39
: FilterBaseImpl(id),
36
start_label_(start_label),
37
end_label_(end_label),
38
unit_label_(unit_label)
40
default_start_value_(default_start_value),
41
default_end_value_(default_end_value),
42
start_prefix_label_(start_prefix_label),
43
start_postfix_label_(start_postfix_label),
44
end_prefix_label_(end_prefix_label),
45
end_postfix_label_(end_postfix_label),
46
central_label_(central_label)
55
std::string RangeInputFilterImpl::start_label() const
60
std::string RangeInputFilterImpl::end_label() const
65
std::string RangeInputFilterImpl::unit_label() const
63
std::string RangeInputFilterImpl::start_prefix_label() const
65
return start_prefix_label_;
68
std::string RangeInputFilterImpl::start_postfix_label() const
70
return start_postfix_label_;
73
std::string RangeInputFilterImpl::end_prefix_label() const
75
return end_prefix_label_;
78
std::string RangeInputFilterImpl::end_postfix_label() const
80
return end_postfix_label_;
83
std::string RangeInputFilterImpl::central_label() const
85
return central_label_;
88
Variant RangeInputFilterImpl::default_start_value() const
90
return default_start_value_;
93
Variant RangeInputFilterImpl::default_end_value() const
95
return default_end_value_;
70
98
bool RangeInputFilterImpl::has_value(FilterState const& filter_state, unsigned int index) const
117
throw unity::scopes::NotFoundException("RangeInputFilterImpl::get_value(): invalid index for filter '" + id() + "'",
145
throw NotFoundException("RangeInputFilterImpl::get_value(): invalid index for filter '" + id() + "'",
118
146
std::to_string(index));
121
149
double RangeInputFilterImpl::start_value(FilterState const& filter_state) const
123
return get_value(filter_state, 0);
153
return get_value(filter_state, 0);
155
catch (unity::scopes::NotFoundException const&)
157
if (default_start_value_.which() == Variant::Type::Double)
159
return default_start_value_.get_double();
161
if (default_end_value_.which() == Variant::Type::Int)
163
return default_start_value_.get_int();
166
throw NotFoundException("RangeInputFilterImpl::start_value(): start value is not set for filter", id());
126
169
double RangeInputFilterImpl::end_value(FilterState const& filter_state) const
128
return get_value(filter_state, 1);
173
return get_value(filter_state, 1);
175
catch (unity::scopes::NotFoundException const&)
177
if (default_end_value_.which() == Variant::Type::Double)
179
return default_end_value_.get_double();
181
if (default_end_value_.which() == Variant::Type::Int)
183
return default_end_value_.get_int();
186
throw NotFoundException("RangeInputFilterImpl::end_value(): end value is not set for filter", id());
131
189
void RangeInputFilterImpl::check_type(Variant const& val, std::string const& filter_id, std::string const& varname)
133
191
if (val.which() == Variant::Type::Int || val.which() == Variant::Type::Double || val.is_null())
135
195
std::stringstream err;
136
196
err << "RangeInputFilterImpl::check_type(): Invalid variant type for " << varname << ", filter '" << filter_id << "'";
137
197
throw unity::InvalidArgumentException(err.str());
179
239
void RangeInputFilterImpl::serialize(VariantMap& var) const
181
var["start_label"] = start_label_;
182
var["end_label"] = end_label_;
183
var["unit_label"] = unit_label_;
241
var["default_start_value"] = default_start_value_;
242
var["default_end_value"] = default_end_value_;
243
var["start_prefix_label"] = start_prefix_label_;
244
var["start_postfix_label"] = start_postfix_label_;
245
var["end_prefix_label"] = end_prefix_label_;
246
var["end_postfix_label"] = end_postfix_label_;
247
var["central_label"] = central_label_;
186
250
void RangeInputFilterImpl::deserialize(VariantMap const& var)
188
auto it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "start_label");
189
start_label_ = it->second.get_string();
190
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "end_label");
191
end_label_ = it->second.get_string();
192
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "unit_label");
193
unit_label_ = it->second.get_string();
252
auto it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "start_prefix_label");
253
start_prefix_label_ = it->second.get_string();
254
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "start_postfix_label");
255
start_postfix_label_ = it->second.get_string();
256
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "end_prefix_label");
257
end_prefix_label_ = it->second.get_string();
258
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "end_postfix_label");
259
end_postfix_label_ = it->second.get_string();
260
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "central_label");
261
central_label_ = it->second.get_string();
262
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "default_start_value");
263
default_start_value_ = it->second;
264
it = find_or_throw("RangeInputFilterImpl::deserialize()", var, "default_end_value");
265
default_end_value_ = it->second;
196
268
void RangeInputFilterImpl::validate_display_hints() const