helics  3.5.2
FederateInfo.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 #pragma once
8 #include "../core/CoreFederateInfo.hpp"
9 #include "../core/CoreTypes.hpp"
10 #include "helics_cxx_export.h"
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 namespace CLI {
17 class App;
18 }
19 
20 namespace Json {
21 class Value;
22 }
23 
24 namespace helics {
25 class helicsCLI11App;
26 
29 class HELICS_CXX_EXPORT FederateInfo: public CoreFederateInfo {
30  public:
31  int uniqueKey{0};
32  char separator{'/'};
33  bool autobroker{
34  false};
37  bool debugging{false};
38  bool observer{false};
40  int brokerPort{-1};
41 
42  bool forceNewCore{false};
44  bool useJsonSerialization{false};
46  bool encrypted{false};
49  std::string profilerFileName;
50  std::string encryptionConfig;
51  std::string defName;
52  std::string coreName;
53  std::string coreInitString;
54  std::string brokerInitString;
55  std::string broker;
56  std::string key;
57  std::string localport;
59 
60  std::string configString;
61  bool fileInUse{false};
63  FederateInfo();
66  explicit FederateInfo(CoreType cType);
71  explicit FederateInfo(const std::string& args);
77  FederateInfo(int argc, char* argv[]);
83  explicit FederateInfo(std::vector<std::string>& args);
88  std::vector<std::string> loadInfoFromArgs(const std::string& args);
94  std::vector<std::string> loadInfoFromArgs(int argc, char* argv[]);
99  void loadInfoFromArgs(std::vector<std::string>& args);
103  void loadInfoFromArgsIgnoreOutput(const std::string& args);
108  void loadInfoFromArgsIgnoreOutput(int argc, char* argv[]);
109 
113  void loadInfoFromToml(const std::string& toml, bool runArgParser = true);
114 
118  void loadInfoFromJson(const std::string& json, bool runArgParser = true);
119 
121  Time checkTimeProperty(int propId, Time defVal) const;
122  bool checkFlagProperty(int propId, bool defVal) const;
123  int checkIntProperty(int propId, int defVal) const;
124 
126  void injectParser(CLI::App* app);
127 
128  private:
129  std::unique_ptr<helicsCLI11App> makeCLIApp();
131  void config_additional(CLI::App* app);
133  void loadJsonConfig(Json::Value& json);
134 };
135 
138 HELICS_CXX_EXPORT FederateInfo loadFederateInfo(const std::string& configString);
139 
141 HELICS_CXX_EXPORT std::string generateFullCoreInitString(const FederateInfo& fedInfo);
142 
148 HELICS_CXX_EXPORT int getPropertyIndex(std::string val);
149 
155 HELICS_CXX_EXPORT int getFlagIndex(std::string val);
156 
162 HELICS_CXX_EXPORT int getOptionIndex(std::string val);
163 
168 HELICS_CXX_EXPORT int getOptionValue(std::string val);
169 
170 } // namespace helics
Definition: CoreFederateInfo.hpp:16
Definition: FederateInfo.hpp:29
std::string broker
connection information for the broker
Definition: FederateInfo.hpp:55
std::string defName
a default name to use for a federate
Definition: FederateInfo.hpp:51
std::string configString
storage for config file name or string
Definition: FederateInfo.hpp:60
std::string brokerInitString
an initialization string for the broker if auto generated
Definition: FederateInfo.hpp:54
std::string profilerFileName
Definition: FederateInfo.hpp:49
std::string key
key for the broker
Definition: FederateInfo.hpp:56
std::string encryptionConfig
encryption configuration string or file
Definition: FederateInfo.hpp:50
std::string localport
Definition: FederateInfo.hpp:57
std::string coreName
the name of the core
Definition: FederateInfo.hpp:52
std::string coreInitString
an initialization string for the core API object
Definition: FederateInfo.hpp:53
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
FederateInfo loadFederateInfo(const std::string &configString)
Definition: FederateInfo.cpp:775
CoreType
Definition: CoreTypes.hpp:46
@ DEFAULT
ZMQ if available or UDP.
int getFlagIndex(std::string val)
Definition: FederateInfo.cpp:408
int getOptionIndex(std::string val)
Definition: FederateInfo.cpp:427
int getOptionValue(std::string val)
Definition: FederateInfo.cpp:446
std::string generateFullCoreInitString(const FederateInfo &fedInfo)
Definition: FederateInfo.cpp:1005
int getPropertyIndex(std::string val)
Definition: FederateInfo.cpp:385
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27