Changeset View
Changeset View
Standalone View
Standalone View
src/univalue/include/univalue.h
Show All 20 Lines | |||||
} | } | ||||
class UniValue { | class UniValue { | ||||
friend struct ::UniValueStreamWriter; | friend struct ::UniValueStreamWriter; | ||||
public: | public: | ||||
enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; | enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; | ||||
UniValue() { typ = VNULL; } | UniValue() : typ(VNULL) {} | ||||
UniValue(UniValue::VType initialType, const std::string& initialStr = "") { | UniValue(UniValue::VType type, const std::string& value = std::string()) : typ(type), val(value) {} | ||||
typ = initialType; | |||||
val = initialStr; | |||||
} | |||||
UniValue(uint64_t val_) { | UniValue(uint64_t val_) { | ||||
setInt(val_); | setInt(val_); | ||||
} | } | ||||
UniValue(int64_t val_) { | UniValue(int64_t val_) { | ||||
setInt(val_); | setInt(val_); | ||||
} | } | ||||
UniValue(bool val_) { | UniValue(bool val_) { | ||||
setBool(val_); | setBool(val_); | ||||
} | } | ||||
UniValue(int val_) { | UniValue(int val_) { | ||||
setInt(val_); | setInt(val_); | ||||
} | } | ||||
UniValue(double val_) { | UniValue(double val_) { | ||||
setFloat(val_); | setFloat(val_); | ||||
} | } | ||||
UniValue(const std::string& val_) { | UniValue(const std::string& val_) { | ||||
setStr(val_); | setStr(val_); | ||||
} | } | ||||
UniValue(const char *val_) { | UniValue(const char *val_) { | ||||
std::string s(val_); | std::string s(val_); | ||||
setStr(s); | setStr(s); | ||||
} | } | ||||
~UniValue() {} | |||||
void clear(); | void clear(); | ||||
void reserve(size_t n) { | |||||
if (typ == VOBJ || typ == VARR) { | |||||
if (typ == VOBJ) | |||||
keys.reserve(n); | |||||
values.reserve(n); | |||||
} else if (typ != VNULL) { | |||||
val.reserve(n); | |||||
} | |||||
} | |||||
bool setNull(); | bool setNull(); | ||||
bool setBool(bool val); | bool setBool(bool val); | ||||
bool setNumStr(const std::string& val); | bool setNumStr(const std::string& val); | ||||
bool setInt(uint64_t val); | bool setInt(uint64_t val); | ||||
bool setInt(int64_t val); | bool setInt(int64_t val); | ||||
bool setInt(int val_) { return setInt((int64_t)val_); } | bool setInt(int val_) { return setInt((int64_t)val_); } | ||||
bool setFloat(double val); | bool setFloat(double val); | ||||
Show All 19 Lines | public: | ||||
bool isFalse() const { return (typ == VBOOL) && (val != "1"); } | bool isFalse() const { return (typ == VBOOL) && (val != "1"); } | ||||
bool isBool() const { return (typ == VBOOL); } | bool isBool() const { return (typ == VBOOL); } | ||||
bool isStr() const { return (typ == VSTR); } | bool isStr() const { return (typ == VSTR); } | ||||
bool isNum() const { return (typ == VNUM); } | bool isNum() const { return (typ == VNUM); } | ||||
bool isArray() const { return (typ == VARR); } | bool isArray() const { return (typ == VARR); } | ||||
bool isObject() const { return (typ == VOBJ); } | bool isObject() const { return (typ == VOBJ); } | ||||
bool push_back(const UniValue& val); | bool push_back(const UniValue& val); | ||||
bool push_back(const std::string& val_) { | |||||
UniValue tmpVal(VSTR, val_); | |||||
return push_back(tmpVal); | |||||
} | |||||
bool push_back(const char *val_) { | |||||
std::string s(val_); | |||||
return push_back(s); | |||||
} | |||||
bool push_back(uint64_t val_) { | |||||
UniValue tmpVal(val_); | |||||
return push_back(tmpVal); | |||||
} | |||||
bool push_back(int64_t val_) { | |||||
UniValue tmpVal(val_); | |||||
return push_back(tmpVal); | |||||
} | |||||
bool push_back(int val_) { | |||||
UniValue tmpVal(val_); | |||||
return push_back(tmpVal); | |||||
} | |||||
bool push_back(double val_) { | |||||
UniValue tmpVal(val_); | |||||
return push_back(tmpVal); | |||||
} | |||||
bool push_backV(const std::vector<UniValue>& vec); | bool push_backV(const std::vector<UniValue>& vec); | ||||
void __pushKV(const std::string& key, const UniValue& val); | void __pushKV(const std::string& key, const UniValue& val); | ||||
bool pushKV(const std::string& key, const UniValue& val); | bool pushKV(const std::string& key, const UniValue& val); | ||||
bool pushKV(const std::string& key, const std::string& val_) { | |||||
UniValue tmpVal(VSTR, val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKV(const std::string& key, const char *val_) { | |||||
std::string _val(val_); | |||||
return pushKV(key, _val); | |||||
} | |||||
bool pushKV(const std::string& key, int64_t val_) { | |||||
UniValue tmpVal(val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKV(const std::string& key, uint64_t val_) { | |||||
UniValue tmpVal(val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKV(const std::string& key, bool val_) { | |||||
UniValue tmpVal((bool)val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKV(const std::string& key, int val_) { | |||||
UniValue tmpVal((int64_t)val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKV(const std::string& key, double val_) { | |||||
UniValue tmpVal(val_); | |||||
return pushKV(key, tmpVal); | |||||
} | |||||
bool pushKVs(const UniValue& obj); | bool pushKVs(const UniValue& obj); | ||||
std::string write(unsigned int prettyIndent = 0, | std::string write(unsigned int prettyIndent = 0, | ||||
unsigned int indentLevel = 0) const; | unsigned int indentLevel = 0) const; | ||||
bool read(const char *raw, size_t len); | bool read(const char *raw, size_t len); | ||||
bool read(const char *raw) { return read(raw, strlen(raw)); } | bool read(const char *raw) { return read(raw, strlen(raw)); } | ||||
bool read(const std::string& rawStr) { | bool read(const std::string& rawStr) { | ||||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |