Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C app interface #2691

Merged
merged 24 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2aaa0f4
add helics Apps C interface
phlptp Nov 1, 2024
ba7cdfe
update the library with helicsApps functions
phlptp Nov 2, 2024
0bcd855
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2024
8bb21a2
add some app test to the C library
phlptp Nov 4, 2024
64acc22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2024
bd688aa
update clang tidy and backup files
phlptp Nov 4, 2024
fffb9b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2024
57b4270
clang-tidy fixes
phlptp Nov 4, 2024
e90f13a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2024
89c46fb
add more tests for C interface and add helicsEndpointSendString variants
phlptp Nov 6, 2024
dab71c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2024
a0df68f
add backup files
phlptp Nov 7, 2024
306b553
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
5cec41a
clang-tidy fixes
phlptp Nov 7, 2024
8067157
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
46d5bbb
clang-tidy fixes
phlptp Nov 7, 2024
be2a8d2
clang tidy fixes
phlptp Nov 7, 2024
9841b02
fix test
phlptp Nov 8, 2024
75ac318
add more tests and fixes
phlptp Nov 8, 2024
15d6f90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2024
e45c87e
tweak the app tests
phlptp Nov 8, 2024
4bc2b26
add missing file to shared cxx library install
phlptp Nov 8, 2024
193afd5
Apply suggestions from code review
phlptp Nov 12, 2024
27ffba1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Checks: "
-hicpp-avoid-c-arrays,
-hicpp-no-array-decay,
clang-analyzer-*,
clang-diagnostic*,
bugprone-*,
-bugprone-narrowing-conversions,
-bugprone-easily-swappable-parameters,
Expand Down Expand Up @@ -62,6 +63,7 @@ WarningsAsErrors: "
-hicpp-no-array-decay,
clang-analyzer-*,
-clang-analyzer-optin.cplusplus.VirtualCall,
clang-diagnostic*,
bugprone-*,
-bugprone-narrowing-conversions,
-bugprone-easily-swappable-parameters,
Expand Down
3 changes: 2 additions & 1 deletion scripts/generateHelicsH.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Created on Mon Dec 7 14:25:17 2020

