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

Expose FullNameAndVersion() from a DSDL type. #352

Merged
merged 9 commits into from
Nov 8, 2024

Conversation

serges147
Copy link

@serges147 serges147 commented Nov 5, 2024

  1. Exposed full name of a DSDL type as...
struct _traits_
{
    ...
    constexpr const char* FullNameAndVersion() { return "{{ composite_type }}"; }
};

Needed for libcyphal's subscriber implementation (see issue # 380)

  1. Fix for issue C++ support/serialization.hpp should #include <cassert> #348 - added #include <cassert> for nunavut/support/serialization.hpp file generation

@serges147 serges147 changed the title Sshirokov/cpp type name Expose FullNameAndVersion() from a DSDL type. Nov 5, 2024
@serges147 serges147 self-assigned this Nov 5, 2024
{% endif -%}
{%- assert composite_type.extent % 8 == 0 %}
{% endif %}
static constexpr const char* FullNameAndVersion() { return "{{ composite_type }}"; }
Copy link
Author

@serges147 serges147 Nov 5, 2024

Choose a reason for hiding this comment

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

Unfortunately I can't make it as simple as it could be in c++17:
static constexpr char FullNameAndVersion[] = "{{ composite_type }}"; - linker error @ c++14

Copy link
Member

Choose a reason for hiding this comment

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

You can by adding constexpr char {{composite_type|short_reference_name}}::FullNameAndVersion[]; after the class.

Copy link
Author

Choose a reason for hiding this comment

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

Sonar will catch ODR issue with such approach.

@serges147 serges147 marked this pull request as ready for review November 5, 2024 18:16
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2024 OpenCyphal Development Team.
* Authors: Sergei Shirokov <sergei.shirokov@zubax.com>
Copy link
Author

Choose a reason for hiding this comment

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

Inspired by corresponding "C" test, namely verification/c/suite/test_constant.c

Copy link

sonarcloud bot commented Nov 7, 2024

Le(regulated::basics::Struct__0_1::_traits_::SerializationBufferSizeBytes * 8U));
EXPECT_TRUE(regulated::basics::Struct__0_1::CONSTANT_TRUTH);

// TODO: Uncomment when some form of "ARRAY_CAPACITY" is generated.
Copy link
Author

@serges147 serges147 Nov 7, 2024

Choose a reason for hiding this comment

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

Separate issue and PR but probably I will add generation of a new <DSDL Type>::_traits_::ArrayCapacity struct (similar to existing struct TypeOf), where there will be listed static constexpr std::size_t constants for each field which has variable array type. Static array fields don't require such information (b/c std::array<> already has .size() method), but maybe just for consistency I will list them as well.

And I'm not planning to expose analog of ARRAY_IS_VARIABLE_LENGTH_ boolean.

Copy link
Author

Choose a reason for hiding this comment

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

@thirtytwobits Do you agree with my future plan about above "ARRAY_CAPACITY" topic?

Copy link
Member

Choose a reason for hiding this comment

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

CETL's variable_length_array already provides max_size for this?

Copy link
Author

@serges147 serges147 Nov 7, 2024

Choose a reason for hiding this comment

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

Yes it does, but under c++17 and above we use std::vector (with PMR allocator of course)

{% endif -%}
{%- assert composite_type.extent % 8 == 0 %}
{% endif %}
static constexpr const char* FullNameAndVersion() { return "{{ composite_type }}"; }
Copy link
Member

Choose a reason for hiding this comment

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

You can by adding constexpr char {{composite_type|short_reference_name}}::FullNameAndVersion[]; after the class.

Le(regulated::basics::Struct__0_1::_traits_::SerializationBufferSizeBytes * 8U));
EXPECT_TRUE(regulated::basics::Struct__0_1::CONSTANT_TRUTH);

// TODO: Uncomment when some form of "ARRAY_CAPACITY" is generated.
Copy link
Member

Choose a reason for hiding this comment

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

CETL's variable_length_array already provides max_size for this?

@thirtytwobits thirtytwobits merged commit afd41a5 into 3.0.preview Nov 8, 2024
236 checks passed
@thirtytwobits thirtytwobits deleted the sshirokov/cpp_type_name branch November 8, 2024 00:14
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.

3 participants