aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2016-08-27 18:12:17 +0900
committeripknHama <ipknhama@gmail.com>2016-08-27 18:12:17 +0900
commitf88b56dff0e8adfbd654d0b39791c2664c863e07 (patch)
treee45e6f87f0a4564492fea7a339f71fda1614541e /include
parente161da45e08a2eaaec747a784020d69f8223418d (diff)
downloadcrow-f88b56dff0e8adfbd654d0b39791c2664c863e07.tar.gz
crow-f88b56dff0e8adfbd654d0b39791c2664c863e07.zip
Add u() for uint64_t: manually applying #129
Diffstat (limited to 'include')
-rw-r--r--include/json.h21
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];
}