diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/json.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/include/json.h b/include/json.h index 3706034..27e621e 100644 --- a/include/json.h +++ b/include/json.h @@ -262,6 +262,11 @@ namespace crow return i(); } + explicit operator uint64_t() const + { + return u(); + } + explicit operator int() const { return (int)i(); @@ -294,6 +299,20 @@ namespace crow return boost::lexical_cast<int64_t>(start_, end_-start_); } + uint64_t u() const + { +#ifndef CROW_JSON_NO_ERROR_CHECK + switch (t()) { + case type::Number: + case type::String: + return boost::lexical_cast<uint64_t>(start_, end_-start_); + default: + throw std::runtime_error(std::string("expected number, got: ") + get_type_str(t())); + } +#endif + return boost::lexical_cast<uint64_t>(start_, end_-start_); + } + double d() const { #ifndef CROW_JSON_NO_ERROR_CHECK @@ -1289,7 +1308,7 @@ namespace crow o = std::unique_ptr< std::unordered_map<std::string, wvalue> >( - new std::unordered_map<std::string, wvalue>{})); + new std::unordered_map<std::string, wvalue>{}); return (*o)[str]; } |