Skip to content

Clean up the properties code and Tie methods.#1317

Merged
agodemar merged 3 commits intoJSBSim-Team:masterfrom
bcoconni:clean_prop_tie
Sep 8, 2025
Merged

Clean up the properties code and Tie methods.#1317
agodemar merged 3 commits intoJSBSim-Team:masterfrom
bcoconni:clean_prop_tie

Conversation

@bcoconni
Copy link
Member

@bcoconni bcoconni commented Aug 9, 2025

This PR is a follow up of the PRs #1304, #1311 and #1312.

  • The function getValue in FGPropertyManager.h as well as the PropertyTraits conversions in FGWinds.cpp and FGPropagate.cpp are no longer needed due to the introduction of the class SGRawValueMethodsEnum. This PR removes the corresponding code.
  • Some clean up in the classes SGRawValueMethodsEnum and SGRawValueMethodsIndexedEnum:
    • Remove the empty destructor
    • Use override instead of repeating the virtual keyword from the mother class.
    • Replace 0 by nullptr for pointers.
  • Use the shorter syntax std::enable_if_t<> instead of std::enable_if<>::type
  • In the method Tie<C, T, U> replace the static_assert by the template std::enable_if_t<>, similarly to what has been done by the PR Add raw values enumeration to fix segfaults #1312
  • Use dynamic_cast in the method SGPropertyNode::get_int and it siblings to check that no illegal conversions are made, as per Add raw values enumeration to fix segfaults #1312 (comment)
    • The usage of dynamic_cast<> is limited to compilations where NDEBUG is not defined. Otherwise static_cast<> is used for performance reasons.
  • Fixed the order in which the members are initialized in the SGPropertyNode constructors to avoid some warnings from the compilers (with gcc flag -Wreorder).

@codecov
Copy link

codecov bot commented Aug 9, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.85%. Comparing base (b005a91) to head (c0417ef).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/input_output/FGPropertyManager.h 72.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1317      +/-   ##
==========================================
- Coverage   24.87%   24.85%   -0.02%     
==========================================
  Files         169      169              
  Lines       19655    19649       -6     
==========================================
- Hits         4889     4884       -5     
+ Misses      14766    14765       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bcoconni bcoconni requested a review from Copilot August 9, 2025 14:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR cleans up property handling code and improves the Tie methods implementation. It removes obsolete code that is no longer needed due to the introduction of SGRawValueMethodsEnum, modernizes C++ usage patterns, and addresses compiler warnings.

  • Removes deprecated PropertyTraits specializations and getValue function from property manager
  • Modernizes C++ patterns using override, std::enable_if_t, and safer casting with debug assertions
  • Fixes member initialization order in constructors to prevent compiler warnings

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/simgear/props/props.cxx Introduces safer casting with debug checks and fixes constructor member initialization order
src/models/atmosphere/FGWinds.cpp Removes obsolete PropertyTraits specializations
src/models/FGPropagate.cpp Removes obsolete PropertyTraits specializations
src/input_output/FGPropertyManager.h Modernizes raw value classes and Tie method templates

@seanmcleod70
Copy link
Contributor

Looks good.

The NDEBUG define with it's negative logic always make me double check it's use 😉

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bcoconni
Copy link
Member Author

bcoconni commented Aug 9, 2025

The NDEBUG define with it's negative logic always make me double check it's use 😉

The same with me 😄

BTW does MSVC define the flag NDEBUG when compiling with RelWithDebInfo ? I am asking because the Python wheels that are uploaded to PyPI are currently compiled with RelWithDebInfo:

JSBSIM_BUILD_CONFIG: RelWithDebInfo

I am concerned that if it does not define NDEBUG then the Windows version of the Python wheels will use dynamic_cast<> instead of static_cast<>.

@seanmcleod70
Copy link
Contributor

seanmcleod70 commented Aug 9, 2025

Hmm, in terms of NDEBUG.

https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170&redirectedfrom=MSDN

The compiler supports these predefined macros specified by the ISO C99, C11, C17, and ISO C++17 standards.

So it doesn't say it supports all macros specified by ISO standards, just 'these', and I don't see NDEBUG listed.

