6#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
7#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
16#include <system_error>
28 using std::runtime_error::runtime_error;
33 template <
typename Ref,
typename T = std::remove_cv_t<std::remove_reference_t<Ref>>,
34 std::enable_if_t<std::is_
floating_po
int_v<T> ||
35 std::is_same_v<
bool, T> ||
36 std::is_
signed_v<T> || std::is_
unsigned_v<T> ||
37 std::is_constructible_v<std::
string, T>,
41 if constexpr (std::is_floating_point_v<T>) {
43 }
else if constexpr (std::is_same_v<bool, T>) {
45 }
else if constexpr (std::is_signed_v<T>) {
47 }
else if constexpr (std::is_unsigned_v<T>) {
50 setStr(std::string{std::forward<Ref>(
val)});
63 void setStr(std::string str);
73 void getObjMap(std::map<std::string,UniValue>& kv)
const;
74 bool checkObject(
const std::map<std::string,UniValue::VType>& memberTypes)
const;
77 bool exists(
const std::string& key)
const {
size_t i;
return findKey(key, i); }
89 void push_backV(
const std::vector<UniValue>& vec);
97 std::string
write(
unsigned int prettyIndent = 0,
98 unsigned int indentLevel = 0)
const;
100 bool read(std::string_view raw);
109 bool findKey(
const std::string& key,
size_t& retIdx)
const;
110 void writeArray(
unsigned int prettyIndent,
unsigned int indentLevel, std::string&
s)
const;
111 void writeObject(
unsigned int prettyIndent,
unsigned int indentLevel, std::string&
s)
const;
116 const std::vector<std::string>&
getKeys()
const;
117 const std::vector<UniValue>&
getValues()
const;
118 template <
typename Int>
121 const std::string&
get_str()
const;
137template <
typename Int>
140 static_assert(std::is_integral<Int>::value);
143 const auto [first_nonmatching, error_condition] = std::from_chars(
val.data(),
val.data() +
val.size(), result);
144 if (first_nonmatching !=
val.data() +
val.size() || error_condition != std::errc{}) {
145 throw std::runtime_error(
"JSON integer out of range");
167 unsigned int& consumed,
const char *raw,
const char *end);
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
void writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string &s) 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 writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string &s) const
void push_backV(const std::vector< UniValue > &vec)
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)