helics  3.0.1
helicsApp.hpp
1 /*
2 Copyright (c) 2017-2021,
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 <vector>
14 
15 namespace CLI {
16 class App;
17 } // namespace CLI
18 namespace Json {
19 class Value;
20 } // namespace Json
21 
22 namespace helics {
23 namespace apps {
28  class HELICS_CXX_EXPORT App {
29  public:
31  App() = default;
36  App(const std::string& defaultAppName, std::vector<std::string> args);
42  App(const std::string& defaultAppName, int argc, char* argv[]);
47  App(const std::string& appName, const FederateInfo& fi);
53  App(const std::string& appName, const std::shared_ptr<Core>& core, const FederateInfo& fi);
59  App(const std::string& appName, CoreApp& core, const FederateInfo& fi);
65  App(const std::string& appName, const std::string& jsonString);
66 
68  App(App&& other_app) = default;
70  App(const App& other_app) = delete;
72  App& operator=(App&& app) = default;
75  App& operator=(const App& app) = delete;
76  virtual ~App();
77 
81  void loadFile(const std::string& filename);
88  virtual void initialize();
89  /*run the Player*/
90  virtual void run();
91 
95  virtual void runTo(Time stopTime_input) = 0;
96 
98  virtual void finalize();
99 
101  bool isActive() const { return !deactivated; }
103  const CombinationFederate& accessUnderlyingFederate() const { return *fed; }
104 
105  protected:
109  virtual void loadJsonFile(const std::string& jsonString);
115  void loadJsonFileConfiguration(const std::string& appName, const std::string& jsonString);
117  virtual void loadTextFile(const std::string& textFile);
118 
119  private:
120  void loadConfigOptions(const Json::Value& element);
122  std::unique_ptr<helicsCLI11App> generateParser();
124  void processArgs(std::unique_ptr<helicsCLI11App>& app, const std::string& defaultAppName);
125 
126  protected:
127  std::shared_ptr<CombinationFederate> fed;
128  Time stopTime = Time::maxVal();
129  std::string masterFileName;
130  bool useLocal{false};
131  bool fileLoaded{false};
132  bool deactivated{false};
133  bool quietMode{false};
134  bool helpMode{false};
135  std::vector<std::string> remArgs;
136  };
137 } // namespace apps
138 } // namespace helics
helics::apps::App::loadJsonFile
virtual void loadJsonFile(const std::string &jsonString)
Definition: helicsApp.cpp:154
helics::apps::App::runTo
virtual void runTo(Time stopTime_input)=0
helics::apps::App::accessUnderlyingFederate
const CombinationFederate & accessUnderlyingFederate() const
Definition: helicsApp.hpp:103
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:129
helics::apps::App::loadJsonFileConfiguration
void loadJsonFileConfiguration(const std::string &appName, const std::string &jsonString)
Definition: helicsApp.cpp:159
helics::apps::App::finalize
virtual void finalize()
Definition: helicsApp.cpp:205
helics::FederateInfo
Definition: FederateInfo.hpp:20
helics::apps::App::isActive
bool isActive() const
Definition: helicsApp.hpp:101
helics::apps::App::loadTextFile
virtual void loadTextFile(const std::string &textFile)
Definition: helicsApp.cpp:134
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:197
helics::apps::App::fed
std::shared_ptr< CombinationFederate > fed
the federate created for the Player
Definition: helicsApp.hpp:127
helics::apps::App::App
App()=default
helics::apps::App::stopTime
Time stopTime
the time the Player should stop
Definition: helicsApp.hpp:128
helics::apps::App
Definition: helicsApp.hpp:28
helics::Federate::Modes::STARTUP
@ STARTUP
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:124
helics::CombinationFederate
Definition: application_api/CombinationFederate.hpp:18