diff --git a/export/CMakeLists.txt b/export/CMakeLists.txt index df13ffd..6f61c8b 100644 --- a/export/CMakeLists.txt +++ b/export/CMakeLists.txt @@ -19,4 +19,3 @@ if (FMU4CPP_BUILD_TESTS) enable_testing() add_subdirectory(tests) endif () - diff --git a/export/include/fmu4cpp/logger.hpp b/export/include/fmu4cpp/logger.hpp index f756eb1..d85d19b 100644 --- a/export/include/fmu4cpp/logger.hpp +++ b/export/include/fmu4cpp/logger.hpp @@ -7,11 +7,12 @@ #include "fmi2/fmi2FunctionTypes.h" namespace fmu4cpp { + class logger { public: - logger(fmi2ComponentEnvironment c, fmi2CallbackFunctions f, std::string instanceName) - : c_(c), + logger(const fmi2CallbackFunctions &f, std::string instanceName) + : c_(f.componentEnvironment), fmiLogger_(f.logger), instanceName_(std::move(instanceName)) {} @@ -35,10 +36,11 @@ namespace fmu4cpp { } private: - bool debugLogging_{false}; - std::string instanceName_; fmi2ComponentEnvironment c_; fmi2CallbackLogger fmiLogger_; + + bool debugLogging_{false}; + std::string instanceName_; std::string msgBuf_; }; diff --git a/export/src/fmu4cpp/fmi2.cpp b/export/src/fmu4cpp/fmi2.cpp index db34e28..53276ee 100644 --- a/export/src/fmu4cpp/fmi2.cpp +++ b/export/src/fmu4cpp/fmi2.cpp @@ -15,10 +15,11 @@ namespace { // A struct that holds all the data for one model instance. struct Component { - Component(std::unique_ptr slave, fmi2CallbackFunctions callbackFunctions) + Component(std::unique_ptr slave, const fmi2CallbackFunctions &callbackFunctions) : lastSuccessfulTime{std::numeric_limits::quiet_NaN()}, slave(std::move(slave)), - logger(this->slave.get(), callbackFunctions, this->slave->instanceName()) { + logger(callbackFunctions, this->slave->instanceName()) { + this->slave->__set_logger(&logger); } @@ -81,7 +82,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, const auto guid = slave->guid(); if (guid != fmuGUID) { std::cerr << "[fmu4cpp] Error. Wrong guid!" << std::endl; - fmu4cpp::logger l(nullptr, *functions, instanceName); + fmu4cpp::logger l(*functions, instanceName); l.log(fmi2Fatal, "", "Error. Wrong guid!"); return nullptr; } @@ -107,9 +108,9 @@ fmi2Status fmi2SetupExperiment(fmi2Component c, try { component->slave->setup_experiment(startTime, stop, tol); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -120,9 +121,9 @@ fmi2Status fmi2EnterInitializationMode(fmi2Component c) { try { component->slave->enter_initialisation_mode(); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -132,9 +133,9 @@ fmi2Status fmi2ExitInitializationMode(fmi2Component c) { try { component->slave->exit_initialisation_mode(); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -144,9 +145,9 @@ fmi2Status fmi2Terminate(fmi2Component c) { try { component->slave->terminate(); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -177,7 +178,7 @@ fmi2Status fmi2DoStep( } } -fmi2Status fmi2CancelStep(fmi2Component c) { +fmi2Status fmi2CancelStep(fmi2Component) { return fmi2Error; } @@ -197,9 +198,9 @@ fmi2Status fmi2GetInteger( try { component->slave->get_integer(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -214,9 +215,9 @@ fmi2Status fmi2GetReal( try { component->slave->get_real(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -231,9 +232,9 @@ fmi2Status fmi2GetBoolean( try { component->slave->get_boolean(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -248,9 +249,9 @@ fmi2Status fmi2GetString( try { component->slave->get_string(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -265,9 +266,9 @@ fmi2Status fmi2SetInteger( try { component->slave->set_integer(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -282,9 +283,9 @@ fmi2Status fmi2SetReal( try { component->slave->set_real(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -299,9 +300,9 @@ fmi2Status fmi2SetBoolean( try { component->slave->set_boolean(vr, nvr, value); return fmi2OK; - } catch (const fmu4cpp::fatal_error &ex) { + } catch (const fmu4cpp::fatal_error &) { return fmi2Fatal; - } catch (const std::exception &ex) { + } catch (const std::exception &) { return fmi2Error; } } @@ -385,7 +386,7 @@ fmi2Status fmi2SetRealInputDerivatives(fmi2Component, return fmi2Error; } -fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, +fmi2Status fmi2GetRealOutputDerivatives(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Integer[], fmi2Real[]) { @@ -404,6 +405,7 @@ fmi2Status fmi2GetDirectionalDerivative(fmi2Component, fmi2Status fmi2GetFMUstate(fmi2Component, fmi2FMUstate *) { + return fmi2Error; } @@ -436,5 +438,4 @@ void fmi2FreeInstance(fmi2Component c) { const auto component = static_cast(c); delete component; } - } diff --git a/export/src/fmu4cpp/fmu_base.cpp b/export/src/fmu4cpp/fmu_base.cpp index ef3a6cb..a08cd20 100644 --- a/export/src/fmu4cpp/fmu_base.cpp +++ b/export/src/fmu4cpp/fmu_base.cpp @@ -16,25 +16,26 @@ namespace { const std::vector &v2, const std::vector &v3, const std::vector &v4, - const std::function &f = [](auto &v) { return true; }) { + const std::function &predicate = [](auto &v) { return true; }) { + std::vector vars; for (const fmu4cpp::VariableBase &v: v1) { - if (f(v)) { + if (predicate(v)) { vars.push_back(v); } } for (const fmu4cpp::VariableBase &v: v2) { - if (f(v)) { + if (predicate(v)) { vars.push_back(v); } } for (const fmu4cpp::VariableBase &v: v3) { - if (f(v)) { + if (predicate(v)) { vars.push_back(v); } } for (const fmu4cpp::VariableBase &v: v4) { - if (f(v)) { + if (predicate(v)) { vars.push_back(v); } } @@ -62,9 +63,8 @@ namespace fmu4cpp { std::string fmu_base::make_description() const { + const model_info m = get_model_info(); std::stringstream ss; - model_info m = get_model_info(); - ss << R"()" << "\n" << R"(\n"; for (const auto &v: integers_) { - auto variability = v.variability(); - auto initial = v.initial(); + const auto variability = v.variability(); + const auto initial = v.initial(); ss << "\t\t\n"; for (const auto &v: outputs) { ss << "\t\t\t content{ + const model_info info = get_model_info(); + const std::vector content{ info.author, info.version, info.modelIdentifier, @@ -266,7 +266,7 @@ namespace fmu4cpp { ss << str; } - auto vars = collect(integers_, reals_, booleans_, strings_); + const auto vars = collect(integers_, reals_, booleans_, strings_); for (const auto &v: vars) { ss << v.name(); ss << std::to_string(v.index());