Also this post - taglib/taglib#790 mentions Visual Studio not defining NDEBUG in release builds.

And from Stackoverflow:

https://stackoverflow.com/questions/2290509/debug-vs-ndebug

Is NDEBUG standard?

Yes it is a standard macro with the semantic "Not Debug" for C89, C99, C++98, C++2003, C++2011, C++2014 standards. There are no _DEBUG macros in the standards.

I rely on NDEBUG, because it's the only one whose behavior is standardized across compilers and implementations (see documentation for the standard assert macro). The negative logic is a small readability speedbump, but it's a common idiom you can quickly adapt to.

Hmm, so this person is claiming it is standardized across compilers, but maybe they've never used MSVC? I see they also complain about the negative logic 😉

Having said all that, I'm fairly familiar with NDEBUG and 99% of my C++ compiler use over the years has been with MSVC.

Looking at the JSBSim vcxproj (as opposed to CMAKE) I see NDEBUG is defined for release build. So maybe the MSVC compiler doesn't automatically define it based on ISO standards, but maybe the default vcxproj that Visual Studio generates adds NDEBUG define by default?

image

@seanmcleod70
Copy link
Contributor

Hmm, so this details CMAKE's Build Types.

https://gist.github.com/MangaD/475b8b413aff7682b803fb007083fb5c

Now it only lists compiler flages for GCC/Clang, and interestingly it explicitly defines NDEBUG for the release builds, i.e. it doesn't appear to rely on the compiler itself to define it?

So we need to figure out what compiler flags are passed to MSVC for CMAKE's RelWithDebInfo.

@bcoconni
Copy link
Member Author

Please note that I have updated the PR and removed 2 templates of the Tiemethods:

  • template <typename T> void Tie (const std::string &name, T (*getter)(), void (*setter)(T) = nullptr)
  • template <typename T> void Tie (const std::string &name, int index, T (*getter)(int), void (*setter)(int, T) = nullptr)

They are not used anywhere and this will reduce the number of lines in FGPropertyManager.h (or should I say compensate the lines added by the PRs mentioned in this PR description).

@bcoconni
Copy link
Member Author

bcoconni commented Sep 6, 2025

So are we ready to merge this PR ?

I will address the NDEBUG flag for Windows in a separate PR.

@seanmcleod70
Copy link
Contributor

So are we ready to merge this PR ?

Yep, I thought the only outstanding thing was the potential issue with NDEBUG on MSVC builds. Which you mention now you'll address in a separate PR.

@bcoconni
Copy link
Member Author

bcoconni commented Sep 6, 2025

Yep, I thought the only outstanding thing was the potential issue with NDEBUG on MSVC builds. Which you mention now you'll address in a separate PR.

Indeed, as you mentioned, we are already setting it up correctly in the MSVC project files and, according to GitHub Copilot, NDEBUG is defined by default for CMake when buidling with RelWithDebInfo and Release. But well that's AI which may or may not be trusted. So I guess we need to specify explicitly the flag in CMakeLists.txt for non-debug builds to be on the safe side, and also to protect ourselves against a change of CMake defaults.

@seanmcleod70
Copy link
Contributor

Yep, setting NDEBUG ourselves explicitly in CMakeLists.txt is the safest option, at worst it will be defined twice in the arguments passed to the compiler.

When I initially took a look I thought I'd be able to fairly easily find a reference to some config file in the CMake installation listing the compiler options per compiler per build type, but wasn't able to at the time until I ran out of steam.

I did come across this link which mentions how you can get CMake to output the compiler options.

https://stackoverflow.com/questions/24767450/using-cmake-how-do-you-determine-the-default-compiler-flags-per-build-type

@agodemar
Copy link
Contributor

agodemar commented Sep 8, 2025

Green light to merge?

@bcoconni
Copy link
Member Author

bcoconni commented Sep 8, 2025

Looks good! Go for it

@bcoconni
Copy link
Member Author

bcoconni commented Sep 8, 2025

And for future reference the topic about NDEBUG is addressed in the PR #1330.

@agodemar agodemar merged commit d280579 into JSBSim-Team:master Sep 8, 2025
29 checks passed
@bcoconni bcoconni deleted the clean_prop_tie branch September 8, 2025 22:25
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants