helics  3.5.2
helicsCLI11JsonConfig.hpp
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 #pragma once
9 
10 #include "helicsCLI11.hpp"
11 
12 #include "json/forwards.h"
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 namespace helics {
19 class 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(Json::Value json,
39  const std::string& name = {},
40  const std::vector<std::string>& prefix = {}) const;
41 };
43 HelicsConfigJSON* 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:117