Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
JsonParser.h
Go to the documentation of this file.
1#ifndef JSONPARSER_H
2#define JSONPARSER_H
3
4#include <memory>
5#include <string>
6#include <cctype>
7#include <stdexcept>
8#include <algorithm>
9#include <stack>
10
11#include "DBNode.h"
12#include "IParser.h"
13#include "Logger.h"
14
42class JSONParser : public IParser {
43public:
54 std::shared_ptr<DBNode> parse(const std::string& input) const override;
55
67 void writeToFile(const std::string& filename, const std::shared_ptr<DBNode>& root) const override;
68
79 std::shared_ptr<DBNode> readFromFile(const std::string& filename) const override;
80
101 std::shared_ptr<DBNode> parseObject(const std::string& input, size_t& index) const;
102
117 std::string parseString(const std::string& input, size_t& index) const;
118
140 DBNode::Value parseValue(const std::string& input, size_t& index) const;
141
158 double parseNumber(const std::string& input, size_t& index) const;
159
169 void skipWhitespace(const std::string& input, size_t& index) const;
170
186 std::shared_ptr<DBNode> parseArray(const std::string& input, size_t& index) const;
187
188};
189
190#endif // PARSER_H
Hierarchical key–value tree with JSON/YAML serialization.
Abstract interface for (de)serializing data as DBNode trees.
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
Abstract base class for data parsers.
Definition IParser.h:30
JSON implementation of the IParser interface.
Definition JsonParser.h:42
void writeToFile(const std::string &filename, const std::shared_ptr< DBNode > &root) const override
Serializes a DBNode tree to a JSON file.
std::shared_ptr< DBNode > parseArray(const std::string &input, size_t &index) const
Parses a JSON array starting at the current position.
DBNode::Value parseValue(const std::string &input, size_t &index) const
Parses any JSON value at the current position.
std::shared_ptr< DBNode > parseObject(const std::string &input, size_t &index) const
Parses a JSON object starting at the given index.
Definition JsonParser.cpp:9
std::shared_ptr< DBNode > readFromFile(const std::string &filename) const override
Reads a JSON file and parses it into a DBNode tree.
double parseNumber(const std::string &input, size_t &index) const
Parses a JSON number (integer or floating point).
std::shared_ptr< DBNode > parse(const std::string &input) const override
Parses a JSON document from an in-memory string.
Definition JsonParser.cpp:3
std::string parseString(const std::string &input, size_t &index) const
Parses a JSON string literal.
void skipWhitespace(const std::string &input, size_t &index) const
Skips whitespace characters in the input string.