6#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
7#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
16#include <system_error>
22struct UniValueStreamWriter;
26 friend struct ::UniValueStreamWriter;
39 using std::runtime_error::runtime_error;
45 template <
typename Ref,
46 typename T = std::remove_cv_t<std::remove_reference_t<Ref>>,
48 std::is_floating_point_v<T> ||
49 std::is_same_v<bool, T> ||
50 std::is_signed_v<T> || std::is_unsigned_v<T> ||
51 std::is_constructible_v<std::string, T>,
54 if constexpr (std::is_floating_point_v<T>) {
56 }
else if constexpr (std::is_same_v<bool, T>) {
58 }
else if constexpr (std::is_signed_v<T>) {
60 }
else if constexpr (std::is_unsigned_v<T>) {
63 setStr(std::string{std::forward<Ref>(
val)});
84 void setStr(std::string str);
94 void getObjMap(std::map<std::string, UniValue> &
kv)
const;
96 const std::map<std::string, UniValue::VType> &
memberTypes)
const;
99 bool exists(
const std::string &key)
const {
124 bool read(std::string_view raw);
138 const std::vector<std::string> &
getKeys()
const;
139 const std::vector<UniValue> &
getValues()
const;
140 template <
typename Int>
Int getInt()
const;
142 const std::string &
get_str()
const;
158 static_assert(std::is_integral<Int>::value);
162 std::from_chars(
val.data(),
val.data() +
val.size(), result);
165 throw std::runtime_error(
"JSON integer out of range");
187 unsigned int &
consumed,
const char *raw,
void push_back(UniValue val)
const std::string & get_str() const
UniValue(UniValue::VType type, std::string str={})
bool checkObject(const std::map< std::string, UniValue::VType > &memberTypes) const
const UniValue & find_value(std::string_view key) const
enum VType getType() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const std::string & getValStr() const
const UniValue & get_obj() const
const std::vector< UniValue > & getValues() const
void pushKVs(UniValue obj)
const std::vector< std::string > & getKeys() const
void setInt(uint64_t val)
void pushKVEnd(std::string key, UniValue val)
std::vector< UniValue > values
std::vector< std::string > keys
void checkType(const VType &expected) const
bool findKey(const std::string &key, size_t &retIdx) const
bool read(std::string_view raw)
const UniValue & operator[](const std::string &key) const
const UniValue & get_array() const
bool exists(const std::string &key) const
void setFloat(double val)
void setStr(std::string str)
void pushKV(std::string key, UniValue val)
void setNumStr(std::string str)
void getObjMap(std::map< std::string, UniValue > &kv) const
void push_backV(const std::vector< UniValue > &vec)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
enum jtokentype getJsonToken(std::string &tokenVal, unsigned int &consumed, const char *raw, const char *end)
static bool jsonTokenIsValue(enum jtokentype jtt)
static bool json_isspace(int ch)
const UniValue NullUniValue
const char * uvTypeName(UniValue::VType t)