From 0bcd855e714ee2bba0a0060c6e6be0929206131c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 04:47:17 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/helics/apps/helicsApp.hpp | 3 +- src/helics/helics_apps.hpp | 4 +- src/helics/shared_api_library/CMakeLists.txt | 31 ++-- .../shared_api_library/FederateExport.cpp | 37 ++--- src/helics/shared_api_library/api-data.h | 4 +- src/helics/shared_api_library/helicsApps.h | 154 +++++++++--------- .../shared_api_library/helicsAppsExport.cpp | 146 +++++++---------- .../helicsAppsExportNull.cpp | 35 ++-- .../shared_api_library/helicsExport.cpp | 11 +- .../shared_api_library/internal/api_objects.h | 11 +- 10 files changed, 196 insertions(+), 240 deletions(-) diff --git a/src/helics/apps/helicsApp.hpp b/src/helics/apps/helicsApp.hpp index f285d0f4dc..e20afca1ac 100644 --- a/src/helics/apps/helicsApp.hpp +++ b/src/helics/apps/helicsApp.hpp @@ -112,7 +112,8 @@ necessary const CombinationFederate& accessUnderlyingFederate() const { return *fed; } /** get a copy of the federate pointer (this can be dangerous if misused) */ - std::shared_ptr getUnderlyingFederatePointer() {return fed;} + std::shared_ptr getUnderlyingFederatePointer() { return fed; } + protected: /** load from a jsonString @param jsonString either a JSON filename or a string containing JSON diff --git a/src/helics/helics_apps.hpp b/src/helics/helics_apps.hpp index d3c02de612..a709fd1670 100644 --- a/src/helics/helics_apps.hpp +++ b/src/helics/helics_apps.hpp @@ -11,11 +11,11 @@ Header file for inclusion of the entire apps library #pragma once #include "apps/BrokerApp.hpp" +#include "apps/Clone.hpp" #include "apps/Connector.hpp" #include "apps/Echo.hpp" #include "apps/Player.hpp" +#include "apps/Probe.hpp" #include "apps/Recorder.hpp" #include "apps/Source.hpp" #include "apps/Tracer.hpp" -#include "apps/Probe.hpp" -#include "apps/Clone.hpp" diff --git a/src/helics/shared_api_library/CMakeLists.txt b/src/helics/shared_api_library/CMakeLists.txt index cf13fa182d..f645e91fc5 100644 --- a/src/helics/shared_api_library/CMakeLists.txt +++ b/src/helics/shared_api_library/CMakeLists.txt @@ -31,8 +31,7 @@ set(helicsShared_sources internal/api_objects.h ) - -if (TARGET HELICS::apps) +if(TARGET HELICS::apps) list(APPEND helicsShared_sources helicsAppsExport.cpp) else() list(APPEND helicsShared_sources helicsAppsExportNull.cpp) @@ -118,7 +117,7 @@ set_target_properties(helics PROPERTIES VERSION ${HELICS_VERSION} SOVERSION ${HE set_target_properties(helics PROPERTIES CXX_VISIBILITY_PRESET hidden C_VISIBILITY_PRESET hidden) target_link_libraries(helics PRIVATE helics_application_api) -if (TARGET HELICS::apps) +if(TARGET HELICS::apps) target_link_libraries(helics PRIVATE HELICS::apps) endif() target_link_libraries(helics PRIVATE compile_flags_target) @@ -129,20 +128,20 @@ endif() if(UNIX OR MINGW) if(NOT APPLE) - include(CheckLinkerFlag) - check_linker_flag( - CXX "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.txt" - flag_linker_version_script + include(CheckLinkerFlag) + check_linker_flag( + CXX "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.txt" + flag_linker_version_script + ) + if(flag_linker_version_script) + target_link_libraries( + helics PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.txt ) - if(flag_linker_version_script) - target_link_libraries( - helics PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.txt - ) - endif() - check_linker_flag(CXX "-Wl,--exclude-libs,ALL" flag_linker_exclude_libs) - if(flag_linker_exclude_libs) - target_link_libraries(helics PRIVATE -Wl,--exclude-libs,ALL) - endif() + endif() + check_linker_flag(CXX "-Wl,--exclude-libs,ALL" flag_linker_exclude_libs) + if(flag_linker_exclude_libs) + target_link_libraries(helics PRIVATE -Wl,--exclude-libs,ALL) + endif() else(NOT_APPLE) target_link_libraries( helics PRIVATE -Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/export_mac.txt diff --git a/src/helics/shared_api_library/FederateExport.cpp b/src/helics/shared_api_library/FederateExport.cpp index 422fb2f28a..1287b42580 100644 --- a/src/helics/shared_api_library/FederateExport.cpp +++ b/src/helics/shared_api_library/FederateExport.cpp @@ -457,12 +457,11 @@ void helicsFederateInfoSetIntegerProperty(HelicsFederateInfo fedInfo, int intege info->setProperty(integerProperty, propertyValue); } - -HelicsFederate generateNewHelicsFederateObject(std::shared_ptr fed,helics::FederateType type) +HelicsFederate generateNewHelicsFederateObject(std::shared_ptr fed, helics::FederateType type) { auto fedI = std::make_unique(); - fedI->fedptr=fed; - fedI->type=type; + fedI->fedptr = fed; + fedI->type = type; fedI->valid = fedValidationIdentifier; auto* hfed = reinterpret_cast(fedI.get()); getMasterHolder()->addFed(std::move(fedI)); @@ -473,24 +472,24 @@ HelicsFederate generateNewHelicsFederateObject(std::shared_ptr HelicsFederate helicsCreateValueFederate(const char* fedName, HelicsFederateInfo fedInfo, HelicsError* err) { HELICS_ERROR_CHECK(err, nullptr); - + std::shared_ptr fed; try { if (fedInfo == nullptr) { - fed=std::make_shared(AS_STRING(fedName), helics::FederateInfo()); + fed = std::make_shared(AS_STRING(fedName), helics::FederateInfo()); } else { auto* info = getFedInfo(fedInfo, err); if (info == nullptr) { return nullptr; } - fed=std::make_shared(AS_STRING(fedName), *info); + fed = std::make_shared(AS_STRING(fedName), *info); } } catch (...) { helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::VALUE); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::VALUE); } HelicsFederate helicsCreateValueFederateFromConfig(const char* configFile, HelicsError* err) @@ -504,7 +503,7 @@ HelicsFederate helicsCreateValueFederateFromConfig(const char* configFile, Helic helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::VALUE); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::VALUE); } /* Creation and destruction of Federates */ @@ -527,7 +526,7 @@ HelicsFederate helicsCreateMessageFederate(const char* fedName, HelicsFederateIn helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::MESSAGE); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::MESSAGE); } HelicsFederate helicsCreateMessageFederateFromConfig(const char* configFile, HelicsError* err) @@ -542,7 +541,7 @@ HelicsFederate helicsCreateMessageFederateFromConfig(const char* configFile, Hel helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::MESSAGE); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::MESSAGE); } /* Creation and destruction of Federates */ @@ -558,14 +557,14 @@ HelicsFederate helicsCreateCombinationFederate(const char* fedName, HelicsFedera if (info == nullptr) { return nullptr; } - fed = std::make_shared(AS_STRING(fedName), *info); + fed = std::make_shared(AS_STRING(fedName), *info); } } catch (...) { helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::COMBINATION); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::COMBINATION); } HelicsFederate helicsCreateCombinationFederateFromConfig(const char* configFile, HelicsError* err) @@ -580,7 +579,7 @@ HelicsFederate helicsCreateCombinationFederateFromConfig(const char* configFile, return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::COMBINATION); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::COMBINATION); } /* Creation and destruction of Federates */ @@ -596,14 +595,14 @@ HelicsFederate helicsCreateCallbackFederate(const char* fedName, HelicsFederateI if (info == nullptr) { return nullptr; } - fed= std::make_shared(AS_STRING(fedName), *info); + fed = std::make_shared(AS_STRING(fedName), *info); } } catch (...) { helicsErrorHandler(err); return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::CALLBACK); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::CALLBACK); } HelicsFederate helicsCreateCallbackFederateFromConfig(const char* configFile, HelicsError* err) @@ -618,7 +617,7 @@ HelicsFederate helicsCreateCallbackFederateFromConfig(const char* configFile, He return nullptr; } - return generateNewHelicsFederateObject(std::move(fed),helics::FederateType::CALLBACK); + return generateNewHelicsFederateObject(std::move(fed), helics::FederateType::CALLBACK); } HelicsFederate helicsFederateClone(HelicsFederate fed, HelicsError* err) @@ -627,7 +626,7 @@ HelicsFederate helicsFederateClone(HelicsFederate fed, HelicsError* err) if (fedObj == nullptr) { return nullptr; } - return generateNewHelicsFederateObject(fedObj->fedptr,fedObj->type); + return generateNewHelicsFederateObject(fedObj->fedptr, fedObj->type); } HelicsFederate helicsGetFederateByName(const char* fedName, HelicsError* err) @@ -651,7 +650,7 @@ HelicsFederate helicsGetFederateByName(const char* fedName, HelicsError* err) } return nullptr; } - return generateNewHelicsFederateObject(fed->fedptr,fed->type); + return generateNewHelicsFederateObject(fed->fedptr, fed->type); } void helicsFederateProtect(const char* fedName, HelicsError* err) diff --git a/src/helics/shared_api_library/api-data.h b/src/helics/shared_api_library/api-data.h index 0913a1c2cb..29e7501e04 100644 --- a/src/helics/shared_api_library/api-data.h +++ b/src/helics/shared_api_library/api-data.h @@ -65,8 +65,8 @@ typedef void* HelicsBroker; typedef void* HelicsFederate; /** -* opaque object representing a helics app -*/ + * opaque object representing a helics app + */ // typedef void* helics_federate; typedef void* HelicsApp; diff --git a/src/helics/shared_api_library/helicsApps.h b/src/helics/shared_api_library/helicsApps.h index b08bc0831b..ad290949a9 100644 --- a/src/helics/shared_api_library/helicsApps.h +++ b/src/helics/shared_api_library/helicsApps.h @@ -6,9 +6,9 @@ SPDX-License-Identifier: BSD-3-Clause */ /** -* @file -* @brief Functions related to using helics apps -*/ + * @file + * @brief Functions related to using helics apps + */ #ifndef HELICS_APISHARED_APP_FUNCTIONS_H_ #define HELICS_APISHARED_APP_FUNCTIONS_H_ @@ -19,81 +19,79 @@ SPDX-License-Identifier: BSD-3-Clause extern "C" { #endif - /** - * Create a helics app object - * - * @details create a helics App object - * - * @param appName A string with the name of the app, can be NULL or an empty string to pull the default name from fedInfo or the config file. - * @param appType the type of app to create - * @param configFile configuration file or string to pass into the app, can be NULL or empty - * @param fedInfo the federate information to pass into the app, can be NULL - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - - * - * @return An opaque value app object nullptr if the object creation failed. - */ - HELICS_EXPORT HelicsApp helicsCreateApp(const char* appName, const char *appType, const char *configFile, HelicsFederateInfo fedInfo, HelicsError* err); - - /** run the App - * @details execute the app to completion - * @param app the app to execute - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - * - * @return An opaque value federate object that can be used in any of the federate methods, not recommended to use this object to advance time, the app will not likely function - normally, other query, or information calls, or modification calls on the federate are fine. - */ - HELICS_EXPORT HelicsFederate helicsAppGetFederate(HelicsApp app,HelicsError* err); - - /** - * Create a helics app object - * - * @details create a helics App object - * - * @param appName A string with the name of the app, can be NULL or an empty string to pull the default name from fedInfo or the config file. - * @param appType the type of app to create - * @param configFile configuration file or string to pass into the app, can be NULL or empty - * @param fedInfo the federate information to pass into the app, can be NULL - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - - * - * @return An opaque value app object nullptr if the object creation failed. - */ - HELICS_EXPORT void helicsAppLoadFile(HelicsApp app, const char *configFile, HelicsError* err); - - /** initialize the App federate - * @details generate all the interfaces and load data for the application - * @param app the app to initialize - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - */ - HELICS_EXPORT void helicsAppInitialize(HelicsApp app, HelicsError* err); - - - /** run the App - * @details execute the app to completion - * @param app the app to execute - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - */ - HELICS_EXPORT void helicsAppRun(HelicsApp app, HelicsError* err); - - - /** run and app to a specified stop time - * @details it is possible to call this method repeatedly with different times - * @param app the app to run - * @param stopTime the desired stop time - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - */ - HELICS_EXPORT void helicsAppRunTo(HelicsApp app, HelicsTime stopTime, HelicsError* err); - - - /** finalize the app - * @param app the app to execute - * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. - */ - HELICS_EXPORT void helicsAppFinalize(HelicsApp app, HelicsError* err); - - /** check if the App is ready to run*/ - HELICS_EXPORT HelicsBool helicsAppIsActive(HelicsApp app); +/** +* Create a helics app object +* +* @details create a helics App object +* +* @param appName A string with the name of the app, can be NULL or an empty string to pull the default name from fedInfo or the config file. +* @param appType the type of app to create +* @param configFile configuration file or string to pass into the app, can be NULL or empty +* @param fedInfo the federate information to pass into the app, can be NULL +* @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + +* +* @return An opaque value app object nullptr if the object creation failed. +*/ +HELICS_EXPORT HelicsApp + helicsCreateApp(const char* appName, const char* appType, const char* configFile, HelicsFederateInfo fedInfo, HelicsError* err); + +/** run the App +* @details execute the app to completion +* @param app the app to execute +* @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. +* +* @return An opaque value federate object that can be used in any of the federate methods, not recommended to use this object to advance +time, the app will not likely function normally, other query, or information calls, or modification calls on the federate are fine. +*/ +HELICS_EXPORT HelicsFederate helicsAppGetFederate(HelicsApp app, HelicsError* err); + +/** +* Create a helics app object +* +* @details create a helics App object +* +* @param appName A string with the name of the app, can be NULL or an empty string to pull the default name from fedInfo or the config file. +* @param appType the type of app to create +* @param configFile configuration file or string to pass into the app, can be NULL or empty +* @param fedInfo the federate information to pass into the app, can be NULL +* @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + +* +* @return An opaque value app object nullptr if the object creation failed. +*/ +HELICS_EXPORT void helicsAppLoadFile(HelicsApp app, const char* configFile, HelicsError* err); + +/** initialize the App federate + * @details generate all the interfaces and load data for the application + * @param app the app to initialize + * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + */ +HELICS_EXPORT void helicsAppInitialize(HelicsApp app, HelicsError* err); + +/** run the App + * @details execute the app to completion + * @param app the app to execute + * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + */ +HELICS_EXPORT void helicsAppRun(HelicsApp app, HelicsError* err); + +/** run and app to a specified stop time + * @details it is possible to call this method repeatedly with different times + * @param app the app to run + * @param stopTime the desired stop time + * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + */ +HELICS_EXPORT void helicsAppRunTo(HelicsApp app, HelicsTime stopTime, HelicsError* err); + +/** finalize the app + * @param app the app to execute + * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. + */ +HELICS_EXPORT void helicsAppFinalize(HelicsApp app, HelicsError* err); + +/** check if the App is ready to run*/ +HELICS_EXPORT HelicsBool helicsAppIsActive(HelicsApp app); #ifdef __cplusplus } /* end of extern "C" { */ diff --git a/src/helics/shared_api_library/helicsAppsExport.cpp b/src/helics/shared_api_library/helicsAppsExport.cpp index 0130efc7bc..048882eaf1 100644 --- a/src/helics/shared_api_library/helicsAppsExport.cpp +++ b/src/helics/shared_api_library/helicsAppsExport.cpp @@ -9,9 +9,9 @@ SPDX-License-Identifier: BSD-3-Clause #include "../core/coreTypeOperations.hpp" #include "../helics.hpp" #include "gmlc/concurrency/TripWire.hpp" +#include "helics/helics_apps.hpp" #include "helicsApps.h" #include "internal/api_objects.h" -#include "helics/helics_apps.hpp" #include #include @@ -21,33 +21,29 @@ SPDX-License-Identifier: BSD-3-Clause #include #include +namespace helics { +/** this is a random identifier put in place when the federate or core or broker gets created*/ +static constexpr int appValidationIdentifier = 0x7A8F'1C4D; -namespace helics -{ - - /** this is a random identifier put in place when the federate or core or broker gets created*/ - static constexpr int appValidationIdentifier = 0x7A8F'1C4D; - - static constexpr const char* invalidAppString = "app object is not valid"; +static constexpr const char* invalidAppString = "app object is not valid"; - AppObject* getAppObject(HelicsApp app, HelicsError* err) noexcept - { - HELICS_ERROR_CHECK(err, nullptr); - if (app == nullptr) { - assignError(err, HELICS_ERROR_INVALID_OBJECT, invalidAppString); - return nullptr; - } - auto* appObj = reinterpret_cast(app); - if (appObj->valid == appValidationIdentifier) { - return appObj; - } +AppObject* getAppObject(HelicsApp app, HelicsError* err) noexcept +{ + HELICS_ERROR_CHECK(err, nullptr); + if (app == nullptr) { assignError(err, HELICS_ERROR_INVALID_OBJECT, invalidAppString); return nullptr; } - + auto* appObj = reinterpret_cast(app); + if (appObj->valid == appValidationIdentifier) { + return appObj; + } + assignError(err, HELICS_ERROR_INVALID_OBJECT, invalidAppString); + return nullptr; } +} // namespace helics helics::apps::App* getApp(HelicsApp app, HelicsError* err) { @@ -67,50 +63,41 @@ std::shared_ptr getAppSharedPtr(HelicsApp core, HelicsError* return appObj->app; } - static constexpr char nullcstr[] = ""; static std::shared_ptr buildApp(std::string_view type, std::string_view appName, helics::FederateInfo& fedInfo) { - if (type == "player") - { + if (type == "player") { return std::make_shared(appName, fedInfo); } - if (type == "recorder") - { + if (type == "recorder") { return std::make_shared(appName, fedInfo); } - if (type == "connector") - { + if (type == "connector") { return std::make_shared(appName, fedInfo); } - if (type == "echo") - { + if (type == "echo") { return std::make_shared(appName, fedInfo); } - if (type == "clone") - { + if (type == "clone") { return std::make_shared(appName, fedInfo); } - if (type == "probe") - { + if (type == "probe") { return std::make_shared(appName, fedInfo); } - if (type == "tracer") - { + if (type == "tracer") { return std::make_shared(appName, fedInfo); } - if (type == "source") - { + if (type == "source") { return std::make_shared(appName, fedInfo); } return nullptr; - } HelicsApp helicsCreateApp(const char* appName, const char* appType, const char* configFile, HelicsFederateInfo fedInfo, HelicsError* err) { - static constexpr const char* invalidAppTypeString = "app type must be one of 'connector', 'source','recorder','player','echo','clone','probe','tracer'"; + static constexpr const char* invalidAppTypeString = + "app type must be one of 'connector', 'source','recorder','player','echo','clone','probe','tracer'"; if ((err != nullptr) && (err->error_code != 0)) { return nullptr; } @@ -119,33 +106,30 @@ HelicsApp helicsCreateApp(const char* appName, const char* appType, const char* auto app = std::make_unique(); app->valid = helics::appValidationIdentifier; auto nstring = AS_STRING_VIEW(appName); - if (appType == nullptr) - { + if (appType == nullptr) { assignError(err, HELICS_ERROR_INVALID_ARGUMENT, invalidAppTypeString); return nullptr; } std::string_view appTypeName(appType); - bool loadFile=true; + bool loadFile = true; if (fedInfo == nullptr) { - helics::FederateInfo newFedInfo=helics::loadFederateInfo(AS_STRING(configFile)); - app->app = buildApp(appTypeName,nstring, newFedInfo); - loadFile=false; + helics::FederateInfo newFedInfo = helics::loadFederateInfo(AS_STRING(configFile)); + app->app = buildApp(appTypeName, nstring, newFedInfo); + loadFile = false; } else { auto* info = getFedInfo(fedInfo, err); if (info == nullptr) { return nullptr; } - app->app = buildApp(appTypeName,nstring, *info); + app->app = buildApp(appTypeName, nstring, *info); } - if (!app->app) - { + if (!app->app) { assignError(err, HELICS_ERROR_INVALID_ARGUMENT, invalidAppTypeString); return nullptr; } - if (loadFile) - { + if (loadFile) { app->app->loadFile(AS_STRING(configFile)); } auto* retapp = reinterpret_cast(app.get()); @@ -158,35 +142,28 @@ HelicsApp helicsCreateApp(const char* appName, const char* appType, const char* } } - HelicsFederate helicsAppGetFederate(HelicsApp app, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return nullptr; } - try - { - return generateNewHelicsFederateObject(happ->getUnderlyingFederatePointer(), helics::FederateType::COMBINATION); + try { + return generateNewHelicsFederateObject(happ->getUnderlyingFederatePointer(), helics::FederateType::COMBINATION); } catch (...) { helicsErrorHandler(err); return nullptr; } - } - void helicsAppLoadFile(HelicsApp app, const char* configFile, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return; } - try - { + try { happ->loadFile(AS_STRING(configFile)); } catch (...) { @@ -196,13 +173,11 @@ void helicsAppLoadFile(HelicsApp app, const char* configFile, HelicsError* err) void helicsAppInitialize(HelicsApp app, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return; } - try - { + try { happ->initialize(); } catch (...) { @@ -210,16 +185,13 @@ void helicsAppInitialize(HelicsApp app, HelicsError* err) } } - void helicsAppRun(HelicsApp app, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return; } - try - { + try { happ->run(); } catch (...) { @@ -229,13 +201,11 @@ void helicsAppRun(HelicsApp app, HelicsError* err) void helicsAppRunTo(HelicsApp app, HelicsTime stopTime, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return; } - try - { + try { happ->runTo(stopTime); } catch (...) { @@ -243,16 +213,13 @@ void helicsAppRunTo(HelicsApp app, HelicsTime stopTime, HelicsError* err) } } - void helicsAppFinalize(HelicsApp app, HelicsError* err) { - auto *happ=getApp(app,err); - if (happ == nullptr) - { + auto* happ = getApp(app, err); + if (happ == nullptr) { return; } - try - { + try { happ->finalize(); } catch (...) { @@ -262,10 +229,9 @@ void helicsAppFinalize(HelicsApp app, HelicsError* err) HelicsBool helicsAppIsActive(HelicsApp app) { - auto *happ=getApp(app,nullptr); - if (happ == nullptr) - { + auto* happ = getApp(app, nullptr); + if (happ == nullptr) { return HELICS_FALSE; } - return (happ->isActive()?HELICS_TRUE:HELICS_FALSE); + return (happ->isActive() ? HELICS_TRUE : HELICS_FALSE); } diff --git a/src/helics/shared_api_library/helicsAppsExportNull.cpp b/src/helics/shared_api_library/helicsAppsExportNull.cpp index 53814dc874..89375b9007 100644 --- a/src/helics/shared_api_library/helicsAppsExportNull.cpp +++ b/src/helics/shared_api_library/helicsAppsExportNull.cpp @@ -8,64 +8,61 @@ SPDX-License-Identifier: BSD-3-Clause #include "helicsApps.h" #include "internal/api_objects.h" - static constexpr const char* invalidAppString = "app object is not valid"; -static constexpr const char* notLoadedString ="helics apps not compiled into library, enable apps when building" -helics::apps::App* getApp(HelicsApp app, HelicsError* err) +static constexpr const char* notLoadedString = + "helics apps not compiled into library, enable apps when building" helics::apps::App * getApp(HelicsApp app, HelicsError* err) { HELICS_ERROR_CHECK(err, nullptr); if (app == nullptr) { assignError(err, HELICS_ERROR_INVALID_OBJECT, invalidAppString); - } - else - { - assignError(err,HELICS_ERROR_OTHER,notLoadedString); + } else { + assignError(err, HELICS_ERROR_OTHER, notLoadedString); } return nullptr; } static constexpr char nullcstr[] = ""; -HelicsApp helicsCreateApp(const char* /*appName*/, const char* /*appType*/, const char* /*configFile*/, HelicsFederateInfo /*fedInfo*/, HelicsError* err) +HelicsApp helicsCreateApp(const char* /*appName*/, + const char* /*appType*/, + const char* /*configFile*/, + HelicsFederateInfo /*fedInfo*/, + HelicsError* err) { HELICS_ERROR_CHECK(err, nullptr); - assignError(err,HELICS_ERROR_OTHER,notLoadedString); + assignError(err, HELICS_ERROR_OTHER, notLoadedString); return nullptr; } - HelicsFederate helicsAppGetFederate(HelicsApp app, HelicsError* err) { - getApp(app,err); + getApp(app, err); return nullptr; } - void helicsAppLoadFile(HelicsApp app, const char* /*configFile*/, HelicsError* err) { - getApp(app,err); + getApp(app, err); } void helicsAppInitialize(HelicsApp app, HelicsError* err) { - getApp(app,err); + getApp(app, err); } - void helicsAppRun(HelicsApp app, HelicsError* err) { - getApp(app,err); + getApp(app, err); } void helicsAppRunTo(HelicsApp app, HelicsTime stopTime, HelicsError* err) { - getApp(app,err); + getApp(app, err); } - void helicsAppFinalize(HelicsApp app, HelicsError* err) { - getApp(app,err); + getApp(app, err); } HelicsBool helicsAppIsActive(HelicsApp app) diff --git a/src/helics/shared_api_library/helicsExport.cpp b/src/helics/shared_api_library/helicsExport.cpp index dd8e431b3a..891600bbb3 100644 --- a/src/helics/shared_api_library/helicsExport.cpp +++ b/src/helics/shared_api_library/helicsExport.cpp @@ -11,8 +11,8 @@ SPDX-License-Identifier: BSD-3-Clause #include "../core/helicsVersion.hpp" #include "../helics.hpp" #include "helics/helics-config.h" -#include "helicsCore.h" #include "helicsApps.h" +#include "helicsCore.h" #include "internal/api_objects.h" #include @@ -1364,7 +1364,6 @@ int MasterObjectHolder::addFed(std::unique_ptr fed) return index; } - int MasterObjectHolder::addApp(std::unique_ptr app) { auto handle = apps.lock(); @@ -1467,7 +1466,7 @@ void MasterObjectHolder::clearApp(int index) (*appList)[index]->valid = 0; (*appList)[index] = nullptr; if (appList->size() > 10) { - if (std::none_of(appList->begin(),appList->end(), [](const auto& app) { return static_cast(app); })) { + if (std::none_of(appList->begin(), appList->end(), [](const auto& app) { return static_cast(app); })) { appList->clear(); } } @@ -1505,10 +1504,10 @@ void MasterObjectHolder::deleteAll() fedHandle->clear(); } { - auto appHandle =apps.lock(); - for (auto& app: appHandle) { + auto appHandle = apps.lock(); + for (auto& app : appHandle) { if ((app) && (app->app)) { - helicsAppFinalize(reinterpret_cast(app.get()),nullptr); + helicsAppFinalize(reinterpret_cast(app.get()), nullptr); app->valid = 0; } } diff --git a/src/helics/shared_api_library/internal/api_objects.h b/src/helics/shared_api_library/internal/api_objects.h index 34d138b20f..a76ec6ac02 100644 --- a/src/helics/shared_api_library/internal/api_objects.h +++ b/src/helics/shared_api_library/internal/api_objects.h @@ -39,8 +39,7 @@ class Endpoint; class Filter; class Translator; -namespace apps -{ +namespace apps { class App; } @@ -76,10 +75,9 @@ class CoreObject { /** get the CoreObject from a HelicsCore and verify it is valid*/ CoreObject* getCoreObject(HelicsCore core, HelicsError* err) noexcept; - /** object representing an app*/ class AppObject { -public: + public: std::string type; //!< the target of the query std::shared_ptr app; int index{-2}; @@ -183,7 +181,6 @@ class QueryObject { int valid{0}; }; - } // namespace helics /** definitions to simplify error returns if an error already exists*/ @@ -225,7 +222,7 @@ helics::FederateInfo* getFedInfo(HelicsFederateInfo fedInfo, HelicsError* err); helics::Core* getCore(HelicsCore core, HelicsError* err); helics::Broker* getBroker(HelicsBroker broker, HelicsError* err); helics::Message* getMessageObj(HelicsMessage message, HelicsError* err); -helics::apps::App *getApp(HelicsApp, HelicsError *err); +helics::apps::App* getApp(HelicsApp, HelicsError* err); /** generate a new helicsFederate and store it in the master*/ HelicsFederate generateNewHelicsFederateObject(std::shared_ptr fed, helics::FederateType type); @@ -280,7 +277,7 @@ class MasterObjectHolder { bool removeFed(std::string_view name, int validationCode); /** add an app to the holder*/ int addApp(std::unique_ptr app); - + void clearBroker(int index); void clearCore(int index); void clearFed(int index);