1#ifndef LIBFILEZILLA_JSON_HEADER
2#define LIBFILEZILLA_JSON_HEADER
33 json()
noexcept =
default;
41 return static_cast<json_type>(value_.index());
54 template<
typename T, std::enable_if_t<std::is_
integral_v<
typename std::decay_t<T>>,
int> = 0>
56 return static_cast<T>(number_value_integer());
60 template<
typename T, std::enable_if_t<std::is_
floating_po
int_v<
typename std::decay_t<T>>,
int> = 0>
62 return static_cast<T>(number_value_double());
69 void erase(std::string
const& name);
97 template<
typename Bool, std::enable_if_t<std::is_same_v<
bool,
typename std::decay_t<Bool>>,
int> = 0>
104 template<
typename T, std::enable_if_t<std::is_
integral_v<T> && !std::is_same_v<
bool,
typename std::decay_t<T>>,
int> = 0>
126 bool has_non_null_value()
const {
132 bool is_array()
const {
return type() == fz::json_type::array; }
133 bool is_number()
const {
return type() == fz::json_type::number; }
134 bool is_boolean()
const {
return type() == fz::json_type::boolean; }
162 void to_string_impl(std::string &
ret,
bool pretty =
false,
size_t depth = 0)
const;
164 uint64_t number_value_integer()
const;
165 double number_value_double()
const;
172 typedef std::variant<
175 std::map<std::string, json, std::less<>>,
184template <
bool isconst>
186 using json_ref_t = std::conditional_t<isconst, json const&, json &>;
203 json_ref_t operator*()
const
208 bool operator!=(json_array_iterator::sentinel
const&)
const
210 return idx_ < json_.children();
219inline json_array_iterator<false>::sentinel end(json &) {
return {}; }
222inline json_array_iterator<true>::sentinel end(json
const&) {
return {}; }
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition buffer.hpp:27
json parser/builder
Definition json.hpp:31
static json parse(std::string_view const &v, size_t max_depth=20)
Parses JSON structure from input.
json & operator=(T n)
Sets type to number and assigns value.
Definition json.hpp:105
json & operator=(std::string_view const &v)
Sets type to string and assigns value.
std::string to_string(bool pretty=false, size_t depth=0) const
Serializes JSON structure.
json & operator[](size_t i)
Returns reference to the child value with the given index.
std::string string_value() const
Returns string, number and boolean values as string.
json const & operator[](std::string const &name) const
If object, get the value with the given name. Returns none if not object or name doesn't exist.
json & operator=(std::wstring_view const &v)
Sets type to string and assigns value.
Definition json.hpp:117
void erase(std::string const &name)
If object value, deletes child value with given name.
json & operator=(Bool b)
Sets type to boolean and assigns value.
Definition json.hpp:98
size_t children() const
For arrays and objects, returns the number of elements.
void to_string(std::string &ret, bool pretty=false, size_t depth=0) const
Serializes JSON structure.
json & operator[](std::string const &name)
Returns reference to the child value with the given name.
T number_value() const
Returns number and string values as the passed integer type.
Definition json.hpp:55
std::wstring wstring_value() const
Returns string, number and boolean values as wstring.
Definition json.hpp:48
json(json_type t)
Explicitly creates a value of a specific type, mainly needed for null objects.
bool bool_value() const
Returns boolean and string values as bool.
json const & operator[](size_t i) const
If array, get the value with the given index. Returns none if not array or index doesn't exist.
type
Definition logger.hpp:16
The namespace used by libfilezilla.
Definition apply.hpp:17
std::wstring to_wstring_from_utf8(std::string_view const &in)
Converts from std::string in UTF-8 into std::wstring.
std::string to_utf8(std::string_view const &in)
Converts from std::string in native encoding into std::string in UTF-8.
bool dispatch(event_base const &ev, F &&f)
Dispatch for simple_event<> based events to simple functors.
Definition event_handler.hpp:199
std::string to_string(std::wstring_view const &in)
Converts from std::wstring into std::string in system encoding.
json_type
Types of JSON values.
Definition json.hpp:16
@ object
The explicit null value.
String types and assorted functions.