Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
DBNode.h
Go to the documentation of this file.
1#ifndef DBNODE_H
2#define DBNODE_H
3
4#include <iostream>
5#include <map>
6#include <vector>
7#include <string>
8#include <memory>
9#include <fstream>
10#include <sstream>
11#include <variant>
12#include <initializer_list>
13#include <stdexcept>
14#include <algorithm>
15
16#include "BlockName.h"
17
33class DBNode {
34public:
45 using Value = std::variant<BlockName, int, double, bool, std::shared_ptr<DBNode>, std::vector<std::shared_ptr<DBNode>>>;
46
47
54
76 template <typename... Keys>
77 Value get(Keys&&... keys) const;
78
87 std::vector<BlockName> get_keys();
88
104 template <typename T, typename Key, typename... Rest>
105 void set(T value, Key&& key, Rest&&... rest);
106
119 std::map<BlockName, Value> getGroup(const std::vector<BlockName>& keys) const;
120
131 void setGroup(const std::vector<BlockName>& keys, const std::map<BlockName, Value>& groupData);
132
141 void printJSON(int level = 0) const;
142
149 void printJSONToStream(std::ostream& os, int level = 0) const;
150
160 void printYAMLToStream(std::ostream& os, int level = 0) const;
161
167 void printYAML(int level = 0) const;
168
178 bool contains(const BlockName& key) const;
179
185 int countChildren() const;
186
194 bool isList() const;
195private:
197 std::map<BlockName, Value> data_;
198
199 // Recursive lookup helpers used by get(...).
200
207 template <typename Map, typename Key>
208 Value getRecursive(const Map& map, Key&& key) const;
209
217 template <typename Map, typename Key, typename Next, typename... Rest>
218
220 Value getRecursive(const Map& map, Key&& key, Next&& next, Rest&&... rest) const;
221
223 void printValue(const Value& value, int level) const;
224
226 void printValueToStream(std::ostream& os, const Value& value, int level) const;
227
228 // YAML helper: prints a scalar Value to an arbitrary stream.
229 void printScalarYAMLToStream(std::ostream& os, const Value& value) const;
230
232 void printScalarYAML(const Value& value) const;
233
240 bool isListDBNode(const std::shared_ptr<DBNode>& node) const;
241};
242
243#include "DBNode.tpp"
244
245#endif
Representation of SLHA / LHA block names with support for aliases.
Block identifier with alias support.
Definition BlockName.h:59
void setGroup(const std::vector< BlockName > &keys, const std::map< BlockName, Value > &groupData)
Sets the content of a whole sub-tree from a map of values.
Definition DBNode.cpp:30
Value get(Keys &&... keys) const
Retrieves a value from the node using a sequence of keys.
void printYAMLToStream(std::ostream &os, int level=0) const
Prints the node in YAML format to a given output stream.
Definition DBNode.cpp:286
DBNode()
Default constructor.
std::map< BlockName, Value > getGroup(const std::vector< BlockName > &keys) const
Retrieves a whole sub-tree as a map from a path of keys.
Definition DBNode.cpp:13
int countChildren() const
Returns the number of direct children of this node.
Definition DBNode.cpp:270
void set(T value, Key &&key, Rest &&... rest)
Sets a value in the node using a sequence of keys.
std::variant< BlockName, int, double, bool, std::shared_ptr< DBNode >, std::vector< std::shared_ptr< DBNode > > > Value
Variant type used to store values in the tree.
Definition DBNode.h:45
std::vector< BlockName > get_keys()
Returns all the keys stored at the current node level.
Definition DBNode.cpp:5
bool contains(const BlockName &key) const
Checks whether the node contains a direct child with the given key.
Definition DBNode.cpp:263
void printJSON(int level=0) const
Prints the node in JSON format to std::cout.
Definition DBNode.cpp:55
void printYAML(int level=0) const
Prints the node in YAML format to std::cout.
Definition DBNode.cpp:148
void printJSONToStream(std::ostream &os, int level=0) const
Prints the node in JSON format to a given output stream.
Definition DBNode.cpp:105
bool isList() const
Returns true if this node represents a "list" node.
double T(double x)
Wilson coefficient T(x).