helics  3.3.0
helicsApp.hpp
1 /*
2 Copyright (c) 2017-2022,
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 
9 #include "../application_api/CombinationFederate.hpp"
10 
11 #include <memory>
12 #include <string>
13 #include <string_view>
14 #include <vector>
15 
16 namespace CLI {
17 class App;
18 } // namespace CLI
19 namespace Json {
20 class Value;
21 } // namespace Json
22 
23 namespace helics {
24 namespace apps {
29  class HELICS_CXX_EXPORT App {
30  public:
32  App() = default;
37  App(std::string_view defaultAppName, std::vector<std::string> args);
43  App(std::string_view defaultAppName, int argc, char* argv[]);
48  App(std::string_view appName, const FederateInfo& fi);
54  App(std::string_view appName, const std::shared_ptr<Core>& core, const FederateInfo& fi);
60  App(std::string_view appName, CoreApp& core, const FederateInfo& fi);
66  App(std::string_view appName, const std::string& jsonString);
67 
69  App(App&& other_app) = default;
71  App(const App& other_app) = delete;
73  App& operator=(App&& app) = default;
76  App& operator=(const App& app) = delete;
77  virtual ~App();
78 
82  void loadFile(const std::string& filename);
89  virtual void initialize();
90  /*run the Player*/
91  virtual void run();
92 
96  virtual void runTo(Time stopTime_input) = 0;
97 
99  virtual void finalize();
100 
102  bool isActive() const { return !deactivated; }
104  const CombinationFederate& accessUnderlyingFederate() const { return *fed; }
105 
106  protected:
110  virtual void loadJsonFile(const std::string& jsonString);
116  void loadJsonFileConfiguration(const std::string& appName, const std::string& jsonString);
118  virtual void loadTextFile(const std::string& textFile);
119 
120  private:
121  void loadConfigOptions(const Json::Value& element);
123  std::unique_ptr<helicsCLI11App> generateParser();
125  void processArgs(std::unique_ptr<helicsCLI11App>& app,
126  FederateInfo& fi,
127  std::string_view defaultAppName);
128 
129  protected:
130  std::shared_ptr<CombinationFederate> fed;
131  Time stopTime = Time::maxVal();
132  std::string masterFileName;
133  bool useLocal{false};
134  bool fileLoaded{false};
135  bool deactivated{false};
136  bool quietMode{false};
137  bool helpMode{false};
138  std::vector<std::string> remArgs;
139  };
140 } // namespace apps
141 } // namespace helics
helics::apps::App::loadJsonFile
virtual void loadJsonFile(const std::string &jsonString)
Definition: helicsApp.cpp:153
helics::apps::App::runTo
virtual void runTo(Time stopTime_input)=0
helics::apps::App::accessUnderlyingFederate
const CombinationFederate & accessUnderlyingFederate() const
Definition: helicsApp.hpp:104
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::apps::App::masterFileName
std::string masterFileName
the name of the master file used to do the construction
Definition: helicsApp.hpp:132
helics::apps::App::loadJsonFileConfiguration
void loadJsonFileConfiguration(const std::string &appName, const std::string &jsonString)
Definition: helicsApp.cpp:158
helics::apps::App::finalize
virtual void finalize()
Definition: helicsApp.cpp:204
helics::FederateInfo
Definition: FederateInfo.hpp:24
helics::apps::App::isActive
bool isActive() const
Definition: helicsApp.hpp:102
helics::FederateInfo::injectParser
void injectParser(CLI::App *app)
Definition: FederateInfo.cpp:449
helics::apps::App::loadTextFile
virtual void loadTextFile(const std::string &textFile)
Definition: helicsApp.cpp:133
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::apps::App::initialize
virtual void initialize()
Definition: helicsApp.cpp:196
helics::apps::App::fed
std::shared_ptr< CombinationFederate > fed
the federate created for the Player
Definition: helicsApp.hpp:130
helics::apps::App::App
App()=default
helics::apps::App::stopTime
Time stopTime
the time the Player should stop
Definition: helicsApp.hpp:131
helics::apps::App
Definition: helicsApp.hpp:29
helics::Federate::Modes::STARTUP
@ STARTUP
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:123
helics::FederateInfo::defName
std::string defName
a default name to use for a federate
Definition: FederateInfo.hpp:46
helics::CombinationFederate
Definition: application_api/CombinationFederate.hpp:18