@author: phlpt
@author: Philip Top
"""

import re
Expand Down Expand Up @@ -73,6 +73,7 @@
"src/helics/shared_api_library/api-data.h",
"src/helics/shared_api_library/helicsData.h",
"src/helics/shared_api_library/helicsCore.h",
"src/helics/shared_api_library/helicsApps.h",
"src/helics/shared_api_library/ValueFederate.h",
"src/helics/shared_api_library/MessageFederate.h",
"src/helics/shared_api_library/MessageFilters.h",
Expand Down
2 changes: 1 addition & 1 deletion src/helics/application_api/helicsTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ inline X invalidValue()
}

/// defined constant for an invalid value as a double
constexpr double invalidDouble = -1e49;
constexpr double invalidDouble = HELICS_INVALID_DOUBLE;

template<>
constexpr double invalidValue<double>()
Expand Down
27 changes: 14 additions & 13 deletions src/helics/apps/helicsApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,35 +154,36 @@ std::vector<int> AppTextParser::preParseFile(const std::vector<char>& klines)
if (str.empty()) {
continue;
}
auto fc = str.find_first_not_of(" \t\n\r\0");
if (fc == std::string::npos) {
auto firstChar = str.find_first_not_of(" \t\n\r\0");
if (firstChar == std::string::npos) {
continue;
}
if (inMline) {
if (fc + 2 < str.size()) {
if ((str[fc] == '#') && (str[fc + 1] == '#') && (str[fc + 2] == ']')) {
if (firstChar + 2 < str.size()) {
if ((str[firstChar] == '#') && (str[firstChar + 1] == '#') &&
(str[firstChar + 2] == ']')) {
inMline = false;
}
}
continue;
}
if (str[fc] == '#') {
if (fc + 2 < str.size()) {
if ((str[fc + 1] == '#') && (str[fc + 2] == '[')) {
if (str[firstChar] == '#') {
if (firstChar + 2 < str.size()) {
if ((str[firstChar + 1] == '#') && (str[firstChar + 2] == '[')) {
inMline = true;
}
}
continue;
}
if (str[fc] == '!') {
configStr += str.substr(fc + 1);
if (str[firstChar] == '!') {
configStr += str.substr(firstChar + 1);
configStr.push_back('\n');
continue;
}

++counts[0];
for (std::size_t ii = 0; ii < klines.size(); ++ii) {
if (str[fc] == klines[ii]) {
if (str[firstChar] == klines[ii]) {
++counts[ii + 1];
}
}
Expand Down Expand Up @@ -277,15 +278,15 @@ void App::loadJsonFileConfiguration(const std::string& appName,
auto doc = fileops::loadJson(jsonString);

if (doc.contains("app")) {
auto appConfig = doc["app"];
auto& appConfig = doc["app"];
loadConfigOptions(appConfig);
}
if (doc.contains("config")) {
auto appConfig = doc["config"];
auto& appConfig = doc["config"];
loadConfigOptions(appConfig);
}
if (doc.contains(appName)) {
auto appConfig = doc[appName];
auto& appConfig = doc[appName];
loadConfigOptions(appConfig);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/helics/apps/helicsApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ necessary
/** get a const reference to the federate*/
const CombinationFederate& accessUnderlyingFederate() const { return *fed; }

/** get a copy of the federate pointer (this can be dangerous if misused) */
std::shared_ptr<CombinationFederate> getUnderlyingFederatePointer() { return fed; }

protected:
/** load from a jsonString
@param jsonString either a JSON filename or a string containing JSON
Expand Down
1 change: 1 addition & 0 deletions src/helics/cxx_shared_library/cxx_file_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(helics_apps_public_headers
${HELICS_LIBRARY_SOURCE_DIR}/apps/Source.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/Tracer.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/helicsApp.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/Probe.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/Connector.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/Clone.hpp
${HELICS_LIBRARY_SOURCE_DIR}/apps/CoreApp.hpp
Expand Down
2 changes: 2 additions & 0 deletions src/helics/helics_apps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +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"
2 changes: 2 additions & 0 deletions src/helics/helics_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ typedef enum { /* NOLINT */
#define HELICS_BIG_NUMBER 9223372036.854774
const double cHelicsBigNumber = HELICS_BIG_NUMBER;

#define HELICS_INVALID_DOUBLE -1E49

#ifdef __cplusplus
} /* end of extern "C" { */
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/helics/shared_api_library/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ Checks: "
clang-analyzer-*,
bugprone-*,
-bugprone-narrowing-conversions,
-bugprone-easily-swappable-parameters,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
cert-*,
-cert-err58-cpp,
portability-*,
readability-*,
-readability-magic-numbers,
-readability-avoid-unconditional-preprocessor-if,
performance-*
"

Expand All @@ -50,10 +53,12 @@ WarningsAsErrors: "
-bugprone-easily-swappable-parameters,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
portability-*,
readability-*,
-readability-magic-numbers,
-readability-identifier-naming,
-readability-avoid-unconditional-preprocessor-if,
performance-*
"

Expand Down
38 changes: 21 additions & 17 deletions src/helics/shared_api_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(helicsShared_headers
MessageFilters.h
Translators.h
helicsCallbacks.h
helicsApps.h
)

set(helicsShared_sources
Expand All @@ -30,6 +31,12 @@ set(helicsShared_sources
internal/api_objects.h
)

if(TARGET HELICS::apps)
list(APPEND helicsShared_sources helicsAppsExport.cpp)
else()
list(APPEND helicsShared_sources helicsAppsExportNull.cpp)
endif()

include(GenerateExportHeader)

if(Python_EXECUTABLE)
Expand All @@ -46,6 +53,7 @@ if(Python_EXECUTABLE)
Translators.h
helicsData.h
helicsCore.h
helicsApps.h
Translators.h
api-data.h
../helics_enums.h
Expand Down Expand Up @@ -109,33 +117,29 @@ 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)
target_link_libraries(helics PRIVATE HELICS::apps)
endif()
target_link_libraries(helics PRIVATE compile_flags_target)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(helics PUBLIC -Wno-documentation)
endif()

if(UNIX OR MINGW)
if(NOT APPLE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
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
)
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()
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
)
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)
Expand Down
Loading
Loading