| 183 | } |
| 184 | |
| 185 | bool 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 | |
| 216 | String Value::GetTypeName() const |
| 217 | { |
no test coverage detected