helics  3.6.1
FederateInfo.hpp
1 /*
2 Copyright (c) 2017-2025,
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 helics {
21 class helicsCLI11App;
22 
23 namespace fileops {
24  class JsonBuffer;
25 }
28 class HELICS_CXX_EXPORT FederateInfo: public CoreFederateInfo {
29  public:
30  int uniqueKey{0};
31  char separator{'/'};
32  bool autobroker{
33  false};
36  bool debugging{false};
37  bool observer{false};
39  int brokerPort{-1};
40 
41  bool forceNewCore{false};
43  bool useJsonSerialization{false};
45  bool encrypted{false};
48  std::string profilerFileName;
49  std::string encryptionConfig;
50  std::string defName;
51  std::string coreName;
52  std::string coreInitString;
53  std::string brokerInitString;
54  std::string broker;
55  std::string key;
56  std::string localport;
58 
59  std::string configString;
60  bool fileInUse{false};
62  FederateInfo();
65  explicit FederateInfo(CoreType cType);
70  explicit FederateInfo(const std::string& args);
76  FederateInfo(int argc, char* argv[]);
82  explicit FederateInfo(std::vector<std::string>& args);
87  std::vector<std::string> loadInfoFromArgs(const std::string& args);
93  std::vector<std::string> loadInfoFromArgs(int argc, char* argv[]);
98  void loadInfoFromArgs(std::vector<std::string>& args);
102  void loadInfoFromArgsIgnoreOutput(const std::string& args);
107  void loadInfoFromArgsIgnoreOutput(int argc, char* argv[]);
108 
112  void loadInfoFromToml(const std::string& toml, bool runArgParser = true);
113 
117  void loadInfoFromJson(const std::string& json, bool runArgParser = true);
118 
120  Time checkTimeProperty(int propId, Time defVal) const;
121  bool checkFlagProperty(int propId, bool defVal) const;
122  int checkIntProperty(int propId, int defVal) const;
123 
125  void injectParser(CLI::App* app);
126 
127  private:
128  std::unique_ptr<helicsCLI11App> makeCLIApp();
130  void config_additional(CLI::App* app);
132  void loadJsonConfig(const fileops::JsonBuffer& json);
133 };
134 
137 HELICS_CXX_EXPORT FederateInfo loadFederateInfo(const std::string& configString);
138 
140 HELICS_CXX_EXPORT std::string generateFullCoreInitString(const FederateInfo& fedInfo);
141 
147 HELICS_CXX_EXPORT int getPropertyIndex(std::string val);
148 
154 HELICS_CXX_EXPORT int getFlagIndex(std::string val);
155 
161 HELICS_CXX_EXPORT int getOptionIndex(std::string val);
162 
167 HELICS_CXX_EXPORT int getOptionValue(std::string val);
168 
169 } // namespace helics
Definition: CoreFederateInfo.hpp:16
Definition: FederateInfo.hpp:28
std::string broker
connection information for the broker
Definition: FederateInfo.hpp:54
std::string defName
a default name to use for a federate
Definition: FederateInfo.hpp:50
std::string configString
storage for config file name or string
Definition: FederateInfo.hpp:59
std::string brokerInitString
an initialization string for the broker if auto generated
Definition: FederateInfo.hpp:53
std::string profilerFileName
Definition: FederateInfo.hpp:48
std::string key
key for the broker
Definition: FederateInfo.hpp:55
std::string encryptionConfig
encryption configuration string or file
Definition: FederateInfo.hpp:49
std::string localport
Definition: FederateInfo.hpp:56
std::string coreName
the name of the core
Definition: FederateInfo.hpp:51
std::string coreInitString
an initialization string for the core API object
Definition: FederateInfo.hpp:52
Definition: JsonProcessingFunctions.hpp:25
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:783
CoreType
Definition: CoreTypes.hpp:46
@ DEFAULT
ZMQ if available or UDP.
int getFlagIndex(std::string val)
Definition: FederateInfo.cpp:412
int getOptionIndex(std::string val)
Definition: FederateInfo.cpp:431
int getOptionValue(std::string val)
Definition: FederateInfo.cpp:450
std::string generateFullCoreInitString(const FederateInfo &fedInfo)
Definition: FederateInfo.cpp:1014
int getPropertyIndex(std::string val)
Definition: FederateInfo.cpp:389
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27