1616
1717#include < filesystem>
1818
19- #define FMU4CPP_INSTANTIATE (MODELCLASS ) \
20- std::unique_ptr<fmu4cpp::fmu_base> fmu4cpp::createInstance (const std::string &instanceName, \
21- const std::filesystem::path &fmuResourceLocation) { \
22- return std::make_unique<MODELCLASS>(instanceName, fmuResourceLocation); \
19+ #define FMU4CPP_INSTANTIATE (MODELCLASS ) \
20+ std::unique_ptr<fmu4cpp::fmu_base> fmu4cpp::createInstance (const fmu4cpp::fmu_data &data) { \
21+ return std::make_unique<MODELCLASS>(data); \
2322 }
2423
2524namespace fmu4cpp {
2625
26+ struct fmu_data {
27+ logger *logger{nullptr };
28+ std::string instance_name{};
29+ std::filesystem::path resourceLocation{};
30+ };
31+
2732 class fmu_base {
2833
2934 public:
30- fmu_base (std::string instance_name, std::filesystem::path resourceLocation )
31- : instanceName_ (std::move(instance_name)), resourceLocation_(std::move(resourceLocation )) {
35+ explicit fmu_base (fmu_data data )
36+ : data_ (std::move(data )) {
3237
3338 register_variable (real (" time" , &time_)
3439 .setCausality (causality_t ::INDEPENDENT)
@@ -39,11 +44,11 @@ namespace fmu4cpp {
3944 fmu_base (const fmu_base &&) = delete ;
4045
4146 [[nodiscard]] std::string instanceName () const {
42- return instanceName_ ;
47+ return data_. instance_name ;
4348 }
4449
4550 [[nodiscard]] const std::filesystem::path &resourceLocation () const {
46- return resourceLocation_ ;
51+ return data_. resourceLocation ;
4752 }
4853
4954 [[nodiscard]] std::optional<IntVariable> get_int_variable (const std::string &name) const {
@@ -200,13 +205,9 @@ namespace fmu4cpp {
200205
201206 [[nodiscard]] std::string make_description_v3 () const ;
202207
203- void __set_logger (logger *logger) {
204- logger_ = logger;
205- }
206-
207208 void log (const fmiStatus s, const std::string &message) const {
208- if (logger_ ) {
209- logger_ ->log (s, message);
209+ if (data_. logger ) {
210+ data_. logger ->log (s, message);
210211 }
211212 }
212213
@@ -265,15 +266,13 @@ namespace fmu4cpp {
265266 }
266267
267268 private:
268- double time_{0 };
269- std::optional<double > stop_;
270- std::optional<double > tolerance_;
269+ fmu_data data_;
271270
272- logger *logger_ = nullptr ;
271+ double time_{ 0 } ;
273272 size_t numVariables_{0 };
274273
275- std::string instanceName_ ;
276- std::filesystem::path resourceLocation_ ;
274+ std::optional< double > stop_ ;
275+ std::optional< double > tolerance_ ;
277276
278277 std::vector<IntVariable> integers_;
279278 std::unordered_map<unsigned int , size_t > vrToIntegerIndices_;
@@ -291,7 +290,7 @@ namespace fmu4cpp {
291290
292291 model_info get_model_info ();
293292
294- std::unique_ptr<fmu_base> createInstance (const std::string &instanceName, const std::filesystem::path &fmuResourceLocation );
293+ std::unique_ptr<fmu_base> createInstance (const fmu_data &data );
295294
296295}// namespace fmu4cpp
297296
0 commit comments