From 9062ad31ec9cf2b0c558e40edece8eb20edafe42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Bueno=20L=C3=B3pez?= <69244257+JLBuenoLopez-eProsima@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:38:55 +0200 Subject: [PATCH] XTypes v1.3 refactor (#327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * New argument -genapi [19958] (#261) * Refs #19944. Initial -genapi Signed-off-by: Ricardo González Moreno * Refs #19944. Remove default templates Signed-off-by: Ricardo González Moreno * Refs #19944. Update scope when getting typecodes Signed-off-by: Ricardo González Moreno * Refs #19944. Fix compilation error Signed-off-by: Ricardo González Moreno * Refs #19944. Apply suggestions Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Update IDL parser submodule to support new Union discriminator as a Member (#262) * Refs #19932: update IDL parser submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #19932: changes required from review suggestion in IDL Parser Signed-off-by: JLBuenoLopez-eProsima * Refs #19932: update submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Remove -cdr argument and support of Fast CDR v1 (#265) * Refs #19971. Remove -cdr argument Signed-off-by: Ricardo González Moreno * Refs #19971. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * User types header-only (#263) * Refs #19960. Implementation Signed-off-by: Ricardo González Moreno * Refs #19960. New argument -no-typesupport Signed-off-by: Ricardo González Moreno * Refs #19960. Remove old template Signed-off-by: Ricardo González Moreno * Refs #19960. New configuration to set explicitly using modules in stg Signed-off-by: Ricardo González Moreno * Refs #19960. Update submodule Signed-off-by: Ricardo González Moreno * Refs #19960. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Fix warning generating TypeObject from IDL file (#266) * Refs #20003. Fix warnings. Signed-off-by: Ricardo González Moreno * Refs #20003: do not generate empty namespaces Signed-off-by: JLBuenoLopez-eProsima * Refs #20003. Fix warnings and new ReturnCode_t Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno Signed-off-by: JLBuenoLopez-eProsima Co-authored-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Fix tests for common struct name in different modules (#268) * Refs #20052: fix tests Signed-off-by: JLBuenoLopez-eProsima * Refs #20052: update submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Add argument to change default unbounded countainer max size (#270) * Refs #20056. Argument to change max size of unbounded containers Signed-off-by: Ricardo González Moreno * Refs #20056. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Fix CLang warning in generated code about unused lambda capture (#269) * Refs #19837: fix Clang warning, unused lambda capture Signed-off-by: JLBuenoLopez-eProsima * Refs #19837: update dds types test submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Support for C++ enum class (#271) * Refs #20063. Support for C++ enum class Signed-off-by: Ricardo González Moreno * Refs #20063. Update submodule Signed-off-by: Ricardo González Moreno * Refs #20063. Update submodule and use Context Signed-off-by: Ricardo González Moreno * Refs #20063. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Use include header which will be used (#272) * Refs #20070. Using includes which will be used Signed-off-by: Ricardo González Moreno * Refs #20070. Fix enum casting Signed-off-by: Ricardo González Moreno * Refs #20070. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Fix using final string for new annotations (#273) * Refs #20070. Update submodule Signed-off-by: Ricardo González Moreno * Refs #20070. Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Add replacement for "dds" modules and -no-dependencies option to fastddsgen (#275) * Added dds to the list of IDL module replacements Signed-off-by: adriancampo * Added -no-dependencies option to avoid generating files for dependencies Signed-off-by: adriancampo * Apply suggestions from code review Co-authored-by: Ricardo González Signed-off-by: adriancampo * Use constants for arguments Signed-off-by: adriancampo * Fixed args sorting Signed-off-by: adriancampo --------- Signed-off-by: adriancampo Co-authored-by: Ricardo González Signed-off-by: Ricardo González Moreno * TypeObject generation (#280) * Typeobjects with tests (#255) * Fix tests for common struct name in different modules (#268) * Refs #20052: fix tests Signed-off-by: JLBuenoLopez-eProsima * Refs #20052: update submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima * Added TypeObject tests with templates for primitives and strings structures. Signed-off-by: adriancampo * Added TypeObject tests for most cases. Signed-off-by: adriancampo * Added TypeObject tests for unions enums and annotations. Signed-off-by: adriancampo * Added missing checks Signed-off-by: adriancampo * API changes. Additional checks. Signed-off-by: adriancampo * Changes if TypeIdentifiers checks. Signed-off-by: adriancampo * API changes. Fixed errors. Signed-off-by: adriancampo * Tests use gtest now. Signed-off-by: adriancampo * Format changes. Signed-off-by: adriancampo * Fixed namespaces, inheritance check and type functions. Signed-off-by: adriancampo * Typo Signed-off-by: adriancampo * Refs #19595: -typeobject argument is deprecated. TypeObject files will always be generated Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix copyright and include header order. Remove unused headers Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix TypeObjectRegistry::get_type_identifiers call Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix TypeObjectRegistry::get_type_objects call Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: remove const tests: constants do not have TypeObject Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix templates. Remove non-required parameter Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: simplify test templates and include collection and string tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: refactor struct TypeObject test Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: refactor bitset TypeObject test Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: refactor bitset TypeObject tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix enum type TypeObject tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix enum literals TypeObject test Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix bitmask TypeObject tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix type detail annotations checks Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix alias tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix union type TypeObject tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix union member tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: reorder templates. Fixes for string/wstring Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: check Collection TypeIdentifier EquivalenceKind Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix discriminator API according to review suggestion Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: array type tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix map type tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: map type tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix build errors Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: check TypeIdentifier and TypeObject consistency Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: remove non-necessary template attribute Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: member applied annotations check Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: remove non necessary templates. Check already done within consistency methods Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: check dimension/union label Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: add annotation type test Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: w/string type tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: REMOVE: comment TypeObject code in order to build Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: update submodules Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fixes in TypeObject tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: update dds types test submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: update idl parser submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: fix Fast DDS include Signed-off-by: JLBuenoLopez-eProsima * Refs #19595: update submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: adriancampo Co-authored-by: José Luis Bueno López <69244257+JLBuenoLopez-eProsima@users.noreply.github.com> Co-authored-by: JLBuenoLopez-eProsima * Refs #19906: introduce new templates to generate TypeObject code Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: TypeObject header implementation Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: minor fixes Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: move anonymous collection name generator to common code Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: skeleton Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: improve verbatim annotation test. Alias custom annotations should be included only once Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: fix typo Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: alias type implementation Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: struct_type implementation Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: fix sequential member id Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: struct members Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: refactor TypeObjectSupport infrastructure Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: refactor TypeObjectSupport Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: do not execute code in main function Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: assign proper member id with inheritance Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: refactor register struct type Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: fix calling templates with proper parameters Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: annotation impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: enum impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: w/string impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: several fixes in tests Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: alias impl. Annotation refactor Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: fix get TypeObject template Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: union impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: union member impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: bitset impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: bitmask impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: sequences impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: small refactor to adapt to new throwing API Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: update unbounded collections name Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: arrays impl Signed-off-by: JLBuenoLopez-eProsima * Refs #19906: map impl Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: support for not applied annotations Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: generate TypeObject tests only for main dependency Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix expected flags Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: option to avoid generating type object support files Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: delete legacy TypeObject template Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: integration, fix use of external and other minor bugs/typos Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: test integration: fix unbounded collections, correctly test collections, correctly check TypeIdentifiers, correctly use fixed_string API Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: use variables Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix conflicts after rebase Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: no type support option disables also TypeObject support generation Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix Fast DDS include Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: avoid warning Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: use genapi module conversion in TypeObject templates Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: apply review suggestions Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: create register_type_object_representation method in TypeSupport Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix map keys Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: add sequence order check and fixes in map keys and minimal annotation parameters Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: update IDL Parser submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix Windows warnings C4456: declararion hides previous local declaration Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix collection name in case of enum types Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: update IDL Parser submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: fix Windows warning Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: update IDL Parser submodule Signed-off-by: JLBuenoLopez-eProsima * Refs #20129: apply review suggestions Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: adriancampo Co-authored-by: Adrian del Campo <107918259+adriancampo@users.noreply.github.com> Signed-off-by: Ricardo González Moreno * Fix bounded collections with unbounded elements (#295) * Refs #20335: fix bounded collections with unbounded elements Signed-off-by: JLBuenoLopez-eProsima * Refs #20335: update submodules Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Test case: scoped structures (#299) * Increase test name uniqueness Signed-off-by: JLBuenoLopez-eProsima * Update dds types tests submodule Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Update FastDDSGen tests for indirect hashes (#307) * Refs #20533: Fixed tests for member_id of unions. Signed-off-by: adriancampo * Refs #20533: Fix for maps equiv_kind. Signed-off-by: adriancampo * Refs #20533: Removed unnecessary checks. Signed-off-by: adriancampo * Refs #20533: Updated submodule. Signed-off-by: adriancampo * Refs #20533: Added check for id2. Signed-off-by: adriancampo * Refs #20533: Added check for TK_NONE keys Signed-off-by: adriancampo --------- Signed-off-by: adriancampo Signed-off-by: Ricardo González Moreno * Support new fastdds naming (#315) * Refs #19451. Support new fastdds naming Signed-off-by: Ricardo González Moreno * Refs #19451. Fix in swig cmake files Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Fix after rebase Signed-off-by: Ricardo González Moreno * New implementation for unions (#310) * Refs #19451. First implementation Signed-off-by: Ricardo González Moreno * Refs #19451. Fixes Signed-off-by: Ricardo González Moreno * Refs #19451. Remove not needed functions on template Signed-off-by: Ricardo González Moreno * Refs #19451. Remove unused template macros Signed-off-by: Ricardo González Moreno * Refs #19451.- Fix externals Signed-off-by: Ricardo González Moreno * Refs #19451.- Fix fixed_string Signed-off-by: Ricardo González Moreno * Refs #19451.- Fix warnings Signed-off-by: Ricardo González Moreno * Refs #19451.- Update submodule Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno * Fix TypeObjectPair API (#296) * Refs #20335: fix TypeObjectPair API Signed-off-by: JLBuenoLopez-eProsima * Refs #20335: use new Fast DDS headers Signed-off-by: JLBuenoLopez-eProsima --------- Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: Ricardo González Moreno * Refs #20734. Fix windows linkage Signed-off-by: Ricardo González Moreno * Apply suggestion Signed-off-by: Ricardo González Moreno * Update submodule Signed-off-by: Ricardo González Moreno * Apply suggestion Co-authored-by: José Luis Bueno López <69244257+JLBuenoLopez-eProsima@users.noreply.github.com> --------- Signed-off-by: Ricardo González Moreno Signed-off-by: JLBuenoLopez-eProsima Signed-off-by: adriancampo Co-authored-by: Ricardo González Co-authored-by: Adrian del Campo <107918259+adriancampo@users.noreply.github.com> --- .github/fastddsgen.meta | 6 + .github/workflows/reusable-ubuntu-ci.yaml | 10 +- .github/workflows/ubuntu-ci.yaml | 7 +- resources/Custom.stg | 7 +- .../eprosima/fastcdr/idl/context/Context.java | 18 +- .../fastcdr/idl/templates/FastCdrCommon.stg | 10 + .../fastcdr/idl/templates/JavaType.stg | 6 +- .../fastcdr/idl/templates/TypesHeader.stg | 861 +++--- .../fastcdr/idl/templates/TypesHeaderv1.stg | 953 ------- .../fastcdr/idl/templates/TypesSource.stg | 1413 ---------- .../fastcdr/idl/templates/TypesSourcev1.stg | 2341 ----------------- .../idl/templates/TypesSwigInterface.stg | 75 +- .../eprosima/fastcdr/idl/util/CdrVersion.java | 15 - .../java/com/eprosima/fastdds/fastddsgen.java | 650 ++--- .../eprosima/fastdds/idl/grammar/Context.java | 281 +- .../parser/typecode/PrimitiveTypeCode.java | 11 +- .../idl/parser/typecode/StringTypeCode.java | 16 +- .../idl/parser/typecode/UnionTypeCode.java | 2 +- .../fastdds/idl/templates/CMakeLists.stg | 33 +- .../fastdds/idl/templates/DDSPubSubMain.stg | 103 - .../idl/templates/DDSPubSubTypeHeader.stg | 98 +- .../idl/templates/DDSPubSubTypeSource.stg | 120 +- .../templates/DDSPubSubTypeSwigInterface.stg | 78 - .../idl/templates/DDSPublisherHeader.stg | 103 - .../idl/templates/DDSPublisherSource.stg | 103 - .../idl/templates/DDSSubscriberHeader.stg | 103 - .../idl/templates/DDSSubscriberSource.stg | 105 +- .../fastdds/idl/templates/JNIHeader.stg | 88 +- .../fastdds/idl/templates/JNISource.stg | 85 - .../fastdds/idl/templates/JavaSource.stg | 93 - .../idl/templates/SerializationHeader.stg | 58 +- .../idl/templates/SerializationSource.stg | 75 +- .../idl/templates/SerializationTestSource.stg | 72 +- .../idl/templates/TypeObjectHeader.stg | 181 -- .../idl/templates/TypeObjectSource.stg | 1914 -------------- .../templates/TypeObjectTestingTestSource.stg | 1416 ++++++++++ .../idl/templates/TypesCdrAuxHeader.stg | 100 +- .../idl/templates/TypesCdrAuxHeaderImpl.stg | 175 +- .../idl/templates/XTypesTypeObjectHeader.stg | 100 + .../idl/templates/XTypesTypeObjectSource.stg | 1102 ++++++++ .../fastdds/idl/templates/eprosima.stg | 183 ++ .../java/com/eprosima/fastdds/util/Utils.java | 7 + .../com/eprosima/fastdds/FastDDSGenTest.java | 28 +- thirdparty/dds-types-test | 2 +- thirdparty/idl-parser | 2 +- 45 files changed, 4089 insertions(+), 9120 deletions(-) delete mode 100644 src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeaderv1.stg delete mode 100644 src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg delete mode 100644 src/main/java/com/eprosima/fastcdr/idl/templates/TypesSourcev1.stg delete mode 100644 src/main/java/com/eprosima/fastcdr/idl/util/CdrVersion.java delete mode 100644 src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg delete mode 100644 src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg create mode 100644 src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg create mode 100644 src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg create mode 100644 src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg diff --git a/.github/fastddsgen.meta b/.github/fastddsgen.meta index 19f3b790..7dc38bdb 100644 --- a/.github/fastddsgen.meta +++ b/.github/fastddsgen.meta @@ -1,6 +1,12 @@ { "names": { + "fastdds": { + "cmake-args": [ + "-DEPROSIMA_BUILD_TESTS=ON" + + ] + }, "fastdds_python": { "cmake-args": [ "-DBUILD_TESTING=ON" diff --git a/.github/workflows/reusable-ubuntu-ci.yaml b/.github/workflows/reusable-ubuntu-ci.yaml index 50b43d35..a680508a 100644 --- a/.github/workflows/reusable-ubuntu-ci.yaml +++ b/.github/workflows/reusable-ubuntu-ci.yaml @@ -122,15 +122,7 @@ jobs: cmake --version colcon build --event-handlers=console_direct+ --mixin rel-with-deb-info ccache --metas src/fastddsgen/.github/fastddsgen.meta - - name: Test fastddsgen with fastcdr v1 - if: startsWith(inputs.fastcdr_branch, '1') - run: | - source install/local_setup.bash - cd src/fastddsgen - ./gradlew test -Dcdr_version=v1 -Dblacklist_tests=external,optional - - - name: Test fastddsgen with fastcdr v2 - if: ${{ ! startsWith(inputs.fastcdr_branch, '1') }} + - name: Test fastddsgen run: | source install/local_setup.bash cd src/fastddsgen diff --git a/.github/workflows/ubuntu-ci.yaml b/.github/workflows/ubuntu-ci.yaml index a4f0c455..750232a5 100644 --- a/.github/workflows/ubuntu-ci.yaml +++ b/.github/workflows/ubuntu-ci.yaml @@ -7,8 +7,8 @@ on: description: 'foonathan_memory_vendor branch to be used' required: true type: string - fastcdr_version: - description: 'Fast CDR branches to be used. Enclose the branch names like ["1.1.x", "master"], then in single quotes' + fastcdr_branch: + description: 'Fast CDR branches to be used' required: true type: string fastdds_branch: @@ -40,14 +40,13 @@ jobs: java_version: - 'openjdk-11-jdk' - 'openjdk-19-jdk' - fastcdr_version: ${{ fromJson(inputs.fastcdr_version || '["master"]') }} uses: ./.github/workflows/reusable-ubuntu-ci.yaml with: os_image: ${{ matrix.os_image }} java_version: ${{ matrix.java_version }} foonathan_memory_vendor_branch: ${{ inputs.foonathan_memory_vendor_branch || 'master' }} - fastcdr_branch: ${{ matrix.fastcdr_version }} + fastcdr_branch: ${{ inputs.fastcdr_branch || 'master' }} fastdds_branch: ${{ inputs.fastdds_branch || github.head_ref }} fastdds_python_branch: ${{ inputs.fastdds_python_branch || '3.0.x-devel' }} fastddsgen_branch: ${{ inputs.fastddsgen_branch || github.ref || '4.0.x-devel' }} diff --git a/resources/Custom.stg b/resources/Custom.stg index 67de7a72..b2d51f96 100644 --- a/resources/Custom.stg +++ b/resources/Custom.stg @@ -8,6 +8,11 @@ $definitions; separator="\n"$ module(ctx, parent, module, definition_list) ::= << +// In case of defining C++ namespaces here (like `namespace $module.name$ {`, property +// `Context.using_explicitly_modules_custom_property` should be added to the related TemplateGroup. +// Example: +// tmanager.addGroup("Custom.stg").enable_custom_property(Context.using_explicitly_modules_custom_property); + $definition_list$ >> @@ -84,7 +89,7 @@ string_type(ctx, string) ::= <<>> wide_string_type(ctx, wstring) ::= <<>> -array_declarator(ctx, array, array_type) ::= <<>> +array_declarator(ctx, array) ::= <<>> interface(ctx, parent, interface, export_list) ::= <<>> diff --git a/src/main/java/com/eprosima/fastcdr/idl/context/Context.java b/src/main/java/com/eprosima/fastcdr/idl/context/Context.java index 58f1c4a4..afeb92dd 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/context/Context.java +++ b/src/main/java/com/eprosima/fastcdr/idl/context/Context.java @@ -39,27 +39,13 @@ public interface Context public String getHeaderGuardName (); - public boolean isGenerateTypeObject(); - - public boolean isGenerateTypesC(); - public boolean isGenerateTypesROS2(); + public boolean isGenerateTypeObjectSupport(); + public boolean isCdr(); public boolean isFastcdr(); - public boolean isCdr_v1(); - - public boolean isCdr_v2(); - - public boolean isCdr_both(); - - public void isSetCdrv1Templates(); - - public void isUnsetCdrv1Templates(); - - public boolean isCdrv1TemplatesEnabled(); - /*** End ***/ } diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg index 12bc5f26..0f8f316d 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg @@ -59,3 +59,13 @@ member_array_cstring_destructor(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$ { free(str); }$endif$>> + +member_default_init(member) ::= <% +$if(member.annotationDefault)$ + {$member.annotationDefaultValue$} +$elseif(!member.annotationOptional && !member.annotationExternal)$ +$if(member.typecode.initialValue)$ + {$member.typecode.initialValue$} +$endif$ +$endif$ +%> diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/JavaType.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/JavaType.stg index bcd2e107..f9912de9 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/JavaType.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/JavaType.stg @@ -109,7 +109,7 @@ public class $union.name$ }; separator="\n"$ } - public $union.discriminator.javaTypename$ getDiscriminator() + public $union.discriminator.typecode.javaTypename$ getDiscriminator() { return d__; } @@ -127,7 +127,7 @@ public class $union.name$ $endif$ } - public void set$member.javaName$($union.discriminator.javaTypename$ discriminator, $member.typecode.javaTypename$ $member.name$) + public void set$member.javaName$($union.discriminator.typecode.javaTypename$ discriminator, $member.typecode.javaTypename$ $member.name$) throws Exception { $if(member.default)$ @@ -188,7 +188,7 @@ public class $union.name$ return false; } - $union.discriminator.javaTypename$ d__; + $union.discriminator.typecode.javaTypename$ d__; $union.members : { member |private $member.typecode.javaTypename$ $member.name$_; }; separator="\n"$ diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg index 72394ffd..93200dbe 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -18,35 +18,46 @@ import "com/eprosima/fastdds/idl/templates/eprosima.stg" import "FastCdrCommon.stg" main(ctx, definitions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, ".h"], description=["This header file contains the declaration of the described types in the IDL file."])$ +$fileHeader(ctx=ctx, file=[ctx.filename, ".hpp"], description=["This header file contains the declaration of the described types in the IDL file."])$ -$if(ctx.cdr_both)$ -#include -#include "$ctx.filename$v1.h" - -#if FASTCDR_VERSION_MAJOR > 1 -$endif$ - -#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ -#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ +#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_HPP_ +#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_HPP_ +$if(ctx.thereIsArray)$ #include +$endif$ +$if(ctx.thereIsBitset)$ #include +$endif$ #include +$if(ctx.thereIsUnion)$ +#include +$endif$ +$if(ctx.thereIsMap)$ #include +$endif$ +$if(ctx.thereIsString)$ #include +$endif$ +#include +$if(ctx.thereIsSequence)$ #include +$endif$ +$if(ctx.thereIsString)$ #include +$endif$ +$if(ctx.thereIsExternalAnnotation)$ #include +$endif$ +$if(ctx.thereIsOptionalAnnotation)$ #include - -$if(ctx.printexception)$ -#include <$ctx.product$/exceptions/UserException.h> +$endif$ +$if(ctx.thereIsUnion)$ +#include $endif$ -$ctx.directIncludeDependencies : {include | #include "$include$.h"}; separator="\n"$ - +$ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$ #if defined(_WIN32) #if defined(EPROSIMA_USER_DLL_EXPORT) @@ -72,42 +83,11 @@ $ctx.directIncludeDependencies : {include | #include "$include$.h"}; separator=" #define $ctx.fileNameUpper$_DllAPI #endif // _WIN32 -$if(ctx.cdr)$ -namespace eprosima { -namespace fastcdr { -class Cdr; -$if(ctx.cdr)$ -class CdrSizeCalculator; -$endif$ -} // namespace fastcdr -} // namespace eprosima - -$endif$ - -$if(ctx.fastcdr)$ -namespace eprosima { -namespace fastcdr { -class FastCdr; -} // namespace fastcdr -} // namespace eprosima - -$endif$ - -$if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { type | -$sequences_definition(type.value)$ -}; separator="\n"$ -$endif$ - - $definitions; separator="\n"$ -#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ +#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$_HPP_ $"\n"$ -$if(ctx.cdr_both)$ -#endif // FASTCDR_VERSION_MAJOR > 1 -$endif$ >> module(ctx, parent, module, definition_list) ::= << @@ -118,19 +98,17 @@ $definition_list$ } // namespace $module.name$ >> -definition_list(definitions) ::= << -$definitions; separator="\n"$ ->> - annotation(ctx, annotation) ::= << +$if(annotation.enums || annotation.typeDefs || annotation.constDecls)$ namespace $annotation.name$ { $annotation.enums : { enum | $enum_type(ctx=ctx, parent=annotation, enum=enum)$}; separator="\n"$ - $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef)$}; separator="\n"$ + $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef, typedefs_type="", declarator_type="")$}; separator="\n"$ - $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const)$}; separator="\n"$ + $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const, const_type="")$}; separator="\n"$ } // namespace $annotation.name$ +$endif$ >> interface(ctx, parent, interface, export_list) ::= << @@ -146,43 +124,17 @@ public: }; >> -export_list(exports) ::= << -$exports; separator="\n"$ ->> - -exception(ctx, parent, exception) ::= <<>> - -operation(ctx, parent, operation, param_list, operation_type) ::= << - -$operation_type$ -$param_list$ - ->> - -param_list(parameters) ::= <<>> - -param(parameter, parameter_type) ::= << - -$parameter_type$ - +const_decl(ctx, parent, const, const_type) ::= << +$const_type$ +const $const.typeCode.cppTypename$ $const.name$ = $const.value$; >> -const_decl(ctx, parent, const, const_type) ::= <<$const_type$$if(ctx.inScopedFile)$$if(const.parent)$$if(const.parent.isInterface)$static $endif$$endif$const $const.typeCode.cppTypename$ $const.name$$if(!const.parent)$ = $const.value$$elseif(!const.parent.isInterface)$ = $const.value$$elseif(!const.typeCode.isType_5)$$if(!const.typeCode.isType_6)$ = $const.value$$endif$$endif$;$endif$>> - typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << $declarator_type$ $typedefs_type$ $typedefs : { typedef | -$if(ctx.generateTypesC)$ -$if(typedef.typedefContentTypeCode.isSequenceType)$ -$sequences_definition_impl(typecode=typedef.typedefContentTypeCode, typename=typedef.name)$ -$else$ typedef $typedef.typedefContentTypeCode.cppTypename$ $typedef.name$; -$endif$ -$else$ -typedef $typedef.typedefContentTypeCode.cppTypename$ $typedef.name$; -$endif$ }; separator="\n"$ >> @@ -199,58 +151,131 @@ public: /*! * @brief Default constructor. */ - eProsima_user_DllExport $struct.name$(); + eProsima_user_DllExport $struct.name$() + $if(struct.inheritance)$ + : $struct_inherit_default_init(struct.inheritance)$ + $endif$ + { + } /*! * @brief Default destructor. */ - eProsima_user_DllExport ~$struct.name$(); + eProsima_user_DllExport ~$struct.name$() + { + $struct.members:{ member |$member_destructor(ctx=ctx, member=member)$}; separator="\n"$ + } /*! * @brief Copy constructor. * @param x Reference to the object $struct.scopedname$ that will be copied. */ eProsima_user_DllExport $struct.name$( - const $struct.name$& x); + const $struct.name$& x) + $if(struct.inheritance)$ + : $struct_inherit_copy_init(struct.inheritance)$ + $endif$ + { + $if(struct.members)$ + $struct.members:{ member | + m_$member.name$ = x.m_$member.name$; + }; separator="\n"$ + $else$ + static_cast(x); + $endif$ + } /*! * @brief Move constructor. * @param x Reference to the object $struct.scopedname$ that will be copied. */ eProsima_user_DllExport $struct.name$( - $struct.name$&& x) noexcept; + $struct.name$&& x) noexcept + $if(struct.inheritance)$ + : $struct_inherit_move_init(struct.inheritance)$ + $endif$ + + { + $if(struct.members)$ + $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ + $else$ + static_cast(x); + $endif$ + } /*! * @brief Copy assignment. * @param x Reference to the object $struct.scopedname$ that will be copied. */ eProsima_user_DllExport $struct.name$& operator =( - const $struct.name$& x); + const $struct.name$& x) + { + $if(struct.inheritance)$$struct.inheritance.scopedname$::operator =(x);$endif$ + + $if(struct.members)$ + $struct.members:{ member | + m_$member.name$ = x.m_$member.name$; + }; separator="\n"$ + $else$ + static_cast(x); + $endif$ + + return *this; + } /*! * @brief Move assignment. * @param x Reference to the object $struct.scopedname$ that will be copied. */ eProsima_user_DllExport $struct.name$& operator =( - $struct.name$&& x) noexcept; + $struct.name$&& x) noexcept + { + $if(struct.inheritance)$$struct.inheritance.scopedname$::operator =(std::move(x));$endif$ + + $if(struct.members)$ + $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ + $else$ + static_cast(x); + $endif$ + + return *this; + } /*! * @brief Comparison operator. * @param x $struct.scopedname$ object to compare. */ eProsima_user_DllExport bool operator ==( - const $struct.name$& x) const; + const $struct.name$& x) const + { + $if(struct.inheritance)$if ($struct.inheritance.scopedname$::operator !=(x)) + { + return false; + } + $endif$ + + $if(!struct.members)$ + static_cast(x); + return true; + $else$ + return ($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$); + $endif$ + } /*! * @brief Comparison operator. * @param x $struct.scopedname$ object to compare. */ eProsima_user_DllExport bool operator !=( - const $struct.name$& x) const; + const $struct.name$& x) const + { + return !(*this == x); + } $struct.members:{ member | $public_member_declaration(member)$}; separator="\n"$ - $serialization_functions(struct)$ + $extensions : { extension | $extension$}; separator="\n"$ + private: $struct.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ @@ -258,13 +283,6 @@ private: }; >> -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - union_type(ctx, parent, union, extensions, switch_type) ::= << $switch_type$ /*! @@ -278,91 +296,234 @@ public: /*! * @brief Default constructor. */ - eProsima_user_DllExport $union.name$(); + eProsima_user_DllExport $union.name$() + { + $if(union.defaultMember)$ + $union.defaultMember.name$_(); + $endif$ + } /*! * @brief Default destructor. */ - eProsima_user_DllExport ~$union.name$(); + eProsima_user_DllExport ~$union.name$() + { + if (member_destructor_) + { + member_destructor_(); + } + } /*! * @brief Copy constructor. * @param x Reference to the object $union.scopedname$ that will be copied. */ eProsima_user_DllExport $union.name$( - const $union.name$& x); + const $union.name$& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + $union.members:{ member | + case $member.id$: + $member.name$_() = x.m_$member.name$; + break; + }; separator="\n"$ + } + } /*! * @brief Move constructor. * @param x Reference to the object $union.scopedname$ that will be copied. */ eProsima_user_DllExport $union.name$( - $union.name$&& x) noexcept; + $union.name$&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + $union.members:{ member | + case $member.id$: + $member.name$_() = std::move(x.m_$member.name$); + break; + }; separator="\n"$ + } + } /*! * @brief Copy assignment. * @param x Reference to the object $union.scopedname$ that will be copied. */ eProsima_user_DllExport $union.name$& operator =( - const $union.name$& x); + const $union.name$& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + $union.members:{ member | + case $member.id$: + $member.name$_() = x.m_$member.name$; + break; + }; separator="\n"$ + } + + return *this; + } /*! * @brief Move assignment. * @param x Reference to the object $union.scopedname$ that will be copied. */ eProsima_user_DllExport $union.name$& operator =( - $union.name$&& x) noexcept; + $union.name$&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + $union.members:{ member | + case $member.id$: + $member.name$_() = std::move(x.m_$member.name$); + break; + }; separator="\n"$ + } + + return *this; + } /*! * @brief Comparison operator. * @param x $union.scopedname$ object to compare. */ eProsima_user_DllExport bool operator ==( - const $union.name$& x) const; + const $union.name$& x) const + { + bool ret_value {false}; + + if (m__d == x.m__d && + selected_member_ == x.selected_member_) + { + switch (selected_member_) + { + $union.members:{ member | + case $member.id$: + ret_value = (m_$member.name$ == x.m_$member.name$); + break; + }; separator="\n"$ + } + } + + return ret_value; + } /*! * @brief Comparison operator. * @param x $union.scopedname$ object to compare. */ eProsima_user_DllExport bool operator !=( - const $union.name$& x) const; + const $union.name$& x) const + { + return !(*this == x); + } /*! * @brief This function sets the discriminator value. * @param __d New value for the discriminator. - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. */ eProsima_user_DllExport void _d( - $union.discriminator.cppTypename$ __d); + $union.discriminator.typecode.cppTypename$ __d) + { + bool valid_discriminator = false; + + switch (__d) + { + $union.members:{ member | + $member.labels:{ label | case $label$:}; separator="\n"$ + $if(member.default)$ + default: + $endif$ + if ($member.id$ == selected_member_) + { + valid_discriminator = true; + \} + break; + }; separator="\n"$ + } + + if (!valid_discriminator) + { + throw eprosima::fastcdr::exception::BadParamException("Discriminator doesn't correspond with the selected union member"); + } + + m__d = __d; + } /*! * @brief This function returns the value of the discriminator. * @return Value of the discriminator */ - eProsima_user_DllExport $union.discriminator.cppTypename$ _d() const; - - /*! - * @brief This function returns a reference to the discriminator. - * @return Reference to the discriminator. - */ - eProsima_user_DllExport $union.discriminator.cppTypename$& _d(); + eProsima_user_DllExport $union.discriminator.typecode.cppTypename$ _d() const + { + return m__d; + } - $union.members:{ member | $public_unionmember_declaration(member)$}; separator="\n"$ - $serialization_functions(union)$ - $extensions : {extension | $extension$}; separator="\n"$ -private: + $union.members: { member | $public_union_member_declaration(union, member)$}; separator="\n"$ - $union.discriminator.cppTypename$ m__d; + $if(!union.defaultMember)$ + void _default() + { + if (member_destructor_) + { + member_destructor_(); + } - $union.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ -}; ->> + selected_member_ = 0x0FFFFFFFu; + } + $endif$ -element_type(ctx, element, type_element, declarator) ::= << + $extensions : {extension | $extension$}; separator="\n"$ -$type_element$ -$declarator$ +private: + $union.members: { member | + $member_type_declaration(member)$& $member.name$_() + { + if ($member.id$ != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + \} + + selected_member_ = $member.id$; + $if(member.typecode.primitive)$ + member_destructor_ = nullptr; + m_$member.name$ = $member_default_init(member)$; + $else$ + member_destructor_ = [&]() {$union_member_destroy_call(member)$\}; + new(&m_$member.name$) $member_type_declaration(member)$(); + $endif$; + \} + + return m_$member.name$; + \} + }; separator="\n"$ + + $union.discriminator.typecode.cppTypename$ m__d {$union.defaultvalue$}; + + union + { + $union.members:{ member | $union_member_declaration(member=member)$}; separator="\n"$ + }; + + uint32_t selected_member_ {0x0FFFFFFFu}; + + std::function member_destructor_; +}; >> bitset_type(ctx, parent, bitset, extensions) ::= << @@ -377,63 +538,130 @@ public: /*! * @brief Default constructor. */ - eProsima_user_DllExport $bitset.name$(); + eProsima_user_DllExport $bitset.name$() + $if(bitset.inheritance)$ + : $struct_inherit_default_init(bitset.inheritance)$ + $endif$ + { + } /*! * @brief Default destructor. */ - eProsima_user_DllExport ~$bitset.name$(); + eProsima_user_DllExport ~$bitset.name$() + { + } /*! * @brief Copy constructor. * @param x Reference to the object $bitset.scopedname$ that will be copied. */ eProsima_user_DllExport $bitset.name$( - const $bitset.name$& x); + const $bitset.name$& x) + $if(bitset.inheritance)$ + : $struct_inherit_copy_init(bitset.inheritance)$ + $endif$ + { + m_bitset = x.m_bitset; + } /*! * @brief Move constructor. * @param x Reference to the object $bitset.scopedname$ that will be copied. */ eProsima_user_DllExport $bitset.name$( - $bitset.name$&& x) noexcept; + $bitset.name$&& x) noexcept + $if(bitset.inheritance)$ + : $struct_inherit_move_init(bitset.inheritance)$ + $endif$ + { + m_bitset = x.m_bitset; + } /*! * @brief Copy assignment. * @param x Reference to the object $bitset.scopedname$ that will be copied. */ eProsima_user_DllExport $bitset.name$& operator =( - const $bitset.name$& x); + const $bitset.name$& x) + { + $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::operator =(x);$endif$ + + m_bitset = x.m_bitset; + + return *this; + } /*! * @brief Move assignment. * @param x Reference to the object $bitset.scopedname$ that will be copied. */ eProsima_user_DllExport $bitset.name$& operator =( - $bitset.name$&& x) noexcept; + $bitset.name$&& x) noexcept + { + $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::operator =(std::move(x));$endif$ + + m_bitset = x.m_bitset; + + return *this; + } /*! * @brief Comparison operator. * @param x $bitset.scopedname$ object to compare. */ eProsima_user_DllExport bool operator ==( - const $bitset.name$& x) const; + const $bitset.name$& x) const + { + $if(bitset.inheritance)$ if ($bitset.inheritance.scopedname$::operator !=(x)) return false;$endif$ + + return m_bitset == x.m_bitset; + } /*! * @brief Comparison operator. * @param x $bitset.scopedname$ object to compare. */ eProsima_user_DllExport bool operator !=( - const $bitset.name$& x) const; + const $bitset.name$& x) const + { + return !(*this == x); + } $bitset.bitfields:{ bitset | $public_bitfield_declaration(bitset)$}; separator="\n"$ - eProsima_user_DllExport std::bitset<$bitset.fullBitSize$> bitset() const; + eProsima_user_DllExport std::bitset<$bitset.fullBitSize$> bitset() const + { + std::string str_value; - eProsima_user_DllExport void bitset( - const std::bitset<$bitset.fullBitSize$>&); + $if(bitset.inheritance)$ + str_value = static_cast(this)->bitset().to_string() + str_value; + $endif$ - $serialization_functions(bitset)$ + str_value = m_bitset.to_string() + str_value; + + return std::bitset<$bitset.fullBitSize$>(str_value); + } + + eProsima_user_DllExport void bitset( + const std::bitset<$bitset.fullBitSize$>& bitset) + { + std::string str_value {bitset.to_string()}; + size_t base_diff {0}; + size_t last_post {std::string::npos}; + + $if(bitset.inheritance)$ + { + base_diff += $bitset.inheritance.fullBitSize$; + std::bitset<$bitset.inheritance.fullBitSize$> internal_bitset(str_value.substr(str_value.length() - base_diff, last_post)); + static_cast<$bitset.inheritance.scopedname$*>(this)->bitset(internal_bitset); + last_post = base_diff; + } + $endif$ + + base_diff += $bitset.bitSize$; + m_bitset = std::bitset<$bitset.bitSize$>(str_value.substr(str_value.length() - base_diff, last_post)); + } $extensions : { extension | $extension$}; separator="\n"$ @@ -448,7 +676,7 @@ enum_type(ctx, parent, enum) ::= << * @brief This class represents the enumeration $enum.name$ defined by the user in the IDL file. * @ingroup $ctx.trimfilename$ */ -enum $enum.name$ : uint32_t +enum class $enum.name$ : uint32_t { $enum.members:{ member | $member.name$}; separator=",\n"$ }; @@ -471,25 +699,6 @@ class $type.name$; >> -sequence_type(ctx, sequence, type_sequence) ::= << - -$type_sequence$ - ->> - -map_type(ctx, map, key_type, value_type) ::= << - -$key_type$ -$value_type$ - ->> - -string_type(ctx, string) ::= <<>> - -wide_string_type(ctx, wstring) ::= <<>> - -array_declarator(ctx, array, array_type) ::= <<>> - /***** Utils *****/ public_struct_inheritances(parent) ::= <<$parent.scopedname$>> @@ -501,12 +710,6 @@ $if(member.annotationOptional || member.annotationExternal)$ $public_member_common_declaration(member=member)$ $elseif(member.typecode.primitive)$ $public_member_primitive_declaration(member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_member_cstring_declaration(member=member)$ -$else$ -$public_member_common_declaration(member=member)$ -$endif$ $else$ $public_member_common_declaration(member=member)$ $endif$ @@ -518,34 +721,28 @@ public_member_primitive_declaration(member) ::= << * @param _$member.name$ New value for member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member_type_declaration(member)$ _$member.name$); + $member_type_declaration(member)$ _$member.name$) +{ + $\ $m_$member.name$ = _$member.name$; +} /*! * @brief This function returns the value of member $member.name$ * @return Value of member $member.name$ */ -eProsima_user_DllExport $member_type_declaration(member)$ $member.name$() const; +eProsima_user_DllExport $member_type_declaration(member)$ $member.name$() const +{ + return m_$member.name$; +} /*! * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ */ -eProsima_user_DllExport $member_type_declaration(member)$& $member.name$(); ->> - -public_member_cstring_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - const $member_type_declaration(member)$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -eProsima_user_DllExport const $member_type_declaration(member)$ $member.name$() const; +eProsima_user_DllExport $member_type_declaration(member)$& $member.name$() +{ + return m_$member.name$; +} >> public_member_common_declaration(member) ::= << @@ -554,26 +751,38 @@ public_member_common_declaration(member) ::= << * @param _$member.name$ New value to be copied in member $member.name$ */ eProsima_user_DllExport void $member.name$( - const $member_type_declaration(member)$& _$member.name$); + const $member_type_declaration(member)$& _$member.name$) +{ + $\ $m_$member.name$ = _$member.name$; +} /*! * @brief This function moves the value in member $member.name$ * @param _$member.name$ New value to be moved in member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member_type_declaration(member)$&& _$member.name$); + $member_type_declaration(member)$&& _$member.name$) +{ + $\ $m_$member.name$ = std::move(_$member.name$); +} /*! * @brief This function returns a constant reference to member $member.name$ * @return Constant reference to member $member.name$ */ -eProsima_user_DllExport const $member_type_declaration(member)$& $member.name$() const; +eProsima_user_DllExport const $member_type_declaration(member)$& $member.name$() const +{ + return m_$member.name$; +} /*! * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ */ -eProsima_user_DllExport $member_type_declaration(member)$& $member.name$(); +eProsima_user_DllExport $member_type_declaration(member)$& $member.name$() +{ + return m_$member.name$; +} >> public_bitfield_declaration(member) ::= << @@ -583,13 +792,42 @@ $if(member.name)$ * @param _$member.name$ New value for member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member.spec.cppTypename$ _$member.name$); + $member.spec.cppTypename$ _$member.name$) +{ + int base = $member.basePosition$; +$if(member.spec.typecode.isType_7)$ + m_bitset.set(base, _$member.name$); +$else$ + int size = $member.spec.bitSize$; + for (int i = base; i < base + size; ++i) + { + m_bitset.set(i, !!(_$member.name$ & 0x01)); + _$member.name$ = _$member.name$ \>> 1; + } +$endif$ + +} /*! * @brief This function returns the value of member $member.name$ * @return Value of member $member.name$ */ -eProsima_user_DllExport $member.spec.cppTypename$ $member.name$() const; +eProsima_user_DllExport $member.spec.cppTypename$ $member.name$() const +{ + int base = $member.basePosition$; +$if(member.spec.typecode.isType_7)$ + return m_bitset.test(base); +$else$ + int size = $member.spec.bitSize$; + std::bitset<$member.spec.bitSize$> aux; + for (int i = 0; i < size; ++i) + { + aux.set(i, m_bitset.test(i + base)); + } + return static_cast<$member.spec.cppTypename$>(aux.to_ullong()); +$endif$ + +} $endif$ >> @@ -597,207 +835,164 @@ private_member_declaration(member) ::= << $member_type_declaration(member)$ m_$member.name$$member_default_init(member)$; >> -public_unionmember_declaration(member) ::= << +public_union_member_declaration(union, member) ::= << $if(member.annotationExternal)$ -$public_unionmember_common_declaration(member=member)$ +$public_union_member_common_declaration(union, member)$ $elseif(member.typecode.primitive)$ -$public_unionmember_primitive_declaration(member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_unionmember_cstring_declaration(member=member)$ +$public_union_member_primitive_declaration(union, member)$ $else$ -$public_unionmember_common_declaration(member=member)$ -$endif$ -$else$ -$public_unionmember_common_declaration(member=member)$ +$public_union_member_common_declaration(union, member)$ $endif$ >> -public_unionmember_primitive_declaration(member) ::= << +public_union_member_primitive_declaration(union, member) ::= << /*! * @brief This function sets a value in member $member.name$ * @param _$member.name$ New value for member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$ _$member.name$); + $member.typecode.cppTypename$ _$member.name$) +{ + $member.name$_() = _$member.name$; + $union_member_set_discriminator(member=member, defaultvalue=union.defaultvalue)$ +} /*! * @brief This function returns the value of member $member.name$ * @return Value of member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. */ -eProsima_user_DllExport $member.typecode.cppTypename$ $member.name$() const; +eProsima_user_DllExport $member.typecode.cppTypename$ $member.name$() const +{ + if ($member.id$ != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_$member.name$; +} /*! * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); ->> - -public_unionmember_cstring_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. */ -eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$ _$member.name$); +eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$() +{ + if ($member.id$ != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport const $member.typecode.cppTypename$ $member.name$() const; + return m_$member.name$; +} >> -public_unionmember_common_declaration(member) ::= << +public_union_member_common_declaration(union, member) ::= << /*! * @brief This function copies the value in member $member.name$ * @param _$member.name$ New value to be copied in member $member.name$ */ eProsima_user_DllExport void $member.name$( - const $member_type_declaration(member)$& _$member.name$); + const $member_type_declaration(member)$& _$member.name$) +{ + $member.name$_() = _$member.name$; + $union_member_set_discriminator(member=member, defaultvalue=union.defaultvalue)$ +} /*! * @brief This function moves the value in member $member.name$ * @param _$member.name$ New value to be moved in member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member_type_declaration(member)$&& _$member.name$); + $member_type_declaration(member)$&& _$member.name$) +{ + $member.name$_() = _$member.name$; + $union_member_set_discriminator(member=member, defaultvalue=union.defaultvalue)$ +} /*! * @brief This function returns a constant reference to member $member.name$ * @return Constant reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. */ -eProsima_user_DllExport const $member_type_declaration(member)$& $member.name$() const; +eProsima_user_DllExport const $member_type_declaration(member)$& $member.name$() const +{ + if ($member.id$ != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_$member.name$; +} /*! * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. */ -eProsima_user_DllExport $member_type_declaration(member)$& $member.name$(); +eProsima_user_DllExport $member_type_declaration(member)$& $member.name$() +{ + if ($member.id$ != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_$member.name$; +} >> -member_default_init(member) ::= <% -$if(member.annotationDefault)$ - {$member.annotationDefaultValue$} -$elseif(!member.annotationOptional && !member.annotationExternal)$ -$if(member.typecode.initialValue)$ - {$member.typecode.initialValue$} -$endif$ +member_move(member) ::= <% +$if(member.typecode.primitive)$ +m_$member.name$ = x.m_$member.name$; +$else$ +m_$member.name$ = std::move(x.m_$member.name$); $endif$ %> -serialization_functions(type) ::= << -$if(ctx.fastcdr)$ -/*! - * @brief This function serializes an object using FastCDR serialization. - * @param cdr FastCDR serialization object. - */ -eProsima_user_DllExport void serialize( - eprosima::fastcdr::FastCdr& cdr) const; - -/*! - * @brief This function deserializes an object using FastCDR serialization. - * @param cdr FastCDR serialization object. - */ -eProsima_user_DllExport void deserialize( - eprosima::fastcdr::FastCdr& cdr); - -$endif$ +union_member_declaration(member) ::= << +$member_type_declaration(member)$ m_$member.name$; >> -sequences_definition(typecode) ::= << -$if(typecode.contentTypeCode.isStructType)$ -$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ -class $typecode.contentTypeCode.name$; -$reverse(typecode.contentTypeCode.namespaces) : { ns | \} // $ns$}; separator="\n"$ +union_member_destroy_call(member) ::= <% +m_$member.name$. +$if(member.annotationExternal)$ +~external(); +$elseif(!member.typecode.isAliasType && (member.typecode.isStringType || member.typecode.isWStringType))$ +$if(member.typecode.isBounded && member.typecode.isStringType)$ +~fixed_string(); +$else$ +~basic_string(); $endif$ -$if(typecode.contentTypeCode.isUnionType)$ -$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ -class $typecode.contentTypeCode.name$; -$reverse(typecode.contentTypeCode.namespaces) : { ns | \} // $ns$}; separator="\n"$ +$elseif(!member.typecode.isAliasType && member.typecode.isSequenceType)$ +~vector(); +$elseif(!member.typecode.isAliasType && member.typecode.isArrayType)$ +~array(); +$elseif(!member.typecode.isAliasType && member.typecode.isMapType)$ +~map(); +$else$ +~$member.typecode.noScopedCppTypename$(); $endif$ +%> -$sequences_definition_impl(typecode=typecode, typename=typecode.cppTypename)$ ->> - -sequences_definition_impl(typecode, typename) ::= << - -class eProsima_user_DllExport $typename$ -{ -public: - $typename$(); - - $typename$( - uint32_t maximum); - - $typename$( - uint32_t length, - $typecode.contentTypeCode.cppTypename$* data, - bool release = false); - - $typename$( - const $typename$& $typename$_); - - $typename$& operator =( - const $typename$& $typename$_); - - ~$typename$(); - - $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ operator[]( - uint32_t index); - - const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ operator[]( - uint32_t index) const; - - void size( - uint32_t size); - - uint32_t size() const; - - void length( - uint32_t size); - - uint32_t length() const; - - uint32_t maximum() const; - - void value( - $typecode.contentTypeCode.cppTypename$* value); - - $typecode.contentTypeCode.cppTypename$* value( - bool orphan = false); - - const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ const$else$$endif$$else$$endif$* value() const; - - void release( - bool release); - - bool release() const; - - bool& release(); - - void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - void deserialize( - eprosima::fastcdr::Cdr& cdr); - -private: - - uint32_t maximum_ = $typecode.maxsize$; - - mutable uint32_t length_ = 0; +union_member_set_discriminator(member, defaultvalue) ::= <% +$if(member.default)$ +m__d = $defaultvalue$; +$else$ +m__d = $first(member.labels)$; +$endif$ +%> - mutable $typecode.contentTypeCode.cppTypename$* value_ = nullptr; +//{ Fast DDS-Gen extensions +module_conversion(ctx, parent, modules, definition_list) ::= << +$modules : { module | +namespace $module.name$ { +}; separator="\n"$ - bool release_ = true; +$definition_list$ - void free_memory(); -}; +$reverse(modules) : { module | +\} // namespace $module.name$ +}; separator="\n"$ >> +//} diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeaderv1.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeaderv1.stg deleted file mode 100644 index 172a127e..00000000 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeaderv1.stg +++ /dev/null @@ -1,953 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -group TypesHeader; - -import "com/eprosima/fastdds/idl/templates/eprosima.stg" -import "FastCdrCommon.stg" - -main(ctx, definitions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, ".h"], description=["This header file contains the declaration of the described types in the IDL file."])$ - -$if(ctx.cdr_both)$ -#include - -#if FASTCDR_VERSION_MAJOR == 1 -$endif$ - -#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ -#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ - -$if(ctx.printexception)$ -#include <$ctx.product$/exceptions/UserException.h> -$endif$ - -$ctx.directIncludeDependencies : {include | #include "$include$.h"}; separator="\n"$ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined($ctx.fileNameUpper$_SOURCE) -#define $ctx.fileNameUpper$_DllAPI __declspec( dllexport ) -#else -#define $ctx.fileNameUpper$_DllAPI __declspec( dllimport ) -#endif // $ctx.fileNameUpper$_SOURCE -#else -#define $ctx.fileNameUpper$_DllAPI -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define $ctx.fileNameUpper$_DllAPI -#endif // _WIN32 - -$if(ctx.cdr)$ -namespace eprosima { -namespace fastcdr { -class Cdr; -} // namespace fastcdr -} // namespace eprosima - -$endif$ - -$if(ctx.fastcdr)$ -namespace eprosima { -namespace fastcdr { -class FastCdr; -} // namespace fastcdr -} // namespace eprosima - -$endif$ - -$if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { type | -$sequences_definition(type.value)$ -}; separator="\n"$ -$endif$ - - -$definitions; separator="\n"$ - -#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ -$"\n"$ - -$if(ctx.cdr_both)$ -#endif // FASTCDR_VERSION_MAJOR == 1 -$endif$ ->> - -// TODO name -> module -module(ctx, parent, module, definition_list) ::= << -namespace $module.name$ { - $definition_list$ -} // namespace $module.name$ ->> - -definition_list(definitions) ::= << -$definitions; separator="\n"$ ->> - -annotation(ctx, annotation) ::= << -namespace $annotation.name$ { - $annotation.enums : { enum | $enum_type(ctx=ctx, parent=annotation, enum=enum)$}; separator="\n"$ - - $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef)$}; separator="\n"$ - - $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const)$}; separator="\n"$ - -} // namespace $annotation.name$ ->> - -interface(ctx, parent, interface, export_list) ::= << -/*! - * @brief This class represents the interface $interface.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -class $ctx.fileNameUpper$_DllAPI $interface.name$ $if(interface.bases)$: $interface.bases : {base |public $base.scopedname$}; separator=", "$$endif$ -{ -public: - - $export_list$ -}; ->> - -export_list(exports) ::= << -$exports; separator="\n"$ ->> - -exception(ctx, parent, exception) ::= << -$if(ctx.printexception)$ -/*! - * @brief This class implementes the user exception $exception.scopedname$ - * @ingroup $ctx.trimfilename$ - */ -class $exception.name$ : public eprosima::rpc::exception::UserException -{ -public: - - //! @brief Default constructor. - eProsima_user_DllExport $exception.name$(); - - /*! - * @brief Copy constructor. - * @param ex Exception to be copied. - */ - eProsima_user_DllExport $exception.name$( - const $exception.name$& ex); - - /*! - * @brief Move constructor. - * @param ex Exception to be moved. - */ - eProsima_user_DllExport $exception.name$( - $exception.name$&& ex); - - /*! - * @brief Copy assignment. - * @param ex Exception to be copied. - */ - eProsima_user_DllExport $exception.name$& operator =( - const $exception.name$ &ex); - - /*! - * @brief Move assignment. - * @param ex Exception to be moved. - */ - eProsima_user_DllExport $exception.name$& operator =( - $exception.name$&& ex); - - //! @brief Destructor. - eProsima_user_DllExport virtual ~$exception.name$() noexcept override; - - //! @brief This function throws the object as exception. - eProsima_user_DllExport virtual void raise() const; - - $exception.members:{ member |$public_member_declaration(member=member)$}; separator="\n"$ - - $size_functions(exception)$ - - $serialization_functions(exception)$ - -private: - - // Exception members - $exception.members:{ member |$private_member_declaration(member=member)$}; separator="\n"$ -}; -$endif$ ->> - -operation(ctx, parent, operation, param_list) ::= << -$if(ctx.printoperation)$ -virtual $paramRetType(operation.rettype)$ $operation.name$($paramDeclarations(params=operation.parameters)$) = 0; - -$endif$ ->> - -param_list(parameters) ::= <<>> - -param(parameter) ::= <<>> - -const_decl(ctx, parent, const, const_type) ::= << -$ctx.setCdrv1Templates$ -$const_type$ -$if(ctx.inScopedFile)$ -$if(const.parent)$ -$if(const.parent.isInterface)$ static $endif$ -$endif$ -const $const.typeCode.cppTypename$ $const.name$$if(!const.parent)$ = $const.value$$elseif(!const.parent.isInterface)$ = $const.value$$elseif(!const.typeCode.isType_5)$$if(!const.typeCode.isType_6)$ = $const.value$$endif$ -$endif$; -$endif$ -$ctx.unsetCdrv1Templates$ ->> - -fwd_decl(ctx, parent, type) ::= << -class $type.name$; - ->> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << -$ctx.setCdrv1Templates$ -$declarator_type$ -$typedefs_type$ -$typedefs : -{ typedef | -$if(ctx.generateTypesC)$ -$if(typedef.typedefContentTypeCode.isSequenceType)$ -$sequences_definition_impl(typecode=typedef.typedefContentTypeCode, typename=typedef.name)$ -$else$ -typedef $typedef.typedefContentTypeCode.cppTypename$ $typedef.name$; -$endif$ -$else$ -typedef $typedef.typedefContentTypeCode.cppTypename$ $typedef.name$; -$endif$ -$ctx.unsetCdrv1Templates$ -}; separator="\n"$ ->> - -struct_type(ctx, parent, struct, extensions, member_list) ::= << -$ctx.setCdrv1Templates$ -$member_list$ -/*! - * @brief This class represents the structure $struct.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -class $struct.name$$if(struct.inheritance)$ : public $public_struct_inheritances(struct.inheritance)$$endif$ -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport $struct.name$(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~$struct.name$(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object $struct.scopedname$ that will be copied. - */ - eProsima_user_DllExport $struct.name$( - const $struct.name$& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object $struct.scopedname$ that will be copied. - */ - eProsima_user_DllExport $struct.name$( - $struct.name$&& x) noexcept; - - /*! - * @brief Copy assignment. - * @param x Reference to the object $struct.scopedname$ that will be copied. - */ - eProsima_user_DllExport $struct.name$& operator =( - const $struct.name$& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object $struct.scopedname$ that will be copied. - */ - eProsima_user_DllExport $struct.name$& operator =( - $struct.name$&& x) noexcept; - - /*! - * @brief Comparison operator. - * @param x $struct.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator ==( - const $struct.name$& x) const; - - /*! - * @brief Comparison operator. - * @param x $struct.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator !=( - const $struct.name$& x) const; - - $struct.members:{ member | $public_member_declaration(member)$}; separator="\n"$ - - $if(ctx.anyCdr)$ - /*! - * @brief This function returns the maximum serialized size of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ - eProsima_user_DllExport static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - $endif$ - - $size_functions(struct)$ - - $serialization_functions(struct)$ - - /*! - * @brief This function tells you if the Key has been defined for this type - */ - eProsima_user_DllExport static bool isKeyDefined(); - - /*! - * @brief This function serializes the key members of an object using CDR serialization. - * @param cdr CDR serialization object. - */ - eProsima_user_DllExport void serializeKey( - eprosima::fastcdr::Cdr& cdr) const; - - $extensions : { extension | $extension$}; separator="\n"$ - -private: - - $struct.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ - -}; -$ctx.unsetCdrv1Templates$ ->> - -union_type(ctx, parent, union, extensions, switch_type) ::= << -$ctx.setCdrv1Templates$ -$switch_type$ -/*! - * @brief This class represents the union $union.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -class $union.name$ -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport $union.name$(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~$union.name$(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object $union.scopedname$ that will be copied. - */ - eProsima_user_DllExport $union.name$( - const $union.name$& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object $union.scopedname$ that will be copied. - */ - eProsima_user_DllExport $union.name$( - $union.name$&& x) noexcept; - - /*! - * @brief Copy assignment. - * @param x Reference to the object $union.scopedname$ that will be copied. - */ - eProsima_user_DllExport $union.name$& operator =( - const $union.name$& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object $union.scopedname$ that will be copied. - */ - eProsima_user_DllExport $union.name$& operator =( - $union.name$&& x) noexcept; - - /*! - * @brief Comparison operator. - * @param x $union.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator ==( - const $union.name$& x) const; - - /*! - * @brief Comparison operator. - * @param x $union.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator !=( - const $union.name$& x) const; - - /*! - * @brief This function sets the discriminator value. - * @param __d New value for the discriminator. - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. - */ - eProsima_user_DllExport void _d( - $union.discriminator.cppTypename$ __d); - - /*! - * @brief This function returns the value of the discriminator. - * @return Value of the discriminator - */ - eProsima_user_DllExport $union.discriminator.cppTypename$ _d() const; - - /*! - * @brief This function returns a reference to the discriminator. - * @return Reference to the discriminator. - */ - eProsima_user_DllExport $union.discriminator.cppTypename$& _d(); - - $union.members:{ member | $public_unionmember_declaration(member)$}; separator="\n"$ - - $size_functions(union)$ - - $serialization_functions(union)$ - - $extensions : { extension | $extension$}; separator="\n"$ - -private: - - $private_declaration(typecode=union.discriminator, name="_d")$ - - $union.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ -}; -$ctx.unsetCdrv1Templates$ ->> - -bitset_type(ctx, parent, bitset, extensions) ::= << -/*! - * @brief This class represents the structure $bitset.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -class $bitset.name$$if(bitset.inheritance)$ : public $public_bitset_inheritances(bitset.inheritance)$$endif$ -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport $bitset.name$(); - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~$bitset.name$(); - - /*! - * @brief Copy constructor. - * @param x Reference to the object $bitset.scopedname$ that will be copied. - */ - eProsima_user_DllExport $bitset.name$( - const $bitset.name$& x); - - /*! - * @brief Move constructor. - * @param x Reference to the object $bitset.scopedname$ that will be copied. - */ - eProsima_user_DllExport $bitset.name$( - $bitset.name$&& x) noexcept; - - /*! - * @brief Copy assignment. - * @param x Reference to the object $bitset.scopedname$ that will be copied. - */ - eProsima_user_DllExport $bitset.name$& operator =( - const $bitset.name$& x); - - /*! - * @brief Move assignment. - * @param x Reference to the object $bitset.scopedname$ that will be copied. - */ - eProsima_user_DllExport $bitset.name$& operator =( - $bitset.name$&& x) noexcept; - - /*! - * @brief Comparison operator. - * @param x $bitset.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator ==( - const $bitset.name$& x) const; - - /*! - * @brief Comparison operator. - * @param x $bitset.scopedname$ object to compare. - */ - eProsima_user_DllExport bool operator !=( - const $bitset.name$& x) const; - - $bitset.bitfields:{ bitfield | $public_bitfield_declaration(bitfield)$}; separator="\n"$ - - eProsima_user_DllExport std::bitset<$bitset.fullBitSize$> bitset() const; - - eProsima_user_DllExport void bitset( - const std::bitset<$bitset.fullBitSize$>&); - - $size_functions(bitset)$ - - $serialization_functions(bitset)$ - - $extensions : { extension | $extension$}; separator="\n"$ - -private: - - std::bitset<$bitset.bitSize$> m_bitset; -}; ->> - -enum_type(ctx, parent, enum) ::= << -/*! - * @brief This class represents the enumeration $enum.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -enum $enum.name$ : uint32_t -{ - $enum.members:{ member | $member.name$}; separator=",\n"$ -}; ->> - -bitmask_type(ctx, parent, bitmask) ::= << -/*! - * @brief This class represents the bitmask $bitmask.name$ defined by the user in the IDL file. - * @ingroup $ctx.trimfilename$ - */ -enum $bitmask.name$Bits$bitmask.boundType$ -{ - $bitmask.members:{ member | $member.name$ = 0x01ull << $member.position$}; separator=",\n"$ -}; -typedef $bitmask.castingType$ $bitmask.name$; ->> - -sequence_type(ctx, sequence, type_sequence) ::= << - -$type_sequence$ - ->> - -map_type(ctx, map, key_type, value_type) ::= << - -$key_type$ -$value_type$ - ->> - -string_type(ctx, string) ::= <<>> - -wide_string_type(ctx, wstring) ::= <<>> - -array_declarator(ctx, array, array_type) ::= <<>> - -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - -element_type(ctx, element, type_element, declarator) ::= << - -$type_element$ -$declarator$ - ->> - -/***** Utils *****/ - -public_struct_inheritances(parent) ::= <<$parent.scopedname$>> - -public_bitset_inheritances(parent) ::= <<$parent.scopedname$>> - -public_member_declaration(member) ::= << -$if(member.typecode.primitive)$ -$public_member_primitive_declaration(member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_member_cstring_declaration(member=member)$ -$else$ -$public_member_common_declaration(member=member)$ -$endif$ -$else$ -$public_member_common_declaration(member=member)$ -$endif$ ->> - -public_member_primitive_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -eProsima_user_DllExport $member.typecode.cppTypename$ $member.name$() const; - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); ->> - -public_member_cstring_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -eProsima_user_DllExport const $member.typecode.cppTypename$ $member.name$() const; ->> - -public_member_common_declaration(member) ::= << -/*! - * @brief This function copies the value in member $member.name$ - * @param _$member.name$ New value to be copied in member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$& _$member.name$); - -/*! - * @brief This function moves the value in member $member.name$ - * @param _$member.name$ New value to be moved in member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$&& _$member.name$); - -/*! - * @brief This function returns a constant reference to member $member.name$ - * @return Constant reference to member $member.name$ - */ -eProsima_user_DllExport const $member.typecode.cppTypename$& $member.name$() const; - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); ->> - -public_bitfield_declaration(member) ::= << -$if(member.name)$ -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - $member.spec.cppTypename$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -eProsima_user_DllExport $member.spec.cppTypename$ $member.name$() const; -$endif$ ->> - -private_member_declaration(member) ::= << -$private_declaration(typecode=member.typecode, name=member.name)$ ->> - -public_unionmember_declaration(member) ::= << -$if(member.typecode.primitive)$ -$public_unionmember_primitive_declaration(member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_unionmember_cstring_declaration(member=member)$ -$else$ -$public_unionmember_common_declaration(member=member)$ -$endif$ -$else$ -$public_unionmember_common_declaration(member=member)$ -$endif$ ->> - -public_unionmember_primitive_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport $member.typecode.cppTypename$ $member.name$() const; - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); ->> - -public_unionmember_cstring_declaration(member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$ _$member.name$); - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport const $member.typecode.cppTypename$ $member.name$() const; ->> - -public_unionmember_common_declaration(member) ::= << -/*! - * @brief This function copies the value in member $member.name$ - * @param _$member.name$ New value to be copied in member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$& _$member.name$); - -/*! - * @brief This function moves the value in member $member.name$ - * @param _$member.name$ New value to be moved in member $member.name$ - */ -eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$&& _$member.name$); - -/*! - * @brief This function returns a constant reference to member $member.name$ - * @return Constant reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport const $member.typecode.cppTypename$& $member.name$() const; - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. - */ -eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); ->> - -private_declaration(typecode, name) ::= << -$typecode.cppTypename$ m_$name$; ->> - - -/*! TODO Quitado de FastBuffers porque no encaja con las excepciones de fastrpc. - * @brief This function calculates the space needed to serialize a type $type.scopedname$. - * For all types with a variable size (strings, sequences) and without a maximum limit, this function uses - * 255 as maximum limit. - * - inline - size_t getMaxSerializedSize() { return $type.maxSerializedSize$;} - - *! - * @brief This function calculates the space needed to serialize a type $type.scopedname$ without alignment. - * For all types with a variable size (strings, sequences) and without a maximum limit, this function uses - * 255 as maximum limit. - * - inline - size_t getMaxSerializedSizeWithoutAlign(){ return $type.maxSerializedSizeWithoutAlignment$;} - */ - -size_functions(type) ::= << -$if(ctx.anyCdr)$ -/*! - * @brief This function returns the serialized size of a data depending on the buffer alignment. - * @param data Data which is calculated its serialized size. - * @param current_alignment Buffer alignment. - * @return Serialized size. - */ -eProsima_user_DllExport static size_t getCdrSerializedSize( - const $type.scopedname$& data, - size_t current_alignment = 0); - -$endif$ ->> - -serialization_functions(type) ::= << -$if(ctx.cdr)$ -/*! - * @brief This function serializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ -eProsima_user_DllExport void serialize( - eprosima::fastcdr::Cdr& cdr) const; - -/*! - * @brief This function deserializes an object using CDR serialization. - * @param cdr CDR serialization object. - */ -eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr); - -$endif$ - -$if(ctx.fastcdr)$ -/*! - * @brief This function serializes an object using FastCDR serialization. - * @param cdr FastCDR serialization object. - */ -eProsima_user_DllExport void serialize( - eprosima::fastcdr::FastCdr& cdr) const; - -/*! - * @brief This function deserializes an object using FastCDR serialization. - * @param cdr FastCDR serialization object. - */ -eProsima_user_DllExport void deserialize( - eprosima::fastcdr::FastCdr& cdr); - -$endif$ ->> - -sequences_definition(typecode) ::= << -$if(typecode.contentTypeCode.isStructType)$ -$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ -class $typecode.contentTypeCode.name$; -$typecode.contentTypeCode.namespaces : { ns | \} }; separator="\n"$ -$endif$ -$if(typecode.contentTypeCode.isUnionType)$ -$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ -class $typecode.contentTypeCode.name$; -$typecode.contentTypeCode.namespaces : { ns | \} }; separator="\n"$ -$endif$ - -$sequences_definition_impl(typecode=typecode, typename=typecode.cppTypename)$ ->> - -sequences_definition_impl(typecode, typename) ::= << - -class eProsima_user_DllExport $typename$ -{ -public: - $typename$(); - - $typename$( - uint32_t maximum); - - $typename$( - uint32_t length, - $typecode.contentTypeCode.cppTypename$* data, - bool release = false); - - $typename$( - const $typename$& $typename$_); - - $typename$& operator =( - const $typename$& $typename$_); - - ~$typename$(); - - $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ operator[]( - uint32_t index); - - const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ operator[]( - uint32_t index) const; - - void size( - uint32_t size); - - uint32_t size() const; - - void length( - uint32_t size); - - uint32_t length() const; - - uint32_t maximum() const; - - void value( - $typecode.contentTypeCode.cppTypename$* value); - - $typecode.contentTypeCode.cppTypename$* value( - bool orphan = false); - - const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ const$else$$endif$$else$$endif$* value() const; - - void release( - bool release); - - bool release() const; - - bool& release(); - -$if(ctx.anyCdr)$ - static size_t getMaxCdrSerializedSize( - size_t current_alignment = 0); - - static size_t getCdrSerializedSize( - const $typename$& data, - size_t current_alignment = 0); - -$endif$ - - void serialize( - eprosima::fastcdr::Cdr& cdr) const; - - void deserialize( - eprosima::fastcdr::Cdr& cdr); - -private: - - uint32_t maximum_ = $typecode.maxsize$; - - mutable uint32_t length_ = 0; - - mutable $typecode.contentTypeCode.cppTypename$* value_ = nullptr; - - bool release_ = true; - - void free_memory(); -}; ->> diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg deleted file mode 100644 index 930b1aeb..00000000 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg +++ /dev/null @@ -1,1413 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -group TypesSource; - -import "com/eprosima/fastdds/idl/templates/eprosima.stg" -import "FastCdrCommon.stg" - -main(ctx, definitions, extensions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, ".cpp"], description=["This source file contains the implementation of the described types in the IDL file."])$ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { -char dummy; -} // namespace -#endif // _WIN32 - -#include "$ctx.filename$.h" - -$if(ctx.cdr_both)$ -#if FASTCDR_VERSION_MAJOR > 1 -$endif$ - -$if(ctx.generateTypeObject)$ -#include "$ctx.filename$TypeObject.h" -$endif$ - -$if(ctx.cdr)$ -#include - -$endif$ - -$if(ctx.fastcdr)$ -#include - -$endif$ - -#include -using namespace eprosima::fastcdr::exception; - -#include - -$extensions : { extension | $extension$}; separator="\n"$ - -$if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { type | $sequences_definition(type.value)$ }; separator="\n"$ -$endif$ - -$definitions; separator="\n"$ -$if(ctx.thereIsStructOrUnion)$ -// Include auxiliary functions like for serializing/deserializing. -#include "$ctx.filename$CdrAux.ipp" -$endif$ - -$if(ctx.cdr_both)$ -#endif // FASTCDR_VERSION_MAJOR > 1 -$endif$ ->> - -module(ctx, parent, module, definition_list) ::= << -namespace $module.name$ { - -$definition_list$ - -} // namespace $module.name$ ->> - -definition_list(definitions) ::= << -$definitions; separator="\n"$ - ->> - -annotation(ctx, annotation) ::= <<>> - -interface(ctx, parent, interface, export_list) ::= << -$export_list$ ->> - -export_list(exports) ::= << -$exports; separator="\n"$ - ->> - -exception(ctx, parent, exception) ::= <<>> - -operation(ctx, parent, operation, param_list, operation_type) ::= << - -$operation_type$ -$param_list$ - ->> - -param_list(parameters) ::= <<>> - -param(parameter, parameter_type) ::= << - -$parameter_type$ - ->> - -const_decl(ctx, parent, const, const_type) ::= << -$const_type$ -$if(const.parent)$ -$if(const.parent.isInterface)$ -$if(const.typeCode.isType_5)$ -const $const.typeCode.cppTypename$ $const.parent.scopedname$::$const.name$ = $const.value$; -$elseif(const.typeCode.isType_6)$ -const $const.typeCode.cppTypename$ $const.parent.scopedname$::$const.name$ = $const.value$; -$endif$ -$endif$ -$endif$ ->> - -fwd_decl(ctx, parent, type) ::= <<>> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << -$declarator_type$ -$typedefs_type$ -$typedefs : -{ typedef | -$if(ctx.generateTypesC)$ -$if(typedef.typedefContentTypeCode.isSequenceType)$ -$sequences_definition_impl(typecode=typedef.typedefContentTypeCode, scopedtypename=typedef.scopedname, typename=typedef.name)$ -$endif$ -$endif$ -}; separator="\n"$ ->> - -struct_type(ctx, parent, struct, extensions, member_list) ::= << -$member_list$ -$struct.name$::$struct.name$() - $if(struct.inheritance)$ - : $struct_inherit_default_init(struct.inheritance)$ - $endif$ - -{ - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ -} - -$struct.name$::~$struct.name$() -{ - $struct.members:{ member |$member_destructor(ctx=ctx, member=member)$}; separator="\n"$ -} - -$struct.name$::$struct.name$( - const $struct.name$& x) - $if(struct.inheritance)$ - : $struct_inherit_copy_init(struct.inheritance)$ - $endif$ - -{ - $if(struct.members)$ - $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ -} - -$struct.name$::$struct.name$( - $struct.name$&& x) noexcept - $if(struct.inheritance)$ - : $struct_inherit_move_init(struct.inheritance)$ - $endif$ - -{ - $if(struct.members)$ - $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ -} - -$struct.name$& $struct.name$::operator =( - const $struct.name$& x) -{ - $if(struct.inheritance)$$struct.inheritance.scopedname$::operator =(x);$endif$ - - $if(struct.members)$ - $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ - - return *this; -} - -$struct.name$& $struct.name$::operator =( - $struct.name$&& x) noexcept -{ - $if(struct.inheritance)$$struct.inheritance.scopedname$::operator =(std::move(x));$endif$ - - $if(struct.members)$ - $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ - - return *this; -} - -bool $struct.name$::operator ==( - const $struct.name$& x) const -{ - $if(struct.inheritance)$if ($struct.inheritance.scopedname$::operator !=(x)) - { - return false; - } - $endif$ - - $if(!struct.members)$ - static_cast(x); - return true; - $else$ - return ($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$); - $endif$ -} - -bool $struct.name$::operator !=( - const $struct.name$& x) const -{ - return !(*this == x); -} - -$if(ctx.fastcdr)$ -void $struct.name$::serialize( - eprosima::fastcdr::FastCdr &scdr) const -{ - $if(struct.inheritance)$$struct.inheritance.scopedname$::serialize(scdr);$endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member)$$endif$}; separator=""$ -} - -void $struct.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $if(struct.inheritance)$$struct.inheritance.scopedname$::deserialize(dcdr);$endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ -} -$endif$ -$struct.members:{ member | $public_member_declaration(class=struct.name, member=member)$}; separator="\n"$ -$extensions : { extension | $extension$}; separator="\n"$ ->> - -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - -bitset_type(ctx, parent, bitset) ::= << -$bitset.name$::$bitset.name$()$if(bitset.inheritance)$ - : $bitset_inherit_default_init(bitset.inheritance)$$endif$ -{ - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ -} - -$bitset.name$::~$bitset.name$() -{ -} - -$bitset.name$::$bitset.name$( - const $bitset.name$& x)$if(bitset.inheritance)$ - : $bitset_inherit_copy_init(bitset.inheritance)$$endif$ -{ - m_bitset = x.m_bitset; -} - -$bitset.name$::$bitset.name$( - $bitset.name$&& x) noexcept $if(bitset.inheritance)$ - : $bitset_inherit_move_init(bitset.inheritance)$$endif$ -{ - m_bitset = x.m_bitset; -} - -$bitset.name$& $bitset.name$::operator =( - const $bitset.name$& x) -{ - $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::operator =(x);$endif$ - - m_bitset = x.m_bitset; - - return *this; -} - -$bitset.name$& $bitset.name$::operator =( - $bitset.name$&& x) noexcept -{ - $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::operator =(std::move(x));$endif$ - - m_bitset = x.m_bitset; - - return *this; -} - -bool $bitset.name$::operator ==( - const $bitset.name$& x) const -{ - $if(bitset.inheritance)$ if ($bitset.inheritance.scopedname$::operator !=(x)) return false;$endif$ - - return m_bitset == x.m_bitset; -} - -bool $bitset.name$::operator !=( - const $bitset.name$& x) const -{ - return !(*this == x); -} - -$if(ctx.fastcdr)$ -void $bitset.name$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::serialize(scdr);$endif$ - - $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_serialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ -} - -void $bitset.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $if(bitset.inheritance)$ $bitset.inheritance.scopedname$::deserialize(dcdr);$endif$ - - $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_deserialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ -} - -$endif$ - - -$bitset.bitfields:{ member | $public_bitfield_definition(class=bitset.name, member=member)$}; separator="\n"$ - -std::bitset<$bitset.fullBitSize$> $bitset.name$::bitset() const -{ - std::string str_value; - - $if(bitset.inheritance)$ - str_value = static_cast(this)->bitset().to_string() + str_value; - $endif$ - - str_value = m_bitset.to_string() + str_value; - - return std::bitset<$bitset.fullBitSize$>(str_value); -} - -void $bitset.name$::bitset( - const std::bitset<$bitset.fullBitSize$>& bitset) -{ - std::string str_value {bitset.to_string()}; - size_t base_diff {0}; - size_t last_post {std::string::npos}; - - $if(bitset.inheritance)$ - { - base_diff += $bitset.inheritance.fullBitSize$; - std::bitset<$bitset.inheritance.fullBitSize$> internal_bitset(str_value.substr(str_value.length() - base_diff, last_post)); - static_cast<$bitset.inheritance.scopedname$*>(this)->bitset(internal_bitset); - last_post = base_diff; - } - $endif$ - - base_diff += $bitset.bitSize$; - m_bitset = std::bitset<$bitset.bitSize$>(str_value.substr(str_value.length() - base_diff, last_post)); -} - ->> - -public_bitfield_definition(class, member) ::= << -$if(member.name)$ -void $class$::$member.name$( - $member.spec.cppTypename$ _$member.name$) -{ - int base = $member.basePosition$; -$if(member.spec.typecode.isType_7)$ - m_bitset.set(base, _$member.name$); -$else$ - int size = $member.spec.bitSize$; - for (int i = base; i < base + size; ++i) - { - m_bitset.set(i, !!(_$member.name$ & 0x01)); - _$member.name$ = _$member.name$ \>> 1; - } -$endif$ - -} - -$member.spec.cppTypename$ $class$::$member.name$() const -{ - int base = $member.basePosition$; -$if(member.spec.typecode.isType_7)$ - return m_bitset.test(base); -$else$ - int size = $member.spec.bitSize$; - std::bitset<$member.spec.bitSize$> aux; - for (int i = 0; i < size; ++i) - { - aux.set(i, m_bitset.test(i + base)); - } - return static_cast<$member.spec.cppTypename$>(aux.to_ullong()); -$endif$ - -} -$endif$ - ->> - -union_type(ctx, parent, union, switch_type) ::= << -$switch_type$ -$union.name$::$union.name$() -{ - $if(union.defaultvalue)$ - m__d = $union.defaultvalue$; - $else$ - m__d = $first(first(union.members).labels)$; - $endif$ -} - -$union.name$::~$union.name$() -{ -} - -$union.name$::$union.name$( - const $union.name$& x) -{ - m__d = x.m__d; - - switch (m__d) - { - $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ - $unionmemberdefault_copy(union.defaultMember)$ - } -} - -$union.name$::$union.name$( - $union.name$&& x) noexcept -{ - m__d = x.m__d; - - switch (m__d) - { - $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ - $unionmemberdefault_move(union.defaultMember)$ - } -} - -$union.name$& $union.name$::operator =( - const $union.name$& x) -{ - m__d = x.m__d; - - switch (m__d) - { - $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ - $unionmemberdefault_copy(union.defaultMember)$ - } - - return *this; -} - -$union.name$& $union.name$::operator =( - $union.name$&& x) noexcept -{ - m__d = x.m__d; - - switch (m__d) - { - $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ - $unionmemberdefault_move(union.defaultMember)$ - } - - return *this; -} - -bool $union.name$::operator ==( - const $union.name$& x) const -{ - if (m__d != x.m__d) - { - return false; - } - - switch (m__d) - { - $union.members:{ member | $unionmember_compare(member)$}; separator="\n"$ - $unionmemberdefault_compare(union.defaultMember)$ - } - return false; -} - -bool $union.name$::operator !=( - const $union.name$& x) const -{ - return !(*this == x); -} - -void $union.name$::_d( - $union.discriminator.cppTypename$ __d) -{ - bool b = false; - - switch (m__d) - { - $union.members:{ member | $unionmember_discriminator_case(member=member, totallabels=union.totallabels)$}; separator="\n"$ - $if(!union.defaultMember)$ - default: - break; - $endif$ - } - - if (!b) - { - throw BadParamException("Discriminator doesn't correspond with the selected union member"); - } - - m__d = __d; -} - -$union.discriminator.cppTypename$ $union.name$::_d() const -{ - return m__d; -} - -$union.discriminator.cppTypename$& $union.name$::_d() -{ - return m__d; -} - -$union.members:{ member | $public_unionmember_declaration(class=union.name, member=member, defaultvalue=union.defaultvalue, totallabels=union.totallabels)$}; separator="\n"$ -$if(ctx.fastcdr)$ -void $union.name$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - scdr << m__d; - - switch (m__d) - { - $union.members:{ member |$unionmember_case_selection_se(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_se(ctx=ctx, member=union.defaultMember)$ - } -} - -void $union.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - dcdr \>> m__d; - - switch (m__d) - { - $union.members:{ member |$unionmember_case_selection_de(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_de(ctx=ctx, member=union.defaultMember)$ - } -} -$endif$ ->> - -element_type(ctx, element, type_element, declarator) ::= << - -$type_element$ -$declarator$ - ->> - -enum_type(ctx, parent, enum) ::= <<>> - -bitmask_type(ctx, parent, bitmask) ::= <<>> - -sequence_type(ctx, sequence, type_sequence) ::= << - -$type_sequence$ - ->> - -map_type(ctx, map, key_type, value_type) ::= << - -$key_type$ -$value_type$ - ->> - -string_type(ctx, string) ::= <<>> - -wide_string_type(ctx, wstring) ::= <<>> - -array_declarator(ctx, array, array_type) ::= <<>> - -/***** Utils *****/ - -public_member_declaration(class, member) ::= << -$if(member.annotationOptional || member.annotationExternal)$ -$public_object_member_declaration(class=class, member=member)$ -$elseif(member.typecode.primitive)$ -$public_primitive_member_declaration(class=class, member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_cstring_member_declaration(class=class, member=member)$ -$else$ -$public_object_member_declaration(class=class, member=member)$ -$endif$ -$else$ -$public_object_member_declaration(class=class, member=member)$ -$endif$ ->> - -public_primitive_member_declaration(class, member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -void $class$::$member.name$( - $member_type_declaration(member)$ _$member.name$) -{ - $\ $m_$member.name$ = _$member.name$; -} - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -$member_type_declaration(member)$ $class$::$member.name$() const -{ - return m_$member.name$; -} - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -$member_type_declaration(member)$& $class$::$member.name$() -{ - return m_$member.name$; -} ->> - -public_cstring_member_declaration(class, member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -void $class$::$member.name$( - const $member.typecode.cppTypename$ _$member.name$) -{ - free(m_$member.name$); - m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(_$member.name$) + 1)); - strncpy(m_$member.name$, _$member.name$, strlen(_$member.name$) + 1); -} - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -const $member.typecode.cppTypename$ $class$::$member.name$() const -{ - return m_$member.name$; -} ->> - -public_object_member_declaration(class, member) ::= << -/*! - * @brief This function copies the value in member $member.name$ - * @param _$member.name$ New value to be copied in member $member.name$ - */ -void $class$::$member.name$( - const $member_type_declaration(member)$& _$member.name$) -{ - $\ $m_$member.name$ = _$member.name$; -} - -/*! - * @brief This function moves the value in member $member.name$ - * @param _$member.name$ New value to be moved in member $member.name$ - */ -void $class$::$member.name$( - $member_type_declaration(member)$&& _$member.name$) -{ - $\ $m_$member.name$ = std::move(_$member.name$); -} - -/*! - * @brief This function returns a constant reference to member $member.name$ - * @return Constant reference to member $member.name$ - */ -const $member_type_declaration(member)$& $class$::$member.name$() const -{ - return m_$member.name$; -} - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -$member_type_declaration(member)$& $class$::$member.name$() -{ - return m_$member.name$; -} ->> - -public_unionmember_declaration(class, member, totallabels, defaultvalue) ::= << -$if(member.annotationExternal)$ -$public_unionmember_cpp_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$ -$elseif(member.typecode.primitive)$ -$public_unionmember_primitive_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$unionmember_cstring_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$ -$else$ -$public_unionmember_cpp_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$ -$endif$ -$else$ -$public_unionmember_cpp_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$ -$endif$ ->> - -public_unionmember_primitive_declaration(class, member, totallabels, defaultvalue) ::= << -void $class$::$member.name$( - $member.typecode.cppTypename$ _$member.name$) -{ - m_$member.name$ = _$member.name$; - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -$member.typecode.cppTypename$ $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} - -$member.typecode.cppTypename$& $class$::$member.name$() -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} ->> - -unionmember_cstring_declaration(class, member, totallabels, defaultvalue) ::= << -void $class$::$member.name$( - const char* _$member.name$) -{ - free(m_$member.name$); - m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(_$member.name$) + 1)); - strncpy(m_$member.name$, _$member.name$, strlen(_$member.name$)); - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -const char* $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} ->> - -public_unionmember_cpp_declaration(class, member, totallabels, defaultvalue) ::= << -void $class$::$member.name$( - const $member_type_declaration(member)$& _$member.name$) -{ - m_$member.name$ = _$member.name$; - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -void $class$::$member.name$( - $member_type_declaration(member)$&& _$member.name$) -{ - m_$member.name$ = std::move(_$member.name$); - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -const $member_type_declaration(member)$& $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} - -$member_type_declaration(member)$& $class$::$member.name$() -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} ->> - -member_copy(ctx, member) ::= <% -$if(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -free(m_$member.name$); -m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(x.m_$member.name$) + 1)); -strncpy(m_$member.name$, x.m_$member.name$, strlen(x.m_$member.name$) + 1); -$else$ -m_$member.name$ = x.m_$member.name$; -$endif$ -$else$ -m_$member.name$ = x.m_$member.name$; -$endif$ -%> - -member_move(member) ::= <% -$if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; -$else$ -m_$member.name$ = std::move(x.m_$member.name$); -$endif$ -%> - -unionmember_discriminator_case(member, totallabels) ::= << -$if(member.default)$ -default: - b = true; - switch (__d) - { - $totallabels:{ label | case $label$:}; separator="\n"$ - b = false; - break; - default: - break; - } - break; -$else$ -$member.labels:{ label | case $label$:}; separator="\n"$ - switch (__d) - { - $member.labels:{ label | case $label$:}; separator="\n"$ - b = true; - break; - default: - break; - } - break; -$endif$ ->> - -unionmember_copy(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ - m_$member.name$ = x.m_$member.name$; - break; -$endif$ ->> - -unionmemberdefault_copy(member) ::= << -default: -$if(member)$ -$if(member.default)$ - m_$member.name$ = x.m_$member.name$; -$endif$ -$endif$ - - break; ->> - -unionmember_move(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ -$if(member.typecode.primitive)$ - m_$member.name$ = x.m_$member.name$; -$else$ - m_$member.name$ = std::move(x.m_$member.name$); -$endif$ - - break; -$endif$ ->> - -unionmemberdefault_move(member) ::= << -default: -$if(member)$ -$if(member.default)$ -$if(member.typecode.primitive)$ - m_$member.name$ = x.m_$member.name$; -$else$ - m_$member.name$ = std::move(x.m_$member.name$); -$endif$ -$endif$ -$endif$ - - break; ->> - -unionmember_compare(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ - return (m_$member.name$ == x.m_$member.name$); - break; -$endif$ ->> - -unionmemberdefault_compare(member) ::= << -default: -$if(member)$ -$if(member.default)$ - return m_$member.name$ == x.m_$member.name$; -$endif$ -$endif$ - - break; ->> - -unionmember_set_discriminator(member, defaultvalue) ::= << -$if(member.default)$ -m__d = $defaultvalue$; -$else$ -m__d = $first(member.labels)$; -$endif$ ->> - -unionmember_check_case_list(member, totallabels) ::= << -$if(member.default)$ -bool b = true; - -switch (m__d) -{ - $totallabels:{ label | case $label$:}; separator="\n"$ - b = false; - break; - default: - break; -} -$else$ -bool b = false; - -switch (m__d) -{ - $member.labels:{ label | case $label$:}; separator="\n"$ - b = true; - break; - default: - break; -} -$endif$ - -if (!b) -{ - throw BadParamException("This member has not been selected"); -} ->> - -unionmember_case_selection_se(ctx, member) ::= << -$if(member.labels)$ -$member.labels:{ label |case $label$:}; separator="\n"$ -$object_serialization(ctx=ctx, object=member)$ -break; -$endif$ ->> - -unionmemberdefault_case_selection_se(ctx, member) ::= << -default: -$if(member)$ -$if(member.default)$ - $object_serialization(ctx=ctx, object=member)$ -$endif$ -$endif$ - - break; ->> - -unionmember_case_selection_de(ctx, member) ::= << -$if(member.labels)$ -$member.labels:{ label |case $label$:}; separator="\n"$ - $object_deserialization(ctx=ctx, object=member)$ - break; -$endif$ ->> - -unionmemberdefault_case_selection_de(ctx, member) ::= << -default: -$if(member)$ -$if(member.default)$ - $object_deserialization(ctx=ctx, object=member)$ -$endif$ -$endif$ - - break; ->> - -sequences_definition(typecode) ::= << -$sequences_definition_impl(typecode=typecode, scopedtypename=typecode.cppTypename, typename=typecode.cppTypename)$ ->> - -sequences_definition_impl(typecode, scopedtypename, typename) ::= << - -$scopedtypename$::$typename$() -{ - // value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - value_ = nullptr; -} - -$scopedtypename$::$typename$( - uint32_t maximum) - : maximum_(maximum) -{ - // value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - value_ = nullptr; -} - -$scopedtypename$::$typename$( - uint32_t length, - $typecode.contentTypeCode.cppTypename$* data, - bool release) - : length_(length) - , value_(data) - , release_(release) -{ -} - -$scopedtypename$::$typename$( - const $typename$& $typename$_) - : maximum_($typename$_.maximum_) - , length_($typename$_.length_) - , release_(true) -{ - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - for (size_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1); - $else$ - value_[i] = $typename$_.value_[i];$endif$$else$ - value_[i] = $typename$_.value_[i];$endif$ - } -} - -$scopedtypename$& $scopedtypename$::operator =( - const $typename$& $typename$_) -{ - maximum_ = $typename$_.maximum_; - length_ = $typename$_.length_; - free_memory(); - release_ = true; - - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - for (size_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1); - $else$ - value_[i] = $typename$_.value_[i];$endif$$else$ - value_[i] = $typename$_.value_[i];$endif$ - } - - return *this; -} - -$scopedtypename$::~$typename$() -{ - free_memory(); -} - -$typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ $scopedtypename$::operator[]( - uint32_t index) -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ != 0) // Must be set. If not, will return nullptr[index] and crash. - { - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_[index]; -} - -const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ $scopedtypename$::operator[]( - uint32_t index) const -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ != 0) // Must be set. If not, will return nullptr[index] and crash. - { - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_[index]; -} - -void $scopedtypename$::size( - uint32_t size) -{ - if (maximum_ == 0) - { - if(value_ != nullptr && size > length_) - { - $typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[size]; - for (size_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - if (value_[i] != nullptr) - { - strncpy(temp[i], value_[i], strlen(value_[i]) + 1); - } - else - { - temp[i] = nullptr; - } - $else$ - temp[i] = value_[i];$endif$$else$ - temp[i] = value_[i];$endif$ - } - free_memory(); - value_ = temp; - release_ = true; - } - } - else - { - if(size > maximum_) - { - throw BadParamException("Length is greater than maximum length of the sequence"); - } - } - - length_ = size; -} - -uint32_t $scopedtypename$::size() const -{ - return length_; -} - -void $scopedtypename$::length( - uint32_t length) -{ - if (maximum_ == 0) - { - if(value_ != nullptr && length > length_) - { - $typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[length]; - for (size_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - if (value_[i] != nullptr) - { - strncpy(temp[i], value_[i], strlen(value_[i]) + 1); - } - else - { - temp[i] = nullptr; - } - $else$ - temp[i] = value_[i];$endif$$else$ - temp[i] = value_[i];$endif$ - } - free_memory(); - value_ = temp; - release_ = true; - } - } - else - { - if(length > maximum_) - { - throw BadParamException("Length is greater than maximum length of the sequence"); - } - } - - length_ = length; -} - -uint32_t $scopedtypename$::length() const -{ - return length_; -} - -uint32_t $scopedtypename$::maximum() const -{ - if (maximum_ == 0) - { - return length_; - } - else - { - return maximum_; - } -} - -void $scopedtypename$::value( - $typecode.contentTypeCode.cppTypename$* value) -{ - free_memory(); - value_ = value; -} - -$typecode.contentTypeCode.cppTypename$* $scopedtypename$::value( - bool orphan) -{ - if (orphan && !release_) - { - return nullptr; - } - - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ == 0) // Not yet set - { - return nullptr; // To be coherent with accessing value[length]; - } - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - if (orphan) - { - release_ = false; - } - - return value_; -} - -const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ const$else$$endif$$else$$endif$* $scopedtypename$::value() const -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ == 0) // Not yet set - { - return nullptr; // To be coherent with accessing value[length]; - } - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_; -} - -void $scopedtypename$::release( - bool release) -{ - release_ = release; -} - -bool $scopedtypename$::release() const -{ - return release_; -} - -bool& $scopedtypename$::release() -{ - return release_; -} - -$if(ctx.anyCdr)$ -size_t $scopedtypename$::calculate_serialized_size( - const $scopedtypename$& data, - size_t& current_alignment) -{ - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); - return calculate_serialized_size(calculator, data, current_alignment); -} - -size_t $scopedtypename$::calculate_serialized_size( - eprosima::fastcdr::CdrSizeCalculator& calculator, - const $scopedtypename$& data, - size_t& current_alignment) -{ - return calculator.calculate_serialized_size(data, current_alignment); -} - -$endif$ - -$if(ctx.cdr)$ -void $scopedtypename$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - scdr << length_; - - if (value_ == nullptr && length_ > 0) - { - size_t size = (maximum_ == 0) ? length_ : maximum_; - value_ = new $typecode.contentTypeCode.cppTypename$[size]; - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - for (size_t count = 0; count < length_; ++count) - { - scdr << value_[count]; - } -} - -void $scopedtypename$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - uint32_t old_length = length_; - uint32_t new_length; - - dcdr \>> new_length; - - if (maximum_ != 0 && new_length > maximum_) - { - throw BadParamException("Deserialized length is greater than maximum length of the sequence. Incompatible \ - sequences."); - } - - if ((value_ == nullptr && new_length > 0) || (old_length < new_length)) - { - free_memory(); - - size_t size = (maximum_ == 0) ? new_length : maximum_; - value_ = new $typecode.contentTypeCode.cppTypename$[size]; - } - - length_ = new_length; - - for (size_t count = 0; count < length_; ++count) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - { - std::string temp; - dcdr \>> temp; - value_[count] = (char*)malloc(temp.size() + 1); - strncpy(value_[count], temp.c_str(), temp.size() + 1); - } - $else$ - dcdr \>> value_[count];$endif$$else$ - dcdr \>> value_[count];$endif$ - } -} - -void $scopedtypename$::free_memory() -{ - if (release_) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (size_t count = 0; count < length_; ++count) - { - free(value_[count]); - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - delete[](value_); - } - value_ = nullptr; -} - -$endif$ ->> diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSourcev1.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSourcev1.stg deleted file mode 100644 index 79ee4010..00000000 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSourcev1.stg +++ /dev/null @@ -1,2341 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -group TypesSource; - -import "com/eprosima/fastdds/idl/templates/eprosima.stg" -import "FastCdrCommon.stg" - -main(ctx, definitions, extensions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, ".cpp"], description=["This source file contains the implementation of the described types in the IDL file."])$ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { -char dummy; -} // namespace -#endif // _WIN32 - -#include "$ctx.filename$.h" - -$if(ctx.cdr_both)$ -#if FASTCDR_VERSION_MAJOR == 1 -$endif$ - -$if(ctx.generateTypeObject)$ -#include "$ctx.filename$TypeObject.h" -$endif$ - -$if(ctx.cdr)$ -#include - -$endif$ - -$if(ctx.fastcdr)$ -#include - -$endif$ - -#include -using namespace eprosima::fastcdr::exception; - -#include - -namespace helper { namespace internal { - -enum class Size { - UInt8, - UInt16, - UInt32, - UInt64, -}; - -constexpr Size get_size(int s) { - return (s <= 8 ) ? Size::UInt8: - (s <= 16) ? Size::UInt16: - (s <= 32) ? Size::UInt32: Size::UInt64; -} - -template -struct FindTypeH; - -template<> -struct FindTypeH { - using type = std::uint8_t; -}; - -template<> -struct FindTypeH { - using type = std::uint16_t; -}; - -template<> -struct FindTypeH { - using type = std::uint32_t; -}; - -template<> -struct FindTypeH { - using type = std::uint64_t; -}; -} - -template -struct FindType { - using type = typename internal::FindTypeH::type; -}; -} - -$if(ctx.anyCdr)$ -$ctx.setCdrv1Templates$ -$ctx.types:{ type | $if(type.typeCode.isStructType)$#define $type.typeCode.cScopedname$_max_cdr_typesize $type.typeCode.maxSerializedSize$ULL;$endif$}; separator="\n"$ -$ctx.unsetCdrv1Templates$ -$endif$ - -$extensions : { extension | $extension$}; separator="\n"$ - -$if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { type | -$sequences_definition(type.value)$ -}; separator="\n"$ -$endif$ - -$definitions; separator="\n"$ - -$if(ctx.cdr_both)$ -#endif // FASTCDR_VERSION_MAJOR == 1 -$endif$ ->> - -module(ctx, parent, module, definition_list) ::= << -namespace $module.name$ { - -$definition_list$ - -} // namespace $module.name$ ->> - -definition_list(definitions) ::= << -$definitions; separator="\n"$ - ->> - -annotation(ctx, annotation) ::= <<>> - -interface(ctx, parent, interface, export_list) ::= << -$export_list$ ->> - -export_list(exports) ::= << -$exports; separator="\n"$ - ->> - -exception(ctx, parent, exception) ::= << -$if(ctx.printexception)$ -$exception.name$::$exception.name$() - : UserException() -{ - $exception.members : { member |$member_default_init(ctx=ctx, member=member, loopvar=ctx.newLoopVarName)$}; separator="\n"$ -} - -$exception.name$::$exception.name$( - const $exception.name$& x) - : UserException(x) -{ - $exception.members : { member |$member_copy(ctx=ctx, member=member)$}; separator="\n"$ -} - -$exception.name$::$exception.name$( - $exception.name$&& x) - : UserException(std::move(x)) -{ - $exception.members : { member |$member_move(member=member)$}; separator="\n"$ -} - -$exception.name$& $exception.name$::operator =( - const $exception.name$& x) -{ - UserException::operator =(x); - $exception.members : { member |$member_copy(ctx=ctx, member=member)$}; separator="\n"$ - return *this; -} - -$exception.name$& $exception.name$::operator =( - $exception.name$&& x) -{ - UserException::operator =(std::move(x)); - $exception.members : { member |$member_move(member=member)$}; separator="\n"$ - return *this; -} - -$exception.name$::~$exception.name$() throw() -{ - $exception.members : { member |$varDel(variable=member)$}; separator="\n"$ -} - -void $exception.name$::raise() const -{ - throw *this; -} - -$if(ctx.anyCdr)$ -size_t $exception.name$::getCdrSerializedSize( - const $exception.name$& data, - size_t current_alignment) -{ - static_cast(data); - size_t initial_alignment = current_alignment; - - $exception.members : { member |$serialized_size(ctx=ctx, object=member, data="data", var="current_alignment")$}; separator="\n"$ - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ -void $exception.name$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - $exception.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator=""$ -} - -void $exception.name$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $exception.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$ -} - -$endif$ - -$if(ctx.fastcdr)$ -void $exception.name$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - $exception.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator=""$ -} - -void $exception.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $exception.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$ -} - -$endif$ - -$endif$ ->> - -operation(ctx, parent, operation, param_list) ::= <<>> - -param_list(parameters) ::= <<>> - -param(parameter) ::= <<>> - -const_decl(ctx, parent, const, const_type) ::= << -$ctx.setCdrv1Templates$ -$const_type$ -$if(const.parent)$ -$if(const.parent.isInterface)$ -$if(const.typeCode.isType_5)$ -const $const.typeCode.cppTypename$ $const.parent.scopedname$::$const.name$ = $const.value$; -$elseif(const.typeCode.isType_6)$ -const $const.typeCode.cppTypename$ $const.parent.scopedname$::$const.name$ = $const.value$; -$endif$ -$endif$ -$endif$ -$ctx.unsetCdrv1Templates$ ->> - -fwd_decl(ctx, parent, type) ::= <<>> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << -$ctx.setCdrv1Templates$ -$declarator_type$ -$typedefs_type$ -$typedefs : -{ typedef | -$if(ctx.generateTypesC)$ -$if(typedef.typedefContentTypeCode.isSequenceType)$ -$sequences_definition_impl(typecode=typedef.typedefContentTypeCode, scopedtypename=typedef.scopedname, typename=typedef.name)$ -$endif$ -$endif$ -}; separator="\n"$ -$ctx.unsetCdrv1Templates$ ->> - -struct_type(ctx, parent, struct, extensions, member_list) ::= << -$ctx.setCdrv1Templates$ -$member_list$ -$struct.name$::$struct.name$() - $if(struct.inheritance)$ - : $struct_inherit_default_init(struct.inheritance)$ - $endif$ -{ - $struct.members:{ member |$member_default_init(ctx=ctx, member=member, loopvar=ctx.newLoopVarName)$}; separator="\n"$ - - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ -} - -$struct.name$::~$struct.name$() -{ - $struct.members:{ member |$member_destructor(ctx=ctx, member=member)$}; separator="\n"$ -} - -$struct.name$::$struct.name$( - const $struct.name$& x) - $if(struct.inheritance)$ - : $struct_inherit_copy_init(struct.inheritance)$ - $endif$ -{ - $if(struct.members)$ - $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ -} - -$struct.name$::$struct.name$( - $struct.name$&& x) noexcept - $if(struct.inheritance)$ - : $struct_inherit_move_init(struct.inheritance)$ - $endif$ -{ - $if(struct.members)$ - $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ -} - -$struct.name$& $struct.name$::operator =( - const $struct.name$& x) -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::operator =(x); - $endif$ - - $if(struct.members)$ - $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ - - return *this; -} - -$struct.name$& $struct.name$::operator =( - $struct.name$&& x) noexcept -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::operator =(std::move(x)); - $endif$ - - $if(struct.members)$ - $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ - $else$ - static_cast(x); - $endif$ - - return *this; -} - -bool $struct.name$::operator ==( - const $struct.name$& x) const -{ - $if(struct.inheritance)$ - if ($struct.inheritance.scopedname$::operator !=(x)) return false; - $endif$ - - $if(!struct.members)$ - static_cast(x); - return true; - $else$ - return ($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$); - $endif$ -} - -bool $struct.name$::operator !=( - const $struct.name$& x) const -{ - return !(*this == x); -} - -$if(ctx.anyCdr)$ -size_t $struct.name$::getMaxCdrSerializedSize( - size_t current_alignment) -{ - static_cast(current_alignment); - return $struct.cScopedname$_max_cdr_typesize; -} - -size_t $struct.name$::getCdrSerializedSize( - const $struct.name$& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - $if(struct.inheritance)$ - current_alignment += $struct.inheritance.scopedname$::getCdrSerializedSize(data, current_alignment); - $endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$serialized_size(ctx=ctx, object=member, data="data", var="current_alignment")$$endif$}; separator="\n"$ - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ -void $struct.name$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::serialize(scdr); - $endif$ - - $if(struct.members)$ - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator=""$ - $else$ - static_cast(scdr); - $endif$ -} - -void $struct.name$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::deserialize(dcdr); - $endif$ - - $if(struct.members)$ - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator="\n"$ - $else$ - static_cast(dcdr); - $endif$ -} - -$endif$ - -$if(ctx.fastcdr)$ -void $struct.name$::serialize( - eprosima::fastcdr::FastCdr &scdr) const -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::serialize(scdr); - $endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator=""$ -} - -void $struct.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $if(struct.inheritance)$ - $struct.inheritance.scopedname$::deserialize(dcdr); - $endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator="\n"$ -} - -$endif$ - -bool $struct.name$::isKeyDefined() -{ - $if(struct.inheritance)$ - if ($struct.inheritance.scopedname$::isKeyDefined()) - return true; - $endif$ - - return $if(struct.hasKey)$true$else$false$endif$; -} - -void $struct.name$::serializeKey( - eprosima::fastcdr::Cdr& scdr) const -{ - (void) scdr; - $if(struct.inheritance)$ $struct.inheritance.scopedname$::serializeKey(scdr);$endif$ - $if(struct.hasKey)$ $struct.members : { member | $if(member.annotationKey)$ $if(member.typecode.isStructType)$ $if(member.typecode.hasKey)$ m_$member.name$.serializeKey(scdr); $else$ m_$member.name$.serialize(scdr); $endif$ $else$ $object_serialization(ctx=ctx, object=member, preffix="m_")$ $endif$ $endif$ }; separator="\n"$ $endif$ -} - -$struct.members:{ member | $public_member_declaration(class=struct.name, member=member)$}; separator="\n"$ - -$extensions : { extension | $extension$}; separator="\n"$ -$ctx.unsetCdrv1Templates$ ->> - -bitset_type(ctx, parent, bitset) ::= << -$bitset.name$::$bitset.name$() - $if(bitset.inheritance)$ - : $bitset_inherit_default_init(bitset.inheritance)$ - $endif$ -{ - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ -} - -$bitset.name$::~$bitset.name$() -{ -} - -$bitset.name$::$bitset.name$( - const $bitset.name$& x) - $if(bitset.inheritance)$ - : $bitset_inherit_copy_init(bitset.inheritance)$ - $endif$ -{ - m_bitset = x.m_bitset; -} - -$bitset.name$::$bitset.name$( - $bitset.name$&& x) noexcept - $if(bitset.inheritance)$ - : $bitset_inherit_move_init(bitset.inheritance)$ - $endif$ -{ - m_bitset = x.m_bitset; -} - -$bitset.name$& $bitset.name$::operator =( - const $bitset.name$& x) -{ - $if(bitset.inheritance)$ - $bitset.inheritance.scopedname$::operator =(x); - $endif$ - - m_bitset = x.m_bitset; - - return *this; -} - -$bitset.name$& $bitset.name$::operator =( - $bitset.name$&& x) noexcept -{ - $if(bitset.inheritance)$ - $bitset.inheritance.scopedname$::operator =(std::move(x)); - $endif$ - - m_bitset = x.m_bitset; - - return *this; -} - -bool $bitset.name$::operator ==( - const $bitset.name$& x) const -{ - $if(bitset.inheritance)$ - if ($bitset.inheritance.scopedname$::operator !=(x)) return false; - $endif$ - - return m_bitset == x.m_bitset; -} - -bool $bitset.name$::operator !=( - const $bitset.name$& x) const -{ - return !(*this == x); -} - -$if(ctx.anyCdr)$ -size_t $bitset.name$::getCdrSerializedSize( - const $bitset.name$&, - size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - current_alignment += sizeof(helper::FindType<$bitset.fullBitSize$>::type)$if(ctx.cdr)$ + - eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(helper::FindType<$bitset.fullBitSize$>::type))$endif$; - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ -void $bitset.name$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - $if(!bitset.scope.empty)$ - using namespace $bitset.scope$; - $endif$ - - helper::FindType<$bitset.fullBitSize$>::type bits = static_cast::type>(bitset().to_ullong()); - scdr << bits; -} - -void $bitset.name$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $if(!bitset.scope.empty)$ - using namespace $bitset.scope$; - $endif$ - - helper::FindType<$bitset.fullBitSize$>::type bits; - dcdr \>> bits; - bitset(std::bitset<$bitset.fullBitSize$>(bits)); -} - -$endif$ - -$if(ctx.fastcdr)$ -void $bitset.name$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - $if(!bitset.scope.empty)$ - using namespace $bitset.scope$; - $endif$ - - helper::FindType<$bitset.fullBitSize$>::type bits = static_cast::type>(bitset().to_ullong()); - scdr << bits; -} - -void $bitset.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $if(!bitset.scope.empty)$ - using namespace $bitset.scope$; - $endif$ - - helper::FindType<$bitset.fullBitSize$>::type bits; - dcdr \>> bits; - bitset(std::bitset<$bitset.fullBitSize$>(bits)); -} - -$endif$ - - -$bitset.bitfields:{ bitfield | $public_bitfield_definition(bitfield)$}; separator="\n"$ - -std::bitset<$bitset.fullBitSize$> $bitset.name$::bitset() const -{ - std::string str_value; - - $if(bitset.inheritance)$ - str_value = static_cast(this)->bitset().to_string() + str_value; - $endif$ - - str_value = m_bitset.to_string() + str_value; - - return std::bitset<$bitset.fullBitSize$>(str_value); -} - -void $bitset.name$::bitset( - const std::bitset<$bitset.fullBitSize$>& bitset) -{ - std::string str_value {bitset.to_string()}; - size_t base_diff {0}; - size_t last_post {std::string::npos}; - - $if(bitset.inheritance)$ - { - base_diff += $bitset.inheritance.fullBitSize$; - std::bitset<$bitset.inheritance.fullBitSize$> internal_bitset(str_value.substr(str_value.length() - base_diff, last_post)); - static_cast<$bitset.inheritance.scopedname$*>(this)->bitset(internal_bitset); - last_post = base_diff; - } - $endif$ - - base_diff += $bitset.bitSize$; - m_bitset = std::bitset<$bitset.bitSize$>(str_value.substr(str_value.length() - base_diff, last_post)); -} - ->> - -public_bitfield_definition(member) ::= << -$if(member.name)$ -void $bitset.scopedname$::$member.name$( - $member.spec.cppTypename$ _$member.name$) -{ - int base = $member.basePosition$; -$if(member.spec.typecode.isType_7)$ - m_bitset.set(base, _$member.name$); -$else$ - int size = $member.spec.bitSize$; - for (int i = base; i < base + size; ++i) - { - m_bitset.set(i, !!(_$member.name$ & 0x01)); - _$member.name$ = _$member.name$ \>> 1; - } -$endif$ - -} - -$member.spec.cppTypename$ $bitset.scopedname$::$member.name$() const -{ - int base = $member.basePosition$; -$if(member.spec.typecode.isType_7)$ - return m_bitset.test(base); -$else$ - int size = $member.spec.bitSize$; - std::bitset<$member.spec.bitSize$> aux; - for (int i = 0; i < size; ++i) - { - aux.set(i, m_bitset.test(i + base)); - } - return static_cast<$member.spec.cppTypename$>(aux.to_ullong()); -$endif$ - -} -$endif$ - ->> - -union_type(ctx, parent, union, extensions, switch_type) ::= << -$ctx.setCdrv1Templates$ -$switch_type$ -$union.name$::$union.name$() -{ - $if(union.defaultvalue)$ - m__d = $union.defaultvalue$; - $else$ - m__d = $first(first(union.members).labels)$; - $endif$ - $union.members:{ member |$member_default_init(ctx=ctx, member=member, loopvar=ctx.newLoopVarName)$}; separator="\n"$ -} - -$union.name$::~$union.name$() -{ -} - -$union.name$::$union.name$( - const $union.name$& x) -{ - m__d = x.m__d; - - switch(m__d) - { - $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ - $unionmemberdefault_copy(union.defaultMember)$ - } -} - -$union.name$::$union.name$( - $union.name$&& x) noexcept -{ - m__d = x.m__d; - - switch(m__d) - { - $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ - $unionmemberdefault_move(union.defaultMember)$ - } -} - -$union.name$& $union.name$::operator =( - const $union.name$& x) -{ - m__d = x.m__d; - - switch(m__d) - { - $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ - $unionmemberdefault_copy(union.defaultMember)$ - } - - return *this; -} - -$union.name$& $union.name$::operator =( - $union.name$&& x) noexcept -{ - m__d = x.m__d; - - switch(m__d) - { - $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ - $unionmemberdefault_move(union.defaultMember)$ - } - - return *this; -} - -bool $union.name$::operator ==( - const $union.name$& x) const -{ - if (m__d != x.m__d) - { - return false; - } - - switch(m__d) - { - $union.members:{ member | $unionmember_compare(member)$}; separator="\n"$ - $unionmemberdefault_compare(union.defaultMember)$ - } - return false; -} - -bool $union.name$::operator !=( - const $union.name$& x) const -{ - return !(*this == x); -} - -void $union.name$::_d( - $union.discriminator.cppTypename$ __d) -{ - bool b = false; - - switch(m__d) - { - $union.members:{ member | $unionmember_discriminator_case(member=member, totallabels=union.totallabels)$}; separator="\n"$ - } - - if(!b) - { - throw BadParamException("Discriminator doesn't correspond with the selected union member"); - } - - m__d = __d; -} - -$union.discriminator.cppTypename$ $union.name$::_d() const -{ - return m__d; -} - -$union.discriminator.cppTypename$& $union.name$::_d() -{ - return m__d; -} - -$union.members:{ member | $public_unionmember_declaration(class=union.name, member=member, defaultvalue=union.defaultvalue, totallabels=union.totallabels)$}; separator="\n"$ - -$if(ctx.anyCdr)$ -// TODO(Ricardo) Review -size_t $union.name$::getCdrSerializedSize( - const $union.name$& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - $serialized_size_type(ctx=ctx, typecode=union.discriminator, var="current_alignment")$ - - switch(data.m__d) - { - $union.members:{ member |$unionmember_case_selection_sesize(ctx=ctx, member=member, data="data", var="current_alignment")$}; separator="\n"$ - $unionmemberdefault_case_selection_sesize(ctx=ctx, member=union.defaultMember, data="data", var="current_alignment")$ - } - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ -void $union.name$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - scdr << $serializeCasting(typecode=union.discriminator)$m__d; - - switch(m__d) - { - $union.members:{ member |$unionmember_case_selection_se(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_se(ctx=ctx, member=union.defaultMember)$ - } -} - -void $union.name$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $deserializePossibleEnum(typecode=union.discriminator, name="m__d", preffix="")$ - - switch(m__d) - { - $union.members:{ member |$unionmember_case_selection_de(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_de(ctx=ctx, member=union.defaultMember)$ - } -} - -$endif$ - -$if(ctx.fastcdr)$ -void $union.name$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - scdr << $serializeCasting(typecode=union.discriminator)$m__d; - - switch(m__d) - { - $union.members:{ member |$unionmember_case_selection_se(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_se(ctx=ctx, member=union.defaultMember)$ - } -} - -void $union.name$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $deserializePossibleEnum(typecode=union.discriminator, name="m__d", preffix="")$ - - switch(m__d) - { - $union.members:{ member |$unionmember_case_selection_de(ctx=ctx, member=member)$}; separator="\n"$ - $unionmemberdefault_case_selection_de(ctx=ctx, member=union.defaultMember)$ - } -} - -$endif$ - -$ctx.unsetCdrv1Templates$ ->> - -enum_type(ctx, parent, enum) ::= <<>> - -bitmask_type(ctx, parent, bitmask) ::= <<>> - -sequence_type(ctx, sequence, type_sequence) ::= << - -$type_sequence$ - ->> - -map_type(ctx, map, key_type, value_type) ::= << - -$key_type$ -$value_type$ - ->> - -string_type(ctx, string) ::= <<>> - -wide_string_type(ctx, wstring) ::= <<>> - -array_declarator(ctx, array, array_type) ::= <<>> - -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - -element_type(ctx, element, type_element, declarator) ::= << - -$type_element$ -$declarator$ - ->> - -/***** Utils *****/ - -public_member_declaration(class, member) ::= << -$if(member.typecode.primitive)$ -$public_primitive_member_declaration(class=class, member=member)$ -$elseif(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -$public_cstring_member_declaration(class=class, member=member)$ -$else$ -$public_object_member_declaration(class=class, member=member)$ -$endif$ -$else$ -$public_object_member_declaration(class=class, member=member)$ -$endif$ ->> - -public_primitive_member_declaration(class, member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -void $class$::$member.name$( - $member.typecode.cppTypename$ _$member.name$) -{ - m_$member.name$ = _$member.name$; -} - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -$member.typecode.cppTypename$ $class$::$member.name$() const -{ - return m_$member.name$; -} - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -$member.typecode.cppTypename$& $class$::$member.name$() -{ - return m_$member.name$; -} ->> - -public_cstring_member_declaration(class, member) ::= << -/*! - * @brief This function sets a value in member $member.name$ - * @param _$member.name$ New value for member $member.name$ - */ -void $class$::$member.name$( - const $member.typecode.cppTypename$ _$member.name$) -{ - free(m_$member.name$); - m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(_$member.name$) + 1)); - strncpy(m_$member.name$, _$member.name$, strlen(_$member.name$) + 1); -} - -/*! - * @brief This function returns the value of member $member.name$ - * @return Value of member $member.name$ - */ -const $member.typecode.cppTypename$ $class$::$member.name$() const -{ - return m_$member.name$; -} ->> - -public_object_member_declaration(class, member) ::= << -/*! - * @brief This function copies the value in member $member.name$ - * @param _$member.name$ New value to be copied in member $member.name$ - */ -void $class$::$member.name$( - const $member.typecode.cppTypename$& _$member.name$) -{ - m_$member.name$ = _$member.name$; -} - -/*! - * @brief This function moves the value in member $member.name$ - * @param _$member.name$ New value to be moved in member $member.name$ - */ -void $class$::$member.name$( - $member.typecode.cppTypename$&& _$member.name$) -{ - m_$member.name$ = std::move(_$member.name$); -} - -/*! - * @brief This function returns a constant reference to member $member.name$ - * @return Constant reference to member $member.name$ - */ -const $member.typecode.cppTypename$& $class$::$member.name$() const -{ - return m_$member.name$; -} - -/*! - * @brief This function returns a reference to member $member.name$ - * @return Reference to member $member.name$ - */ -$member.typecode.cppTypename$& $class$::$member.name$() -{ - return m_$member.name$; -} ->> - -public_unionmember_declaration(class, member, totallabels, defaultvalue) ::= << -$if(ctx.generateTypesC)$$if(member.typecode.isStringType)$$unionmember_cstring_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$$else$$public_unionmember_cpp_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$$endif$$else$$public_unionmember_cpp_declaration(class=class, member=member, totallabels=totallabels, defaultvalue=defaultvalue)$$endif$ ->> - -unionmember_cstring_declaration(class, member, totallabels, defaultvalue) ::= << -void $class$::$member.name$( - const char* _$member.name$) -{ - free(m_$member.name$); - m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(_$member.name$) + 1)); - strncpy(m_$member.name$, _$member.name$, strlen(_$member.name$)); - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -const char* $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} ->> - -public_unionmember_cpp_declaration(class, member, totallabels, defaultvalue) ::= << -$if(member.typecode.primitive)$ -void $class$::$member.name$( - $member.typecode.cppTypename$ _$member.name$) -{ - m_$member.name$ = _$member.name$; - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -$member.typecode.cppTypename$ $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} - -$member.typecode.cppTypename$& $class$::$member.name$() -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} -$else$ -void $class$::$member.name$( - const $member.typecode.cppTypename$& _$member.name$) -{ - m_$member.name$ = _$member.name$; - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -void $class$::$member.name$( - $member.typecode.cppTypename$&& _$member.name$) -{ - m_$member.name$ = std::move(_$member.name$); - $unionmember_set_discriminator(member=member, defaultvalue=defaultvalue)$ -} - -const $member.typecode.cppTypename$& $class$::$member.name$() const -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} - -$member.typecode.cppTypename$& $class$::$member.name$() -{ - $unionmember_check_case_list(member=member, totallabels=totallabels)$ - - return m_$member.name$; -} -$endif$ ->> - -member_copy(ctx, member) ::= << -$if(ctx.generateTypesC)$ -$if(member.typecode.isStringType)$ -free(m_$member.name$); -m_$member.name$ = (char*)malloc(sizeof(char) * (strlen(x.m_$member.name$) + 1)); -strncpy(m_$member.name$, x.m_$member.name$, strlen(x.m_$member.name$) + 1); -$else$ -m_$member.name$ = x.m_$member.name$; -$endif$ -$else$ -m_$member.name$ = x.m_$member.name$; -$endif$ ->> - -member_move(member) ::= << -$if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; -$else$ -m_$member.name$ = std::move(x.m_$member.name$); -$endif$ ->> - -// TODO Mirar si el default: esta delante de otros casos, el resto no se ejecuta. -unionmember_discriminator_case(member, totallabels) ::= << -$if(member.default)$ -default: -b = true; -switch(__d) -{ - $totallabels:{ label | case $label$:}; separator="\n"$ - b = false; - break; - default: - break; -} -break; -$else$ -$member.labels:{ label | case $label$:}; separator="\n"$ -switch(__d) -{ - $member.labels:{ label | case $label$:}; separator="\n"$ - b = true; - break; - default: - break; -} -break; -$endif$ ->> - -unionmember_copy(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ -m_$member.name$ = x.m_$member.name$; -break; -$endif$ ->> - -unionmemberdefault_copy(member) ::= << -default: -$if(member)$ -$if(member.default)$ -m_$member.name$ = x.m_$member.name$; -$endif$ -$endif$ - -break; ->> - -unionmember_move(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ -$if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; -$else$ -m_$member.name$ = std::move(x.m_$member.name$); -$endif$ - -break; -$endif$ ->> - -unionmemberdefault_move(member) ::= << -default: -$if(member)$ -$if(member.default)$ -$if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; -$else$ -m_$member.name$ = std::move(x.m_$member.name$); -$endif$ -$endif$ -$endif$ - -break; ->> - -unionmember_compare(member) ::= << -$if(member.labels)$ -$member.labels:{ label | case $label$:}; separator="\n"$ - return (m_$member.name$ == x.m_$member.name$); - break; -$endif$ ->> - -unionmemberdefault_compare(member) ::= << -default: -$if(member)$ -$if(member.default)$ -return m_$member.name$ == x.m_$member.name$; -$endif$ -$endif$ - -break; ->> - -unionmember_set_discriminator(member, defaultvalue) ::= << -$if(member.default)$ -m__d = $defaultvalue$; -$else$ -m__d = $first(member.labels)$; -$endif$ ->> - -unionmember_check_case_list(member, totallabels) ::= << -$if(member.default)$ -bool b = true; - -switch(m__d) -{ - $totallabels:{label | case $label$:}; separator="\n"$ - b = false; - break; - default: - break; -} -$else$ -bool b = false; - -switch(m__d) -{ - $member.labels:{ label | case $label$:}; separator="\n"$ - b = true; - break; - default: - break; -} -$endif$ - -if(!b) -{ - throw BadParamException("This member has not been selected"); -} ->> - -unionmember_case_selection_se(ctx, member) ::= << -$if(member.labels)$ -$member.labels:{ label |case $label$:}; separator="\n"$ -$object_serialization(ctx=ctx, object=member, preffix="m_")$ -break; -$endif$ ->> - -unionmemberdefault_case_selection_se(ctx, member) ::= << -default: -$if(member)$ -$if(member.default)$ -$object_serialization(ctx=ctx, object=member, preffix="m_")$ -$endif$ -$endif$ - -break; ->> - -unionmember_case_selection_de(ctx, member) ::= << -$if(member.labels)$ -$member.labels:{ label |case $label$:}; separator="\n"$ -$object_deserialization(ctx=ctx, object=member, preffix="m_")$ -break; -$endif$ ->> - -unionmemberdefault_case_selection_de(ctx, member) ::= << -default: -$if(member)$ -$if(member.default)$ -$object_deserialization(ctx=ctx, object=member, preffix="m_")$ -$endif$ -$endif$ - -break; ->> - -unionmember_case_selection_sesize(ctx, member, data, var) ::= << -$if(member.labels)$ -$member.labels:{ label |case $label$:}; separator="\n"$ -$serialized_size(ctx=ctx, object=member, data=data, var=var)$ -break; -$endif$ ->> - -unionmemberdefault_case_selection_sesize(ctx, member, data, var) ::= << -default: -$if(member)$ -$if(member.default)$ -$serialized_size(ctx=ctx, object=member, data=data, var=var)$ -$endif$ -$endif$ - -break; ->> - -sequences_definition(typecode) ::= << -$sequences_definition_impl(typecode=typecode, scopedtypename=typecode.cppTypename, typename=typecode.cppTypename)$ ->> - -sequences_definition_impl(typecode, scopedtypename, typename) ::= << - -$scopedtypename$::$typename$() -{ - // value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - value_ = nullptr; -} - -$scopedtypename$::$typename$( - uint32_t maximum) - : maximum_(maximum) -{ - // value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - value_ = nullptr; -} - -$scopedtypename$::$typename$( - uint32_t length, - $typecode.contentTypeCode.cppTypename$* data, - bool release) - : length_(length) - , value_(data) - , release_(release) -{ -} - -$scopedtypename$::$typename$( - const $typename$& $typename$_) - : maximum_($typename$_.maximum_) - , length_($typename$_.length_) - , release_(true) -{ - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - for (uint32_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1); - $else$ - value_[i] = $typename$_.value_[i];$endif$$else$ - value_[i] = $typename$_.value_[i];$endif$ - } -} - -$scopedtypename$& $scopedtypename$::operator =( - const $typename$& $typename$_) -{ - maximum_ = $typename$_.maximum_; - length_ = $typename$_.length_; - free_memory(); - release_ = true; - - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - for (uint32_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1); - $else$ - value_[i] = $typename$_.value_[i];$endif$$else$ - value_[i] = $typename$_.value_[i];$endif$ - } - - return *this; -} - -$scopedtypename$::~$typename$() -{ - free_memory(); -} - -$typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ $scopedtypename$::operator[]( - uint32_t index) -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ != 0) // Must be set. If not, will return nullptr[index] and crash. - { - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_[index]; -} - -const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$$else$&$endif$$else$&$endif$ $scopedtypename$::operator[]( - uint32_t index) const -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ != 0) // Must be set. If not, will return nullptr[index] and crash. - { - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_[index]; -} - -void $scopedtypename$::size( - uint32_t size) -{ - if (maximum_ == 0) - { - if(value_ != nullptr && size > length_) - { - $typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[size]; - for (uint32_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - if (value_[i] != nullptr) - { - strncpy(temp[i], value_[i], strlen(value_[i]) + 1); - } - else - { - temp[i] = nullptr; - } - $else$ - temp[i] = value_[i];$endif$$else$ - temp[i] = value_[i];$endif$ - } - free_memory(); - value_ = temp; - release_ = true; - } - } - else - { - if(size > maximum_) - { - throw BadParamException("Length is greater than maximum length of the sequence"); - } - } - - length_ = size; -} - -uint32_t $scopedtypename$::size() const -{ - return length_; -} - -void $scopedtypename$::length( - uint32_t length) -{ - if (maximum_ == 0) - { - if(value_ != nullptr && length > length_) - { - $typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[length]; - for (uint32_t i = 0; i < length_; ++i) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - if (value_[i] != nullptr) - { - strncpy(temp[i], value_[i], strlen(value_[i]) + 1); - } - else - { - temp[i] = nullptr; - } - $else$ - temp[i] = value_[i];$endif$$else$ - temp[i] = value_[i];$endif$ - } - free_memory(); - value_ = temp; - release_ = true; - } - } - else - { - if(length > maximum_) - { - throw BadParamException("Length is greater than maximum length of the sequence"); - } - } - - length_ = length; -} - -uint32_t $scopedtypename$::length() const -{ - return length_; -} - -uint32_t $scopedtypename$::maximum() const -{ - if (maximum_ == 0) - { - return length_; - } - else - { - return maximum_; - } -} - -void $scopedtypename$::value( - $typecode.contentTypeCode.cppTypename$* value) -{ - free_memory(); - value_ = value; -} - -$typecode.contentTypeCode.cppTypename$* $scopedtypename$::value( - bool orphan) -{ - if (orphan && !release_) - { - return nullptr; - } - - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ == 0) // Not yet set - { - return nullptr; // To be coherent with accessing value[length]; - } - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - if (orphan) - { - release_ = false; - } - - return value_; -} - -const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ const$else$$endif$$else$$endif$* $scopedtypename$::value() const -{ - if (value_ == nullptr) - { - if (maximum_ == 0) - { - if (length_ == 0) // Not yet set - { - return nullptr; // To be coherent with accessing value[length]; - } - value_ = new $typecode.contentTypeCode.cppTypename$[length_]; - } - else - { - value_ = new $typecode.contentTypeCode.cppTypename$[maximum_]; - } - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - return value_; -} - -void $scopedtypename$::release( - bool release) -{ - release_ = release; -} - -bool $scopedtypename$::release() const -{ - return release_; -} - -bool& $scopedtypename$::release() -{ - return release_; -} - -$if(ctx.anyCdr)$ -size_t $scopedtypename$::getCdrSerializedSize( - const $scopedtypename$& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - current_alignment += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment(current_alignment, 4)$endif$; - - $sequence_serialized_size(ctx=ctx, typecodeSeq=typecode, data="data", var="current_alignment", loopvar=ctx.newLoopVarName)$ - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ -void $scopedtypename$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - scdr << length_; - - if (value_ == nullptr && length_ > 0) - { - uint32_t size = (maximum_ == 0) ? length_ : maximum_; - value_ = new $typecode.contentTypeCode.cppTypename$[size]; - - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - } - - for (uint32_t count = 0; count < length_; ++count) - { - scdr << value_[count]; - } -} - -void $scopedtypename$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - uint32_t old_length = length_; - uint32_t new_length; - - dcdr \>> new_length; - - if (maximum_ != 0 && new_length > maximum_) - { - throw BadParamException("Deserialized length is greater than maximum length of the sequence. Incompatible \ - sequences."); - } - - if ((value_ == nullptr && new_length > 0) || (old_length < new_length)) - { - free_memory(); - - uint32_t size = (maximum_ == 0) ? new_length : maximum_; - value_ = new $typecode.contentTypeCode.cppTypename$[size]; - } - - length_ = new_length; - - for (uint32_t count = 0; count < length_; ++count) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - { - std::string temp; - dcdr \>> temp; - value_[count] = (char*)malloc(temp.size() + 1); - strncpy(value_[count], temp.c_str(), temp.size() + 1); - } - $else$ - dcdr \>> value_[count];$endif$$else$ - dcdr \>> value_[count];$endif$ - } -} - -void $scopedtypename$::free_memory() -{ - if (release_) - { - $if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$ - for (uint32_t count = 0; count < length_; ++count) - { - free(value_[count]); - value_[count] = nullptr; - } - $else$$endif$$else$$endif$ - delete[](value_); - } - value_ = nullptr; -} - -$endif$ ->> - -object_serialization(ctx, object, preffix) ::= << -$if(object.typecode.isType_f)$ -$object_array_serialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(object.typecode.isType_e)$ -$object_seq_serialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(object.typecode.isMapType)$ -$object_map_serialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$$if(object.typecode.isStringType)$.c_str()$endif$; -$endif$ ->> - -object_array_serialization(ctx, object, preffix) ::= << -$if(object.typecode.contentTypeCode.isStringType)$ -$string_collection_serialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(rest(object.typecode.dimensions))$ -$recursive_array_array_serialization(ctx=ctx, name=cdrMemberName(name=object.name, preffix=preffix), loopvar=ctx.nextLoopVarName, dims=object.typecode.dimensions, object=object)$ -$elseif(object.typecode.contentTypeCode.isType_c)$ -scdr.serializeArray(reinterpret_cast($preffix$$object.name$.data()), $preffix$$object.name$.size()); -$else$ -scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$; -$endif$ ->> - -object_seq_serialization(ctx, object, preffix) ::= << -$if(object.typecode.contentTypeCode.isType_c)$ -scdr << static_cast($preffix$$object.name$.size()); -scdr.serializeArray(reinterpret_cast($preffix$$object.name$.data()), $preffix$$object.name$.size()); -$elseif(object.typecode.contentTypeCode.isStringType)$ -$string_collection_serialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$; -$endif$ ->> - -object_map_serialization(ctx, object, preffix) ::= << -scdr << static_cast($preffix$$object.name$.size()); -for (const auto& pair : $preffix$$object.name$) -{ -$if(object.typecode.keyTypeCode.isType_c)$ - scdr << static_cast(pair.first); -$elseif(object.typecode.keyTypeCode.isType_d || - object.typecode.keyTypeCode.isStringType || - object.typecode.keyTypeCode.isWStringType)$ - scdr << pair.first$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$; -$else$ - scdr << pair.first; -$endif$ -$if(object.typecode.valueTypeCode.isType_c)$ - scdr << static_cast(pair.second); -$elseif(object.typecode.valueTypeCode.isType_d || - object.typecode.valueTypeCode.isStringType || - object.typecode.valueTypeCode.isWStringType)$ - scdr << pair.second$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$else$ - scdr << pair.second; -$endif$ -} ->> - -string_collection_serialization(ctx, object, preffix) ::= << -$if(object.typecode.isType_f)$ -$recursive_string_array_serialization(ctx=ctx, name=cdrMemberName(name=object.name, preffix=preffix), loopvar=ctx.nextLoopVarName, dims=object.typecode.dimensions, object=object)$ -$elseif(ctx.generateTypesC)$ -$if(object.typecode.isType_e)$ -{ - scdr << $preffix$$object.name$; -} -$else$ -{ - std::vector temp_$object.name$; - for (char* str : $preffix$$object.name$) - { - temp_$object.name$.push_back(std::string(str != nullptr ? str : "")); - } - scdr << temp_$object.name$; -} -$endif$ - -$elseif(object.typecode.contentTypeCode.isStringType)$ -$if(object.typecode.contentTypeCode.isBounded)$ -{ -$if(object.typecode.isType_e)$ - scdr << static_cast($preffix$$object.name$.size()); -$endif$ - - for (const auto& item : $preffix$$object.name$) - { - scdr << item.c_str(); - } -} - -$else$ -scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$; - -$endif$ -$else$ -scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$; - -$endif$ ->> - -recursive_string_array_serialization(ctx, name, loopvar, dims, object) ::= << -$if(rest(dims))$ -for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $recursive_string_array_serialization(ctx=ctx, name=cdrIndexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims), object=object)$ -} -$elseif(ctx.generateTypesC)$ -for (char* str : $name$) -{ - scdr << std::string(str != nullptr ? str : ""); -} -$else$ -for (const auto& str : $name$) -{ - scdr << str$if(object.typecode.contentTypeCode.isStringType)$.c_str()$endif$; -} - -$endif$ ->> - -recursive_array_array_serialization(ctx, name, loopvar, dims, object) ::= << -$if(rest(dims))$ -for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $recursive_array_array_serialization(ctx=ctx, name=cdrIndexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims), object=object)$ -} -$elseif(object.typecode.contentTypeCode.isType_c)$ -scdr.serializeArray(reinterpret_cast($name$.data()), $name$.size()); -$elseif(object.typecode.contentTypeCode.isBitmaskType)$ -scdr.serializeArray(reinterpret_cast($name$.data()), $name$.size()); -$elseif(object.typecode.contentTypeCode.isStringType)$ -$string_collection_serialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -scdr << $name$; -$endif$ ->> - -recursive_array_array_deserialization(ctx, name, loopvar, dims, object) ::= << -$if(rest(dims))$ -for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $recursive_array_array_deserialization(ctx=ctx, name=cdrIndexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims), object=object)$ -} -$elseif(object.typecode.contentTypeCode.isType_c)$ -dcdr.deserializeArray(reinterpret_cast($name$.data()), $name$.size()); -$elseif(object.typecode.contentTypeCode.isBitmaskType)$ -dcdr.deserializeArray(reinterpret_cast($name$.data()), $name$.size()); -$elseif(object.typecode.contentTypeCode.isStringType)$ -$string_collection_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -dcdr \>> $name$; -$endif$ ->> - -object_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.isType_f)$ -$object_array_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(object.typecode.isMapType)$ -$object_map_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(object.typecode.isType_e)$ -$object_map_seq_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -$deserializePossibleEnum(typecode=object.typecode, name=object.name, preffix=preffix)$ -$endif$ ->> - -object_array_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.contentTypeCode.isStringType)$ -$string_collection_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$elseif(rest(object.typecode.dimensions))$ -$recursive_array_array_deserialization(ctx=ctx, name=cdrMemberName(name=object.name, preffix=preffix), loopvar=ctx.nextLoopVarName, dims=object.typecode.dimensions, object=object)$ -$elseif(object.typecode.contentTypeCode.isType_c)$ -dcdr.deserializeArray(reinterpret_cast($preffix$$object.name$.data()), $preffix$$object.name$.size()); -$else$ -dcdr \>> $preffix$$object.name$; -$endif$ ->> - -object_map_seq_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.contentTypeCode.isType_c)$ -{ - uint32_t seq_length = 0; - dcdr \>> seq_length; - $preffix$$object.name$.resize(seq_length); - dcdr.deserializeArray(reinterpret_cast($preffix$$object.name$.data()), seq_length); -} -$elseif(object.typecode.contentTypeCode.isStringType)$ -$string_collection_deserialization(ctx=ctx, object=object, preffix=preffix)$ -$else$ -dcdr \>> $preffix$$object.name$; -$endif$ ->> - -object_map_deserialization(ctx, object, preffix) ::= << - -$if(object.typecode.valueTypeCode.isType_c || - object.typecode.valueTypeCode.isBitmaskType || - object.typecode.valueTypeCode.isStringType || - object.typecode.valueTypeCode.isWStringType || - object.typecode.keyTypeCode.isStringType || - object.typecode.keyTypeCode.isWStringType)$ -uint32_t seq_length = 0; -dcdr \>> seq_length; -$preffix$$object.name$.clear(); -for (uint32_t i = 0; i < seq_length; ++i) -{ -$object_map_key_deserialization(ctx=ctx, keyTypeCode=object.typecode.keyTypeCode)$ - -$object_map_value_deserialization(ctx=ctx, name=[preffix, object.name], keyTypeCode=object.typecode.keyTypeCode, - valueTypeCode=object.typecode.valueTypeCode)$ -} -$else$ - dcdr \>> $preffix$$object.name$; -$endif$ ->> - - -object_map_key_deserialization(ctx, keyTypeCode) ::= << -$if(keyTypeCode.isStringType)$ - std::string key; - $if(keyTypeCode.isBounded)$ - std::string aux; - dcdr \>> aux; - key = aux.c_str(); - $else$ - dcdr \>> key; - $endif$ -$elseif(keyTypeCode.isWStringType)$ - std::wstring key; - $if(keyTypeCode.isBounded)$ - std::wstring aux; - dcdr \>> aux; - key = aux.c_str(); - $else$ - dcdr \>> key; - $endif$ -$else$ - $keyTypeCode.cppTypename$ key; - dcdr \>> key; -$endif$ ->> - -object_map_value_deserialization(ctx, name, keyTypeCode, valueTypeCode) ::= << -$if(valueTypeCode.isStringType)$ - std::string value; - dcdr \>> value; - $name$[key$if(keyTypeCode.isStringType)$.c_str()$endif$] = value$if(valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(valueTypeCode.isWStringType)$ - std::wstring value; - dcdr \>> value; - $name$[key$if(keyTypeCode.isStringType)$.c_str()$endif$] = value$if(valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(valueTypeCode.isType_c)$ - uint32_t value; - dcdr \>> value; - $name$[key$if(keyTypeCode.isStringType)$.c_str()$endif$] = static_cast<$valueTypeCode.cppTypename$>(value); -$elseif(valueTypeCode.isBitmaskType)$ - uint32_t value; - dcdr \>> value; - $name$[key$if(keyTypeCode.isStringType)$.c_str()$endif$] = static_cast<$valueTypeCode.cppTypename$>(value); -$else$ - $valueTypeCode.cppTypename$ value; - dcdr \>> value; - $name$[key$if(keyTypeCode.isStringType)$.c_str()$endif$] = value$if(valueTypeCode.isStringType)$.c_str()$endif$; -$endif$ ->> - -string_collection_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.isType_f)$ -$recursive_string_array_deserialization(ctx=ctx, name=cdrMemberName(name=object.name, preffix=preffix), loopvar=ctx.nextLoopVarName, dims=object.typecode.dimensions, object=object)$ -$elseif(ctx.generateTypesC)$ -$if(object.typecode.isType_e)$ -{ - dcdr \>> $preffix$$object.name$; -} -$else$ -{ - // Free old memory allocation - for (char* str : $preffix$$object.name$) - { - free(str); - } - $preffix$$object.name$.clear(); - std::vector temp_$object.name$; - dcdr \>> temp_$object.name$; - for (std::string str : temp_$object.name$) - { - char* aux = (char*)malloc(str.size() + 1); - strncpy(aux, str.c_str(), str.size() + 1); - $preffix$$object.name$.push_back(aux); - } -} -$endif$ -$elseif(object.typecode.contentTypeCode.isStringType)$ -$if(object.typecode.contentTypeCode.isBounded)$ -{ -$if(object.typecode.isType_e)$ - uint32_t sequence_size = 0; - dcdr \>> sequence_size; - $preffix$$object.name$.resize(sequence_size); -$endif$ - - for (auto& item : $preffix$$object.name$) - { - std::string s; - dcdr \>> s; - item = s.c_str(); - } -} - -$else$ -dcdr \>> $preffix$$object.name$; -$endif$ -$else$ -dcdr \>> $preffix$$object.name$; -$endif$ ->> - -recursive_string_array_deserialization(ctx, name, loopvar, dims, object) ::= << -$if(rest(dims))$ -for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $recursive_string_array_deserialization(ctx=ctx, name=cdrIndexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims), object=object)$ -} -$elseif(ctx.generateTypesC)$ -// Free old memory allocation -for (char* str : $name$) -{ - free(str); -} -$name$.fill(nullptr); -for (uint32_t index = 0; index < $name$.size(); ++index) -{ - std::string str; - dcdr \>> str; - char* aux = new char[str.size() + 1]; - strncpy(aux, str.c_str(), str.size() + 1); - $name$[index] = aux; -} -$else$ -for (auto& str : $name$) -{ -$if(object.typecode.contentTypeCode.isStringType)$ -$if(object.typecode.contentTypeCode.isBounded)$ - { - std::string aux_str; - dcdr \>> aux_str; - str = aux_str.c_str(); - } - -$else$ - dcdr \>> str; -$endif$ -$else$ - dcdr \>> str; -$endif$ -} - -$endif$ ->> - -bitfield_deserialization(ctx, object) ::= <<$if(member.name)$$member.spec.cppTypename$ aux_$member.name$; -dcdr \>> aux_$member.name$; -$member.name$(aux_$member.name$);$endif$ ->> - -serialized_size_type(ctx, typecode, var) ::= << -$if(typecode.isType_13)$ -$var$ += 16$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 8)$endif$; // 128 bits, but aligned as 64 -$elseif(typecode.primitive)$ -$var$ += $typecode.size$$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecode.size$)$endif$; - -$endif$ ->> - -serialized_size(ctx, object, data, var) ::= << -$if(object.typecode.isType_13)$ -$var$ += 16$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 8)$endif$; // 128 bits, but aligned as 64 -$elseif(object.typecode.primitive || object.typecode.isBitmaskType)$ -$var$ += $object.typecode.size$$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $object.typecode.size$)$endif$; -$elseif(object.typecode.isWStringType)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + ($data$.$object.name$().size()) * 4; // 32 bits -$elseif(object.typecode.isType_d)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $if(ctx.generateTypesC)$strlen($data$.$object.name$())$else$$data$.$object.name$().size()$endif$ + 1; -$elseif(object.typecode.isMapType)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$map_serialized_size(ctx=ctx, typecodeMap=object.typecode, data=[data, ".", object.name, "()"], var=var, loopvar=ctx.newLoopVarName)$ -$elseif(object.typecode.isType_e)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$sequence_serialized_size(ctx=ctx, typecodeSeq=object.typecode, data=[data, ".", object.name, "()"], var=var, loopvar=ctx.newLoopVarName)$ -$elseif(object.typecode.isType_f)$ -$array_serialized_size(ctx=ctx, typecodeArr=object.typecode, data=[data, ".", object.name, "()"], var=var, loopvar=ctx.newLoopVarName, dimensions=object.typecode.dimensions)$ -$elseif(object.typecode.isBitmaskType)$ -$var$ += $object.typecode.size$$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $object.typecode.size$)$endif$; -$else$ -$var$ += $object.typecode.scopedname$::getCdrSerializedSize($data$.$object.name$(), $var$); -$endif$ - ->> - -sequence_serialized_size(ctx, typecodeSeq, data, var, loopvar) ::= << -$if(typecodeSeq.contentTypeCode.primitive || typecodeSeq.contentTypeCode.isBitmaskType)$ -if ($data$.size() > 0) -{ - $if(typecodeSeq.contentTypeCode.isType_13)$ - $var$ += ($data$.size() * $typecodeSeq.contentTypeCode.size$)$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 8)$endif$; // 128 bits, but aligned as 64 - $else$ - $var$ += ($data$.size() * $typecodeSeq.contentTypeCode.size$)$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecodeSeq.contentTypeCode.size$)$endif$; - $endif$ -} - -$elseif(typecodeSeq.contentTypeCode.isType_d)$ - -for(size_t $loopvar$ = 0; $loopvar$ < $data$.size(); ++$loopvar$) -{ - $if(typecodeSeq.contentTypeCode.isWStringType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + ($data$.at($loopvar$).size() * 4); - $else$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + - $if(ctx.generateTypesC)$strlen($data$.value()[$loopvar$])$else$$data$.at($loopvar$).size()$endif$ + 1; - $endif$ -} -$else$ - -for(size_t $loopvar$ = 0; $loopvar$ < $data$.size(); ++$loopvar$) -{ -$if(typecodeSeq.contentTypeCode.isType_e)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $if(ctx.generateTypesC)$ - $sequence_serialized_size(ctx=ctx, typecodeSeq=typecodeSeq.contentTypeCode, data=[data, ".value()[", loopvar, "]"], var=var, loopvar=ctx.nextLoopVarName)$ - $else$ - $sequence_serialized_size(ctx=ctx, typecodeSeq=typecodeSeq.contentTypeCode, data=[data, ".at(", loopvar, ")"], var=var, loopvar=ctx.nextLoopVarName)$ - $endif$ -$elseif(typecodeSeq.contentTypeCode.isMapType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $if(ctx.generateTypesC)$ - $map_serialized_size(ctx=ctx, typecodeMap=typecodeSeq.contentTypeCode, data=[data, ".value()[", loopvar, "]"], var=var, loopvar=ctx.nextLoopVarName)$ - $else$ - $map_serialized_size(ctx=ctx, typecodeMap=typecodeSeq.contentTypeCode, data=[data, ".at(", loopvar, ")"], var=var, loopvar=ctx.nextLoopVarName)$ - $endif$ -$elseif(typecodeSeq.contentTypeCode.isType_f)$ - $if(ctx.generateTypesC)$ - $array_serialized_size(ctx=ctx, typecodeArr=typecodeSeq.contentTypeCode, data=[data, ".value()[", loopvar, "]"], var=var, loopvar=ctx.nextLoopVarName, dimensions=typecodeSeq.contentTypeCode.dimensions)$ - $else$ - $array_serialized_size(ctx=ctx, typecodeArr=typecodeSeq.contentTypeCode, data=[data, ".at(", loopvar, ")"], var=var, loopvar=ctx.nextLoopVarName, dimensions=typecodeSeq.contentTypeCode.dimensions)$ - $endif$ -$else$ - $var$ += $typecodeSeq.contentTypeCode.scopedname$::getCdrSerializedSize($if(ctx.generateTypesC)$$data$.value()[$loopvar$]$else$$data$.at($loopvar$)$endif$, $var$); -$endif$ -} -$endif$ ->> - -array_serialized_size(ctx, typecodeArr, data, var, loopvar, dimensions) ::= << -$if(typecodeArr.contentTypeCode.primitive || typecodeArr.contentTypeCode.isBitmaskType)$ -$if(typecodeArr.notZeroArray)$ -$var$ += ($typecodeArr.size$ * $typecodeArr.contentTypeCode.size$)$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecodeArr.contentTypeCode.size$)$endif$; -$endif$ -$else$ -$if(first(dimensions))$ - -for(size_t $loopvar$ = 0; $loopvar$ < $data$.size(); ++$loopvar$) -{ - $array_serialized_size(ctx=ctx, typecodeArr=typecodeArr, data=[data, ".at(", loopvar, ")"], var=var, loopvar=ctx.nextLoopVarName, dimensions=rest(dimensions))$ -} -$else$ -$if(typecodeArr.contentTypeCode.isType_d)$ - $if(typecodeArr.contentTypeCode.isWStringType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + ($data$.size() * 4); - $else$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $if(ctx.generateTypesC)$strlen($data$)$else$$data$.size()$endif$ + 1; - $endif$ -$elseif(typecodeArr.contentTypeCode.isMapType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $map_serialized_size(ctx=ctx, typecodeMap=typecodeArr.contentTypeCode, data=data, var=var, loopvar=loopvar)$ -$elseif(typecodeArr.contentTypeCode.isType_e)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $sequence_serialized_size(ctx=ctx, typecodeSeq=typecodeArr.contentTypeCode, data=data, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeArr.contentTypeCode.isType_f)$ - $array_serialized_size(ctx=ctx, typecodeArr=typecodeArr.contentTypeCode, data=data, var=var, loopvar=loopvar, dimensions=typecodeArr.contentTypeCode.dimensions)$ -$else$ - $var$ += $typecodeArr.contentTypeCode.scopedname$::getCdrSerializedSize($data$, $var$); -$endif$ -$endif$ -$endif$ ->> - -map_serialized_size(ctx, typecodeMap, data, var, loopvar) ::= << -for(auto $loopvar$ : $data$) -{ - (void)$loopvar$; - - $map_serialized_size_element(ctx=ctx, typecodeMapElement=typecodeMap.keyTypeCode, data=[loopvar, ".first"], var=var, loopvar=loopvar)$ - $map_serialized_size_element(ctx=ctx, typecodeMapElement=typecodeMap.valueTypeCode, data=[loopvar, ".second"], var=var, loopvar=loopvar)$ -\} ->> - -map_serialized_size_element(ctx, typecodeMapElement, data, var, loopvar) ::= << -$if(typecodeMapElement.isType_13)$ - $var$ += 16$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 8)$endif$; // 128 bits, but aligned as 64 -$elseif(typecodeMapElement.primitive || typecodeMapElement.isBitmaskType)$ - $var$ += $typecodeMapElement.size$$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecodeMapElement.size$)$endif$; -$elseif(typecodeMapElement.isWStringType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $data$.size() * 4; -$elseif(typecodeMapElement.isType_d)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $if(ctx.generateTypesC)$strlen($loopvar$)$else$$data$.size()$endif$ + 1; -$elseif(typecodeMapElement.isMapType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $map_serialized_size(ctx=ctx, typecodeMap=typecodeMapElement, data=data, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeMapElement.isType_e)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $sequence_serialized_size(ctx=ctx, typecodeSeq=typecodeMapElement, data=data, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeMapElement.isType_f)$ - $array_serialized_size(ctx=ctx, typecodeArr=typecodeMapElement, data=data, var=var, loopvar=ctx.nextLoopVarName, dimensions=typecodeMapElement.dimensions)$ -$else$ - $var$ += $typecodeMapElement.scopedname$::getCdrSerializedSize($data$, $var$); -$endif$ ->> - -serializeCasting(typecode) ::= << -$if(typecode.isType_c)$(uint32_t)$elseif(typecode.isBitmaskType)$($typecode.castingType$)$endif$ ->> - -deserializePossibleEnum(typecode, name, preffix) ::= << -$if(typecode.isType_c)$ -{ - uint32_t enum_value = 0; - dcdr \>> enum_value; - $preffix$$name$ = ($typecode.scopedname$)enum_value; -} -$elseif(typecode.isBitmaskType)$ -{ - $typecode.castingType$ bitmask_value = 0; - dcdr \>> bitmask_value; - $preffix$$name$ = ($typecode.scopedname$)bitmask_value; -} - -$elseif(ctx.generateTypesC)$ -$if(typecode.isStringType)$ -{ - std::string aux; - dcdr \>> aux; - free($preffix$$name$); - $preffix$$name$ = (char*)malloc(aux.size() + 1); - strncpy($preffix$$name$, aux.c_str(), aux.size() + 1); -} -$else$ -dcdr \>> $preffix$$name$; -$endif$ -$elseif(typecode.isStringType)$ -$if(typecode.isBounded)$ -{ - std::string aux; - dcdr \>> aux; - $preffix$$name$ = aux.c_str(); -} -$else$ -dcdr \>> $preffix$$name$; -$endif$ -$else$ -dcdr \>> $preffix$$name$; -$endif$ ->> - -cdrIndexName(name, loopvar) ::= <<$name$[$loopvar$]>> - -cdrMemberName(name, preffix) ::= <<$preffix$$name$>> - -member_default_init(ctx, member, loopvar) ::= << -// $member.typecode.idlTypename$ m_$member.name$ -$if(member.typecode.primitive)$$if(member.typecode.isBitmaskType)$m_$member.name$ = $if(member.annotationDefault)$$member.annotationDefaultValue$$else$static_cast<$member.typecode.cppTypename$>(0)$endif$;$else$m_$member.name$ = $if(member.annotationDefault)$$member.annotationDefaultValue$$else$$member.typecode.initialValue$$endif$;$endif$$elseif(member.typecode.isType_f)$$if(member.typecode.contentTypeCode.primitive)$memset(&m_$member.name$, $if(member.annotationDefault)$$member.annotationDefaultValue$$else$0$endif$, $member.typecode.size$ * $member.typecode.contentTypeCode.size$);$elseif(member.typecode.contentTypeCode.isStringType)$$if(ctx.generateTypesC)$$member_array_default_cstring_init(ctx=ctx, name=memberName(member.name), loopvar=ctx.newLoopVarName, dims=member.typecode.dimensions)$$endif$$endif$$endif$>> - -member_array_default_cstring_init(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $member_array_default_cstring_init(ctx=ctx, name=indexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims))$ -}$else$$name$.fill(nullptr);$endif$>> - -indexName(name, loopvar) ::= <<$name$[$loopvar$]>> - -memberName(name) ::= <> diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 816197d5..0283549f 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -38,7 +38,7 @@ $fast_macro_declarations()$ $ctx.directIncludeDependencies : {include | %include "$include$.i"}; separator="\n"$ %{ -#include "$ctx.filename$.h" +#include "$ctx.filename$.hpp" #include %} @@ -66,25 +66,13 @@ namespace swig { $definitions; separator="\n"$ // Include the class interfaces -%include "$ctx.filename$.h" -$if(ctx.cdr_both)$ -%include "$ctx.filename$v1.h" -$endif$ +%include "$ctx.filename$.hpp" // Include the corresponding TopicDataType %include "$ctx.filename$PubSubTypes.i" $"\n"$ >> -module(ctx, parent, module, definition_list) ::= << -$definition_list$ ->> - -definition_list(definitions) ::= << -$definitions; separator="\n"$ - ->> - fast_macro_declarations() ::= << // Macro declarations // Any macro used on the Fast DDS header files will give an error if it is not redefined here @@ -123,13 +111,6 @@ $struct.members : { member | $member_getters(struct_name=struct.scopedname, memb >> -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - template_sequence_name(typecode) ::= <% $if(typecode.isSequenceType)$ $template_sequence_name(typecode.contentTypeCode)$_vector @@ -226,13 +207,6 @@ $union.members : { member | $member_getters(struct_name=union.name, member=membe >> -element_type(ctx, element, type_element, declarator) ::= << - -$type_element$ -$declarator$ - ->> - bitset_type(ctx, parent, bitset, extensions) ::= << //////////////////////////////////////////////////////// // Binding for class $bitset.name$ @@ -248,48 +222,3 @@ bitset_type(ctx, parent, bitset, extensions) ::= << enum_type(ctx, parent, enum) ::= << %traits_penumn(enum $enum.cppTypename$); >> - -// bitmasks are implemented as enums. Therefore, are ported as constants in the target language -bitmask_type(ctx, parent, bitmask) ::= <<>> - -sequence_type(ctx, sequence, type_sequence) ::= << - -$type_sequence$ - ->> - -map_type(ctx, map, key_type, value_type) ::= << - -$key_type$ -$value_type$ - ->> - -string_type(ctx, string) ::= <<>> - -wide_string_type(ctx, wstring) ::= <<>> - -array_declarator(ctx, array, array_type) ::= <<>> - -const_decl(ctx, parent, const, const_type) ::= << - -$const_type$ - ->> - -annotation(ctx, parent, annotation) ::= <<>> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << - -$declarator_type$ -$typedefs_type$ - ->> - -fwd_decl(ctx, parent, type) ::= <<>> - -annotation(ctx, annotation) ::= <<>> - -interface(ctx, parent, interface, export_list) ::= <<>> - -exception(ctx, parent, exception) ::= <<>> diff --git a/src/main/java/com/eprosima/fastcdr/idl/util/CdrVersion.java b/src/main/java/com/eprosima/fastcdr/idl/util/CdrVersion.java deleted file mode 100644 index 9391e3ba..00000000 --- a/src/main/java/com/eprosima/fastcdr/idl/util/CdrVersion.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.eprosima.fastcdr.idl.util; - -public class CdrVersion -{ - public enum Select - { - V1, - V2, - BOTH - } - - public static String v1_str = "v1"; - public static String v2_str = "v2"; - public static String both_str = "both"; -} diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index abaada35..6faf3720 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -15,7 +15,6 @@ package com.eprosima.fastdds; import com.eprosima.fastcdr.idl.generator.TypesGenerator; -import com.eprosima.fastcdr.idl.util.CdrVersion; import com.eprosima.fastdds.exceptions.BadArgumentException; import com.eprosima.fastdds.idl.grammar.Context; import com.eprosima.fastdds.solution.Project; @@ -24,13 +23,13 @@ import com.eprosima.fastdds.util.VSConfiguration; import com.eprosima.idl.generator.manager.TemplateGroup; import com.eprosima.idl.generator.manager.TemplateManager; +import com.eprosima.idl.generator.manager.TemplateST; import com.eprosima.idl.parser.grammar.IDLLexer; import com.eprosima.idl.parser.grammar.IDLParser; import com.eprosima.idl.parser.tree.Annotation; -import com.eprosima.idl.parser.tree.AnnotationDeclaration; -import com.eprosima.idl.parser.tree.AnnotationMember; import com.eprosima.idl.parser.tree.Specification; import com.eprosima.idl.parser.typecode.Kind; +import com.eprosima.idl.parser.typecode.ContainerTypeCode; import com.eprosima.idl.parser.typecode.PrimitiveTypeCode; import com.eprosima.idl.parser.typecode.TypeCode; import com.eprosima.idl.util.Util; @@ -108,9 +107,6 @@ public class fastddsgen // Generates type naming compatible with ROS 2 private boolean m_type_ros2 = false; - // Generate TypeObject files? - private boolean m_type_object_files = false; - // Generate string and sequence types compatible with C? private boolean m_typesc = false; @@ -127,6 +123,9 @@ public class fastddsgen // ignoring the relative dir of the input files private boolean m_flat_output_dir = false; + // Generating internal API + private boolean gen_api_ = false; + // Use to know the programming language public enum LANGUAGE { @@ -136,7 +135,14 @@ public enum LANGUAGE private LANGUAGE m_languageOption = LANGUAGE.CPP; // Default language -> CPP - private CdrVersion.Select cdr_version_ = CdrVersion.Select.V2; + // Specifies whether the type support files should be generated. + private boolean generate_typesupport_ = true; + + // Specifies whether the dependent IDL files should be processed. + private boolean generate_dependencies_ = true; + + // Specifies whether the TypeObject Support files should be generated. + private boolean generate_typeobjectsupport_ = true; /* * ---------------------------------------------------------------------------------------- @@ -166,68 +172,75 @@ public fastddsgen( { m_idlFiles.add(arg); } - else if (arg.equals("-example")) + else if (arg.equals(case_sensitive_arg)) + { + m_case_sensitive = true; + } + else if (arg.equals(output_path_arg)) { if (count < args.length) { - m_exampleOption = args[count++]; - if (!m_platforms.contains(m_exampleOption)) - { - throw new BadArgumentException("Unknown example arch " + m_exampleOption); - } + m_outputDir = Utils.addFileSeparator(args[count++]); } else { - throw new BadArgumentException("No architecture speficied after -example argument"); + throw new BadArgumentException("No URL specified after " + output_path_arg + " argument"); } } - else if (arg.equals("-language")) + else if (arg.equals(default_container_prealloc_size)) { if (count < args.length) { - String languageOption = args[count++]; - - if (languageOption.equalsIgnoreCase("c++")) - { - m_languageOption = LANGUAGE.CPP; - } - else if (languageOption.equalsIgnoreCase("java")) - { - m_languageOption = LANGUAGE.JAVA; - } - else - { - throw new BadArgumentException("Unknown language " + languageOption); - } + ContainerTypeCode.default_unbounded_max_size = args[count++]; } else { - throw new BadArgumentException("No language specified after -language argument"); + throw new BadArgumentException("No value specified after " + default_container_prealloc_size + " argument"); } } - else if (arg.equals("-package")) + else if (arg.equals(default_extensibility_short_arg) || arg.equals(default_extensibility_arg)) { if (count < args.length) { - m_package = args[count++]; + String extensibility = args[count++]; + if (extensibility.equals(Annotation.final_str)) + { + TypeCode.default_extensibility = TypeCode.ExtensibilityKind.FINAL; + } + else if (extensibility.equals(Annotation.appendable_str)) + { + TypeCode.default_extensibility = TypeCode.ExtensibilityKind.APPENDABLE; + } + else if (extensibility.equals(Annotation.mutable_str)) + { + TypeCode.default_extensibility = TypeCode.ExtensibilityKind.MUTABLE; + } + else + { + throw new BadArgumentException("Extensibility value " + extensibility + " is not valid"); + } } else { - throw new BadArgumentException("No package after -package argument"); + throw new BadArgumentException("No extensibility value after " + default_extensibility_arg + " argument"); } } - else if (arg.equals("-ppPath")) + else if (arg.equals(specific_platform_arg)) { if (count < args.length) { - m_ppPath = args[count++]; + m_exampleOption = args[count++]; + if (!m_platforms.contains(m_exampleOption)) + { + throw new BadArgumentException("Unknown example arch " + m_exampleOption); + } } else { - throw new BadArgumentException("No URL specified after -ppPath argument"); + throw new BadArgumentException("No architecture speficied after " + specific_platform_arg + " argument"); } } - else if (arg.equals("-extrastg")) + else if (arg.equals(extra_template_arg)) { if (count + 1 < args.length) { @@ -235,146 +248,141 @@ else if (arg.equals("-extrastg")) } else { - throw new BadArgumentException("Missing arguments for -extrastg"); + throw new BadArgumentException("Missing arguments for " + extra_template_arg); } } - else if (arg.equals("-ppDisable")) + else if (arg.equals(flat_output_directory_arg)) { - m_ppDisable = true; + m_flat_output_dir = true; } - else if (arg.equals("-replace")) + else if (arg.equals(generate_api_arg)) { - m_replace = true; + gen_api_ = true; } - else if (arg.equals("-d")) + else if (arg.equals(help_arg)) + { + printHelp(); + System.exit(0); + } + else if (arg.equals("-help+")) + { + printEnhacedHelp(); + System.exit(0); + } + else if (arg.equals(include_path_arg)) { if (count < args.length) { - m_outputDir = Utils.addFileSeparator(args[count++]); + m_includePaths.add(include_path_arg.concat(args[count++])); } else { - throw new BadArgumentException("No URL specified after -d argument"); + throw new BadArgumentException("No include directory specified after " + include_path_arg + " argument"); } } - else if (arg.equals("-t")) + else if (arg.equals(language_arg)) { if (count < args.length) { - m_tempDir = Utils.addFileSeparator(args[count++]); + String languageOption = args[count++]; + + if (languageOption.equalsIgnoreCase("c++")) + { + m_languageOption = LANGUAGE.CPP; + } + else if (languageOption.equalsIgnoreCase("java")) + { + m_languageOption = LANGUAGE.JAVA; + } + else + { + throw new BadArgumentException("Unknown language " + languageOption); + } } else { - throw new BadArgumentException("No temporary directory specified after -t argument"); + throw new BadArgumentException("No language specified after " + language_arg + " argument"); } } - else if (arg.equals("-version")) + else if (arg.equals(no_typesupport_arg)) { - showVersion(); - System.exit(0); - } - else if (arg.equals("-help")) - { - printHelp(); - System.exit(0); + generate_typesupport_ = false; + generate_typeobjectsupport_ = false; } - else if (arg.equals("-fusion")) + else if (arg.equals(no_dependencies_arg)) { - fusion_ = true; + generate_dependencies_ = false; } - else if (arg.equals("-typeros2")) + else if (arg.equals(no_typeobjectsupport_arg)) { - m_type_ros2 = true; - } - else if (arg.equals("-typeobject")) - { - m_type_object_files = true; - } - else if (arg.equals("-typesc")) - { - m_typesc = true; - } - else if (arg.equals("-python")) - { - m_python = true; + generate_typeobjectsupport_ = false; } - else if (arg.equals("-test")) - { - m_test = true; - } - else if (arg.equals("-flat-output-dir")) - { - m_flat_output_dir = true; - } - else if (arg.equals("-I")) + else if (arg.equals(package_arg)) { if (count < args.length) { - m_includePaths.add("-I".concat(args[count++])); + m_package = args[count++]; } else { - throw new BadArgumentException("No include directory specified after -I argument"); + throw new BadArgumentException("No package after " + package_arg + " argument"); } } - else if (arg.equals("-cs")) + else if (arg.equals(disable_preprocessor_arg)) { - m_case_sensitive = true; + m_ppDisable = true; } - else if (arg.equals("-de") || arg.equals("-default_extensibility")) + else if (arg.equals(preprocessor_path_arg)) { if (count < args.length) { - String extensibility = args[count++]; - if (extensibility.equals(Annotation.final_str)) - { - TypeCode.default_extensibility = TypeCode.ExtensibilityKind.FINAL; - } - else if (extensibility.equals(Annotation.appendable_str)) - { - TypeCode.default_extensibility = TypeCode.ExtensibilityKind.APPENDABLE; - } - else if (extensibility.equals(Annotation.mutable_str)) - { - TypeCode.default_extensibility = TypeCode.ExtensibilityKind.MUTABLE; - } - else - { - throw new BadArgumentException("Extensibility value " + extensibility + " is not valid"); - } + m_ppPath = args[count++]; } else { - throw new BadArgumentException("No extensibility value after -default_extensibility argument"); + throw new BadArgumentException("No URL specified after " + preprocessor_path_arg + " argument"); } } - else if (arg.equals("-cdr")) + else if (arg.equals(python_bindings_arg)) + { + m_python = true; + } + else if (arg.equals(replace_arg)) + { + m_replace = true; + } + else if (arg.equals(temp_dir_arg)) { if (count < args.length) { - String cdr_version_str = args[count++]; - if (cdr_version_str.equals(CdrVersion.v1_str)) - { - cdr_version_ = CdrVersion.Select.V1; - } - else if (cdr_version_str.equals(CdrVersion.v2_str)) - { - cdr_version_ = CdrVersion.Select.V2; - } - else if (cdr_version_str.equals(CdrVersion.both_str)) - { - cdr_version_ = CdrVersion.Select.BOTH; - } - else - { - throw new BadArgumentException("CDR version value " + cdr_version_str + " is not valid"); - } + m_tempDir = Utils.addFileSeparator(args[count++]); } else { - throw new BadArgumentException("No CDR version value after -cdr argument"); + throw new BadArgumentException("No temporary directory specified after "+ temp_dir_arg +" argument"); } } + else if (arg.equals(execute_test_arg)) + { + m_test = true; + } + else if (arg.equals(ros2_names_arg)) + { + m_type_ros2 = true; + } + else if (arg.equals(cnames_arg)) + { + m_typesc = true; + } + else if (arg.equals(version_arg)) + { + showVersion(); + System.exit(0); + } + else if (arg.equals(fusion_arg)) + { + fusion_ = true; + } else // TODO: More options: -rpm, -debug { throw new BadArgumentException("Unknown argument " + arg); @@ -384,7 +392,7 @@ else if (cdr_version_str.equals(CdrVersion.both_str)) if (null != m_exampleOption && m_python) { - throw new BadArgumentException("-example and -python currently are incompatible"); + throw new BadArgumentException(specific_platform_arg + " and " + python_bindings_arg + " currently are incompatible"); } if (m_idlFiles.isEmpty()) @@ -464,14 +472,16 @@ public boolean execute() { solution.addProject(project); } - - for (String include : project.getIDLIncludeFiles()) + if(generate_dependencies_) { - Project inner = process(include, Util.getIDLFileDirectoryOnly(m_idlFiles.get(count)), false); - if (inner != null && !solution.existsProject(inner.getFile())) + for (String include : project.getIDLIncludeFiles()) { - System.out.println("Adding project: " + inner.getFile()); - solution.addProject(inner); + Project inner = process(include, Util.getIDLFileDirectoryOnly(m_idlFiles.get(count)), false); + if (inner != null && !solution.existsProject(inner.getFile())) + { + System.out.println("Adding project: " + inner.getFile()); + solution.addProject(inner); + } } } } @@ -549,51 +559,100 @@ private void showVersion() System.out.println(m_appName + " version " + version); } + + + /* + * ---------------------------------------------------------------------------------------- + * Arguments + */ + private static final String case_sensitive_arg = "-cs"; + private static final String output_path_arg = "-d"; + private static final String default_container_prealloc_size = "-default-container-prealloc-size"; + private static final String default_extensibility_arg = "-default_extensibility"; + private static final String default_extensibility_short_arg = "-de"; + private static final String specific_platform_arg = "-example"; + private static final String extra_template_arg = "-extrastg"; + private static final String flat_output_directory_arg = "-flat-output-dir"; + private static final String fusion_arg = "-fusion"; + private static final String help_arg = "-help"; + private static final String include_path_arg = "-I"; + private static final String language_arg = "-language"; + private static final String no_typesupport_arg = "-no-typesupport"; + private static final String no_typeobjectsupport_arg = "-no-typeobjectsupport"; + private static final String no_dependencies_arg = "-no-dependencies"; + private static final String package_arg = "-package"; + private static final String disable_preprocessor_arg = "-ppDisable"; + private static final String preprocessor_path_arg = "-ppPath"; + private static final String python_bindings_arg = "-python"; + private static final String replace_arg = "-replace"; + private static final String temp_dir_arg = "-t"; + private static final String typeobject_arg = "-typeobject"; + private static final String ros2_names_arg = "-typeros2"; + private static final String cnames_arg = "-typesc"; + private static final String version_arg = "-version"; + + /* + * ---------------------------------------------------------------------------------------- + * Developer Arguments + */ + private static final String generate_api_arg = "-genapi"; + private static final String execute_test_arg = "-test"; + public static void printHelp() { System.out.println(m_appName + " usage:"); System.out.println("\t" + m_appName + " [options] [ ...]"); System.out.println("\twhere the options are:"); - System.out.println("\t\t-help: shows this help"); - System.out.println("\t\t-version: shows the current version of eProsima Fast DDS gen."); - System.out.println( - "\t\t-example : Generates a solution for a specific platform (example: x64Win64VS2019)"); + System.out.println("\t\t" + case_sensitive_arg + ": IDL grammar apply case sensitive matching."); + System.out.println("\t\t" + output_path_arg + " : sets an output directory for generated files."); + System.out.print("\t\t" + default_container_prealloc_size + ": sets the default preallocated size for "); + System.out.println("containers (sequence and maps). Default value: 0"); + System.out.print("\t\t" + default_extensibility_arg + " | " + default_extensibility_short_arg + " : "); + System.out.println("sets the default extensibility for types without the @extensibility annotation."); + System.out.println("\t\t Values:"); + System.out.println("\t\t\t* " + Annotation.final_str); + System.out.println("\t\t\t* " + Annotation.appendable_str + " (default)"); + System.out.println("\t\t\t* " + Annotation.mutable_str); + System.out.print("\t\t" + specific_platform_arg + " : Generates a solution for a specific "); + System.out.println("platform (example: x64Win64VS2019)"); System.out.println("\t\t\tSupported platforms:"); for (int count = 0; count < m_platforms.size(); ++count) { System.out.println("\t\t\t * " + m_platforms.get(count)); } - //System.out.println("\t\t-language : Programming language (default: C++)."); - System.out.println("\t\t-replace: replaces existing generated files."); - System.out.println("\t\t-ppDisable: disables the preprocessor."); - System.out.println("\t\t-ppPath: specifies the preprocessor path."); - System.out.println("\t\t-extrastg