MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ToBool

Method ToBool

lib/base/value.cpp:185–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185bool Value::ToBool() const
186{
187 switch (GetType()) {
188 case ValueNumber:
189 return static_cast<bool>(boost::get<double>(m_Value));
190
191 case ValueBoolean:
192 return boost::get<bool>(m_Value);
193
194 case ValueString:
195 return !boost::get<String>(m_Value).IsEmpty();
196
197 case ValueObject:
198 if (IsObjectType<Dictionary>()) {
199 Dictionary::Ptr dictionary = *this;
200 return dictionary->GetLength() > 0;
201 } else if (IsObjectType<Array>()) {
202 Array::Ptr array = *this;
203 return array->GetLength() > 0;
204 } else {
205 return true;
206 }
207
208 case ValueEmpty:
209 return false;
210
211 default:
212 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid variant type."));
213 }
214}
215
216String Value::GetTypeName() const
217{

Callers 12

InternalExecuteQueryMethod · 0.45
InternalExecuteQueryMethod · 0.45
PackAnyFunction · 0.45
EncodeMethod · 0.45
AssertMethod · 0.45
EvaluateObjectRuleMethod · 0.45
EvaluateObjectRuleMethod · 0.45
EvaluateObjectRuleMethod · 0.45
DoEvaluateMethod · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
CheckNotificationFunction · 0.45

Calls 2

IsEmptyMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected