Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider exposing value::_type or provide a value::_type to std::string utility #77

Open
weegreenblobbie opened this issue Feb 6, 2016 · 0 comments

Comments

@weegreenblobbie
Copy link

I'm passing around some picojson objects/values and wanted to assert on type. As part of my message, I wanted to dump the type of value I got:

M_ASSERT_MSG(
    input.is<picojson::object>(),
     "Expecting a JSON object, got " << to_type_string(input)
);

As a workaround, I've written this in my code to do it:

std::string
to_type_string(const picojson::value & v)
{
    if(v.is<bool>()) return "bool";
    else
    if(v.is<picojson::null>()) return "null";
    else
    if(v.is<int64_t>()) return "int";
    else
    if(v.is<float64>()) return "float";
    else
    if(v.is<std::string>()) return "string";
    else
    if(v.is<picojson::array>()) return "array";
    else
    if(v.is<picojson::object>()) return "object";
    else
    if(v.is<picojson::object>()) return "object";
    return "unknown";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant