diff options
author | Jeff Garzik <jgarzik@bitpay.com> | 2014-08-20 15:15:16 -0400 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-04 09:16:05 +0200 |
commit | 15982a8b69ec6ab3c3a6bf71fc6a9b681d3ff541 (patch) | |
tree | 854a48a039d4199dbc1acf33ef94d06d007f1348 /src/univalue/univalue.h | |
parent | 5e3060c0d104c734e7e2a200e2d937ea01166c8a (diff) |
Convert tree to using univalue. Eliminate all json_spirit uses.
Diffstat (limited to 'src/univalue/univalue.h')
-rw-r--r-- | src/univalue/univalue.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/univalue/univalue.h b/src/univalue/univalue.h index afe751ed9d..28d6e3d3cd 100644 --- a/src/univalue/univalue.h +++ b/src/univalue/univalue.h @@ -11,6 +11,10 @@ #include <map> #include <cassert> +#include <sstream> // .get_int64() +#include <utility> // std::pair +#include <stdlib.h> // atoi(), atof() TODO: remove + class UniValue { public: enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; @@ -130,8 +134,88 @@ private: int findKey(const std::string& key) const; void writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const; void writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const; + +public: + // + // The following were added for compatibility with json_spirit. + // Most duplicate other methods, and should be removed. + // + std::vector<std::string> getKeys() const { return keys; } + std::vector<UniValue> getValues() const { return values; } + bool get_bool() const { return getBool(); } + std::string get_str() const { return getValStr(); } + int get_int() const { return atoi(getValStr().c_str()); } + double get_real() const { return atof(getValStr().c_str()); } + const UniValue& get_obj() const { return *this; } + const UniValue& get_array() const { return *this; } + enum VType type() const { return getType(); } + bool push_back(std::pair<std::string,UniValue> pear) { + return pushKV(pear.first, pear.second); + } + int64_t get_int64() const { + int64_t ret; + std::istringstream(getValStr()) >> ret; + return ret; + } }; +// +// The following were added for compatibility with json_spirit. +// Most duplicate other methods, and should be removed. +// +static inline std::pair<std::string,UniValue> Pair(const char *cKey, const char *cVal) +{ + std::string key(cKey); + UniValue uVal(cVal); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, std::string strVal) +{ + std::string key(cKey); + UniValue uVal(strVal); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, uint64_t u64Val) +{ + std::string key(cKey); + UniValue uVal(u64Val); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, int64_t i64Val) +{ + std::string key(cKey); + UniValue uVal(i64Val); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, int iVal) +{ + std::string key(cKey); + UniValue uVal(iVal); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, double dVal) +{ + std::string key(cKey); + UniValue uVal(dVal); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(const char *cKey, const UniValue& uVal) +{ + std::string key(cKey); + return std::make_pair(key, uVal); +} + +static inline std::pair<std::string,UniValue> Pair(std::string key, const UniValue& uVal) +{ + return std::make_pair(key, uVal); +} + enum jtokentype { JTOK_ERR = -1, JTOK_NONE = 0, // eof |