openPMD-api
 
Loading...
Searching...
No Matches
JSONMatcher.hpp
1#pragma once
2
3/* Copyright 2021-2024 Franz Poeschel
4 *
5 * This file is part of openPMD-api.
6 *
7 * openPMD-api is free software: you can redistribute it and/or modify
8 * it under the terms of of either the GNU General Public License or
9 * the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * openPMD-api is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License and the GNU Lesser General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * and the GNU Lesser General Public License along with openPMD-api.
21 * If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "openPMD/auxiliary/JSON_internal.hpp"
25
26#include <regex>
27#include <string>
28#include <vector>
29
30namespace openPMD::json
31{
32struct Pattern
33{
34 std::regex pattern;
35 nlohmann::json config;
36
37 Pattern(std::string const &pattern_in, nlohmann::json config_in);
38};
39
45{
46private:
47 std::vector<Pattern> m_patterns;
48
49 void init(TracingJSON config);
50
51public:
56
69 MatcherPerBackend(std::string backendName, TracingJSON config);
70
71 std::string backendName;
72
79 auto get(std::string const &datasetPath) const -> nlohmann::json const &;
80};
81
89{
90private:
91 // Only one backend matcher is initialized lazily upon calling
92 // JsonMatcher::get()
93 // Usually only one backend is active, so initializing all of them
94 // is not necessary.
95 MatcherPerBackend m_backendMatcher;
96 TracingJSON m_entireConfig;
97
98 auto init() -> void;
99
100public:
104 explicit JsonMatcher();
105
119
127 auto get(std::string const &datasetPath, std::string const &backendName)
128 -> ParsedConfig;
129
136 auto getDefault(std::string const &backendName) -> TracingJSON;
137
138 auto initBackendLazily(std::string const &backendName) -> void;
139};
140} // namespace openPMD::json
JsonMatcher()
For default construction.
auto getDefault(std::string const &backendName) -> TracingJSON
Get the default JSON config.
Definition JSONMatcher.cpp:170
auto get(std::string const &datasetPath, std::string const &backendName) -> ParsedConfig
Get the JSON config associated with a regex pattern.
Definition JSONMatcher.cpp:150
Matcher for dataset configurations per backend.
Definition JSONMatcher.hpp:45
auto get(std::string const &datasetPath) const -> nlohmann::json const &
Get the JSON config associated with a regex pattern.
Definition JSONMatcher.cpp:110
MatcherPerBackend()
For default construction.
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition JSON_internal.hpp:69
Definition JSON_internal.hpp:50