17#include <nlohmann/json.hpp>
36 return *
static_cast<nlohmann::json *
>(
value);
39inline nlohmann::json parseWrapper(std::istream &is)
42 return nlohmann::json::parse(is);
43 }
catch (
const nlohmann::json::exception &
ex) {
44 throw std::runtime_error(
ex.what());
50bool isResettingPossible(nlohmann::json
const &node)
53 if (node.type() == nlohmann::json::value_t::null) {
57 if (node.type() == nlohmann::json::value_t::string) {
58 if (node.get<std::string>().empty()) {
83 std::vector<JSONNode *> &list =
childLists.back();
84 if (!
value.is_structured()) {
87 list.reserve(
value.size());
88 for (
auto it =
value.begin(); it !=
value.end(); ++it) {
89 list.push_back(&
makeNode(it.value(),
value.is_array() ?
"" : it.key()));
104 std::vector<std::unique_ptr<JSONNode>>
nodes;
112 : _storage{&storage}, _value{
value}, _key{std::move(key)}
196 throw std::runtime_error(
"cannot declare \"" + this->
key() +
"\" to be of map - type, already of type " +
210 throw std::runtime_error(
"cannot declare \"" + this->
key() +
"\" to be of seq - type, already of type " +
240 switch (
value.type()) {
241 case nlohmann::json::value_t::string:
return value.get<std::string>();
242 case nlohmann::json::value_t::boolean:
return value.get<
bool>() ?
"true" :
"false";
243 case nlohmann::json::value_t::number_integer:
return std::to_string(
value.get<
int>());
244 case nlohmann::json::value_t::number_unsigned:
return std::to_string(
value.get<
unsigned int>());
245 case nlohmann::json::value_t::number_float: {
246 std::stringstream ss;
247 ss <<
value.get<
double>();
251 throw std::runtime_error(
"node \"" +
_key +
"\": implicit string conversion for type " +
value.type_name() +
269 if (nd.type() == nlohmann::json::value_t::number_unsigned) {
270 auto val = nd.get<
unsigned int>();
277 return nd.get<
bool>();
282 return !
_key.empty();
350 return std::unique_ptr<JSONTree>{
new JSONTree{std::make_unique<JSONNode::Storage>(nlohmann::json{})}};
355 return std::unique_ptr<JSONTree>{
new JSONTree{std::make_unique<JSONNode::Storage>(parseWrapper(is))}};
360 std::stringstream ss{str};
374 recorders.erase(std::find(recorders.begin(), recorders.end(),
this));
391 std::vector<std::string> out;
396 for (
auto const &item :
value.items()) {
397 if (
_read.count(item.key()) == 0) {
398 out.push_back(item.key());
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
JSONNode & makeNode(nlohmann::json &value, std::string key)
Storage(nlohmann::json value)
std::vector< JSONReadRecorder * > recorders
std::vector< JSONNode * > const & makeChildren(nlohmann::json &value)
void recordRead(void const *value, std::string const *key)
std::deque< std::vector< JSONNode * > > childLists
std::vector< std::unique_ptr< JSONNode > > nodes
JSONNode & operator[](std::string const &k)
JSONNode & get(std::string const &key)
double val_double() const
void erase(std::string const &key)
Remove a child of a map, if it exists.
bool is_container() const
void writeJSON(std::ostream &os) const
JSONNode & append_child()
JSONNode & operator<<(std::string const &s)
size_t num_children() const
JSONNode(JSONNode const &)=delete
const JSONNode & operator>>(std::string &v) const
bool has_child(std::string const &) const
JSONNode & child(size_t pos)
Records which components of a JSON map are read while it is alive, through any node of the tree.
std::set< std::string > _read
void record(void const *value, std::string const *key)
Called by the tree for every read of the component key of value, where nullptr means all components.
JSONReadRecorder(JSONNode const &node)
std::vector< std::string > unreadComponents() const
The components of the map that were not read.
static std::unique_ptr< JSONTree > create()
JSONTree(std::unique_ptr< JSONNode::Storage > storage)
std::unique_ptr< JSONNode::Storage > _storage
std::ostream & operator<<(std::ostream &os, RooFit::Detail::JSONNode const &s)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...