helics 3.7.0
Loading...
Searching...
No Matches
helicsCLI11JsonConfig.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7
8#pragma once
9
10#include "helicsCLI11.hpp"
11
12#include <nlohmann/json_fwd.hpp>
13#include <string>
14#include <utility>
15#include <vector>
16
17namespace helics {
19class HelicsConfigJSON: public CLI::ConfigBase {
20 public:
21 std::vector<CLI::ConfigItem> from_config(std::istream& input) const override final;
22
24 void skipJson(bool skj = true) { mSkipJson = skj; }
26 void fallbackToDefault(bool ftd = true) { mFallbackToDefault = ftd; }
28 void throwJsonErrors(bool the = true) { mThrowJsonErrors = the; }
29 void promoteSection(std::string sectionName) { mPromoteSection = std::move(sectionName); }
30
31 private:
32 bool mSkipJson{false};
33 bool mFallbackToDefault{false};
34 bool mThrowJsonErrors{true};
35 std::string mPromoteSection;
37 std::vector<CLI::ConfigItem>
38 fromConfigInternal(const nlohmann::json& json,
39 const std::string& name = {},
40 const std::vector<std::string>& prefix = {}) const;
41};
43HelicsConfigJSON* addJsonConfig(CLI::App* app);
44
45} // namespace helics
Define a JSON parser for the config files for CLI11.
Definition helicsCLI11JsonConfig.hpp:19
void skipJson(bool skj=true)
skip checking the JSON and go directly to the TOML processing
Definition helicsCLI11JsonConfig.hpp:24
void throwJsonErrors(bool the=true)
throw if the json processing produces errors
Definition helicsCLI11JsonConfig.hpp:28
void fallbackToDefault(bool ftd=true)
if the specified section isn't available use the root section
Definition helicsCLI11JsonConfig.hpp:26
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
HelicsConfigJSON * addJsonConfig(CLI::App *app)
Add the HELICS JSON configuration processor to the app.
Definition helicsCLI11JsonConfig.cpp:120