Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
mainjson.cpp
Go to the documentation of this file.
1#include "Json.h"
2
3int main() {
4
6
7 auto root = std::make_shared<Node>();
8
9 root->set("wowow", "1", "2", "3");
10 root->set("wowo2w", "1", "2", "4");
11 root->set(42.5, "level1", "level2", "sdf");
12 root->set("value", "level1", "level2", "ERER");
13
14 std::cout << "Structure JSON générée :\n";
15 root->printJSON();
16 std::cout << "\n";
17
18 try {
19 auto value = std::get<BlockName>(root->get("1", "2", "3"));
20 std::cout << "Valeur de [1, 2, 3] : " << value << "\n";
21 } catch (const std::exception& e) {
22 std::cerr << "Erreur : " << e.what() << "\n";
23 }
24
25 try {
26 auto group = root->getGroup({"1", "2"});
27 std::cout << "Groupe sous [1, 2] :\n";
28 for (const auto& [key, val] : group) {
29 std::cout << "- " << key << " : ";
30 if (std::holds_alternative<BlockName>(val)) {
31 std::cout << std::get<BlockName>(val);
32 } else if (std::holds_alternative<int>(val)) {
33 std::cout << std::get<int>(val);
34 } else if (std::holds_alternative<double>(val)) {
35 std::cout << std::get<double>(val);
36 }
37 std::cout << "\n";
38 }
39 } catch (const std::exception& e) {
40 std::cerr << "Erreur : " << e.what() << "\n";
41 }
42
43 std::map<std::string, Node::Value> newGroup = {
44 {"newKey1", "newValue1"},
45 {"newKey2", 12345},
46 {"newKey3", false},
47 };
48 root->setGroup({"1", "2", "5"}, newGroup);
49
50 std::cout << "Structure JSON après setGroup :\n";
51 root->printJSON();
52 std::cout << "\n";
53
54 std::cout << "Structure YAML générée :\n";
55 root->printYAML();
56 parser->writeToFile("output.json", root);
57
58 try {
59 auto newRoot = parser->readFromFile("output.json");
60 std::cout << "\nFichier JSON lu avec succès.\n";
61 newRoot->printJSON();
62 } catch (const std::exception& e) {
63 std::cerr << "Erreur lors de la lecture : " << e.what() << "\n";
64 }
65
66 return 0;
67}
static std::shared_ptr< IParser > createParser(Type type)
Creates a parser instance of the specified type.
int main()
Definition mainjson.cpp:3