diff --git a/.github/actions/fetch-fastddsgen-repos/action.yml b/.github/actions/fetch-fastddsgen-repos/action.yml index 5a0907e4..0ca25907 100644 --- a/.github/actions/fetch-fastddsgen-repos/action.yml +++ b/.github/actions/fetch-fastddsgen-repos/action.yml @@ -1,13 +1,26 @@ name: 'fetch-fastddsgen-repos' description: 'Fetch Fast DDS dependencies' +inputs: + foonathan-memory-vendor-branch: + description: 'foonathan_memory_vendor branch to be used' + required: false + default: 'master' + fastcdr-branch: + description: 'Fast-CDR branch to be used' + required: false + default: 'master' + fastdds-branch: + description: 'Fast-DDS branch to be used' + required: false + default: 'master' runs: using: "composite" steps: - id: fetch-fastddsgen-repos run: | cd src - git clone https://github.com/eProsima/foonathan_memory_vendor.git - git clone https://github.com/eProsima/Fast-CDR.git - git clone https://github.com/eProsima/Fast-DDS.git + git clone https://github.com/eProsima/foonathan_memory_vendor.git --branch ${{ inputs.foonathan-memory-vendor-branch }} + git clone https://github.com/eProsima/Fast-CDR.git --branch ${{ inputs.fastcdr-branch }} + git clone https://github.com/eProsima/Fast-DDS.git --branch ${{ inputs.fastdds-branch }} cd .. shell: bash diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 29be05c0..c44c36de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,6 +2,19 @@ name: Continuous Integration on: workflow_dispatch: + inputs: + foonathan_memory_vendor_branch: + description: 'foonathan_memory_vendor branch to be used' + required: false + default: 'master' + fastcdr_branch: + description: 'Fast-CDR branch to be used' + required: false + default: 'master' + fastdds_branch: + description: 'Fast-DDS branch to be used' + required: false + default: 'master' push: branches: @@ -19,7 +32,7 @@ jobs: java_version: ['openjdk-11-jdk', 'openjdk-17-jdk', 'openjdk-18-jdk', 'openjdk-19-jdk'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: src/fastddsgen @@ -28,11 +41,15 @@ jobs: java-version: ${{ matrix.java_version }} - uses: ./src/fastddsgen/.github/actions/install-python-packages - uses: ./src/fastddsgen/.github/actions/fetch-fastddsgen-repos + with: + foonathan-memory-vendor-branch: '${{ github.event.inputs.foonathan_memory_vendor_branch }}' + fastcdr-branch: '${{ github.event.inputs.fastcdr_branch }}' + fastdds-branch: '${{ github.event.inputs.fastdds_branch }}' - name: Get minimum supported version of CMake uses: lukka/get-cmake@latest with: - cmakeVersion: 3.16.3 + cmakeVersion: 3.22.6 - name: Use cmake run: cmake --version diff --git a/resources/Custom.stg b/resources/Custom.stg new file mode 100644 index 00000000..261bbfae --- /dev/null +++ b/resources/Custom.stg @@ -0,0 +1,49 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). + +main(ctx, definitions) ::= << + +$definitions; separator="\n"$ + +>> + +module(ctx, parent, module, definition_list) ::= << + +$definition_list$ + +>> + +definition_list(definitions) ::= << + +$definitions; separator="\n"$ + +>> + +annotation(ctx, annotation) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> + +typedef_decl(ctx, parent, typedefs) ::= <<>> + +fwd_decl(ctx, parent, type) ::= <<>> + +struct_type(ctx, parent, struct) ::= <<>> + +union_type(ctx, parent, union, extensions) ::= <<>> + +bitset_type(ctx, parent, bitset, extensions) ::= <<>> + +enum_type(ctx, parent, enum) ::= <<>> + +bitmask_type(ctx, parent, bitmask) ::= <<>> + +interface(ctx, parent, interface, export_list) ::= <<>> + +export_list(exports) ::= <<>> + +exception(ctx, parent, exception) ::= <<>> + +operation(ctx, parent, operation, param_list) ::= <<>> + +param_list(parameters) ::= <<>> + +param(parameter) ::= <<>> diff --git a/src/main/java/com/eprosima/fastcdr/idl/generator/TypesGenerator.java b/src/main/java/com/eprosima/fastcdr/idl/generator/TypesGenerator.java index 43d8d1b8..568c9d0d 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/generator/TypesGenerator.java +++ b/src/main/java/com/eprosima/fastcdr/idl/generator/TypesGenerator.java @@ -26,8 +26,8 @@ import java.io.*; import java.util.ArrayList; import java.util.Map; -import org.antlr.stringtemplate.StringTemplate; -import org.antlr.stringtemplate.StringTemplateGroup; +import org.stringtemplate.v4.ST; +import org.stringtemplate.v4.STGroup; @@ -54,9 +54,9 @@ public boolean generate(Context context, String packagDir, String packag, String if(returnedValue) { // Create gradle build script. - StringTemplateGroup gradlestg = tmanager_.createStringTemplateGroup("gradle"); - StringTemplate gradlest = gradlestg.getInstanceOf("main"); - gradlest.setAttribute("name", libraryName); + STGroup gradlestg = tmanager_.createStringTemplateGroup("gradle"); + ST gradlest = gradlestg.getInstanceOf("main"); + gradlest.add("name", libraryName); if(!writeFile(outputDir_ + "build.gradle", gradlest)) { @@ -99,36 +99,36 @@ else if(definition.isIsInterface()) { Interface ifc = (Interface)definition; - // Create StringTemplate of the interface - StringTemplate ifcst = stg_.getInstanceOf("interface"); - ifcst.setAttribute("ctx", context); - ifcst.setAttribute("parent", ifc.getParent()); - ifcst.setAttribute("interface", ifc); + // Create ST of the interface + ST ifcst = stg_.getInstanceOf("interface"); + ifcst.add("ctx", context); + ifcst.add("parent", ifc.getParent()); + ifcst.add("interface", ifc); - StringTemplate extensionst = null; + ST extensionst = null; String extensionname = null; if(extensions != null && (extensionname = extensions.get("interface")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("ctx", context); - extensionst.setAttribute("parent", ifc.getParent()); - extensionst.setAttribute("interface", ifc); - ifcst.setAttribute("extension", extensionst.toString()); + extensionst.add("ctx", context); + extensionst.add("parent", ifc.getParent()); + extensionst.add("interface", ifc); + ifcst.add("extension", extensionst.render()); } if(processExports(context, ifc.getExports(), ifcst, extensions)) { // Save file. - StringTemplate st = stg_.getInstanceOf("main"); - st.setAttribute("ctx", context); - st.setAttribute("definitions", ifcst.toString()); - st.setAttribute("package", (!packag.isEmpty() ? packag : null)); + ST st = stg_.getInstanceOf("main"); + st.add("ctx", context); + st.add("definitions", ifcst.render()); + st.add("package", (!packag.isEmpty() ? packag : null)); if(extensions != null && (extensionname = extensions.get("main")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("ctx", context); - st.setAttribute("extension", extensionst.toString()); + extensionst.add("ctx", context); + st.add("extension", extensionst.render()); } if(!writeFile(packagDir + ifc.getName() + ".java", st)) @@ -144,24 +144,24 @@ else if(definition.isIsTypeDeclaration()) { TypeDeclaration typedecl = (TypeDeclaration)definition; - // get StringTemplate of the structure - StringTemplate typest = processTypeDeclaration(context, typedecl, extensions); + // get ST of the structure + ST typest = processTypeDeclaration(context, typedecl, extensions); if(typest != null) { // Save file. - StringTemplate st = stg_.getInstanceOf("main"); - st.setAttribute("ctx", context); - st.setAttribute("definitions", typest.toString()); - st.setAttribute("package", (!packag.isEmpty() ? packag : null)); + ST st = stg_.getInstanceOf("main"); + st.add("ctx", context); + st.add("definitions", typest.render()); + st.add("package", (!packag.isEmpty() ? packag : null)); - StringTemplate extensionst = null; + ST extensionst = null; String extensionname = null; if(extensions != null && (extensionname = extensions.get("main")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("ctx", context); - st.setAttribute("extension", extensionst.toString()); + extensionst.add("ctx", context); + st.add("extension", extensionst.render()); } if(!writeFile(packagDir + typedecl.getName() + ".java", st)) @@ -175,21 +175,19 @@ else if(definition.isIsAnnotation()) { AnnotationDeclaration annotation = (AnnotationDeclaration)definition; - // Create StringTemplate of the annotation - StringTemplate ifcst = stg_.getInstanceOf("annotation"); - ifcst.setAttribute("ctx", context); - //ifcst.setAttribute("parent", annotation.getParent()); - ifcst.setAttribute("annotation", annotation); + // Create ST of the annotation + ST ifcst = stg_.getInstanceOf("annotation"); + ifcst.add("ctx", context); + ifcst.add("annotation", annotation); - StringTemplate extensionst = null; + ST extensionst = null; String extensionname = null; if(extensions != null && (extensionname = extensions.get("annotation")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("ctx", context); - //extensionst.setAttribute("parent", annotation.getParent()); - extensionst.setAttribute("annotation", annotation); - ifcst.setAttribute("extension", extensionst.toString()); + extensionst.add("ctx", context); + extensionst.add("annotation", annotation); + ifcst.add("extension", extensionst.render()); } } } @@ -198,7 +196,7 @@ else if(definition.isIsAnnotation()) return true; } - public boolean processExports(Context context, ArrayList exports, StringTemplate ifcst, Map extensions) + public boolean processExports(Context context, ArrayList exports, ST ifcst, Map extensions) { for(Export export : exports) { @@ -206,13 +204,13 @@ public boolean processExports(Context context, ArrayList exports, String { TypeDeclaration typedecl = (TypeDeclaration)export; - // get StringTemplate of the structure - StringTemplate typest = processTypeDeclaration(context, typedecl, extensions); + // get ST of the structure + ST typest = processTypeDeclaration(context, typedecl, extensions); if(typest != null) { // Add type stringtemplate to interface stringtemplate. - ifcst.setAttribute("exports", typest.toString()); + ifcst.add("exports", typest.render()); } } } @@ -220,70 +218,70 @@ public boolean processExports(Context context, ArrayList exports, String return true; } - public StringTemplate processTypeDeclaration(Context context, TypeDeclaration typedecl, Map extensions) + public ST processTypeDeclaration(Context context, TypeDeclaration typedecl, Map extensions) { - StringTemplate typest = null, extensionst = null; + ST typest = null, extensionst = null; String extensionname = null; System.out.println("processTypesDeclaration " + typedecl.getName()); if(typedecl.getTypeCode().getKind() == Kind.KIND_STRUCT) { typest = stg_.getInstanceOf("struct_type"); - typest.setAttribute("struct", typedecl.getTypeCode()); + typest.add("struct", typedecl.getTypeCode()); // Get extension if(extensions != null && (extensionname = extensions.get("struct_type")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("struct", typedecl.getTypeCode()); + extensionst.add("struct", typedecl.getTypeCode()); } } else if(typedecl.getTypeCode().getKind() == Kind.KIND_UNION) { typest = stg_.getInstanceOf("union_type"); - typest.setAttribute("union", typedecl.getTypeCode()); + typest.add("union", typedecl.getTypeCode()); // Get extension if(extensions != null && (extensionname = extensions.get("union_type")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("union", typedecl.getTypeCode()); + extensionst.add("union", typedecl.getTypeCode()); } } else if(typedecl.getTypeCode().getKind() == Kind.KIND_ENUM) { typest = stg_.getInstanceOf("enum_type"); - typest.setAttribute("enum", typedecl.getTypeCode()); + typest.add("enum", typedecl.getTypeCode()); // Get extension if(extensions != null && (extensionname = extensions.get("enum_type")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("enum", typedecl.getTypeCode()); + extensionst.add("enum", typedecl.getTypeCode()); } } else if(typedecl.getTypeCode().getKind() == Kind.KIND_BITSET) { typest = stg_.getInstanceOf("bitset_type"); - typest.setAttribute("bitset", typedecl.getTypeCode()); + typest.add("bitset", typedecl.getTypeCode()); // Get extension if(extensions != null && (extensionname = extensions.get("bitset_type")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("bitset", typedecl.getTypeCode()); + extensionst.add("bitset", typedecl.getTypeCode()); } } else if(typedecl.getTypeCode().getKind() == Kind.KIND_BITMASK) { typest = stg_.getInstanceOf("bitmask_type"); - typest.setAttribute("bitmask", typedecl.getTypeCode()); + typest.add("bitmask", typedecl.getTypeCode()); // Get extension if(extensions != null && (extensionname = extensions.get("bitmask_type")) != null) { extensionst = stg_.getInstanceOf(extensionname); - extensionst.setAttribute("bitmask", typedecl.getTypeCode()); + extensionst.add("bitmask", typedecl.getTypeCode()); } } @@ -292,20 +290,20 @@ else if(typedecl.getTypeCode().getKind() == Kind.KIND_BITMASK) // Generate extension if(extensionst != null) { - extensionst.setAttribute("ctx", context); - extensionst.setAttribute("parent", typedecl.getParent()); - typest.setAttribute("extension", extensionst.toString()); + extensionst.add("ctx", context); + extensionst.add("parent", typedecl.getParent()); + typest.add("extension", extensionst.render()); } // Main stringtemplate - typest.setAttribute("ctx", context); - typest.setAttribute("parent", typedecl.getParent()); + typest.add("ctx", context); + typest.add("parent", typedecl.getParent()); } return typest; } - private boolean writeFile(String file, StringTemplate template) + private boolean writeFile(String file, ST template) { boolean returnedValue = false; @@ -316,7 +314,7 @@ private boolean writeFile(String file, StringTemplate template) if(!handle.exists() || replace_) { FileWriter fw = new FileWriter(file); - String data = template.toString(); + String data = template.render(); fw.write(data, 0, data.length()); fw.close(); } @@ -336,7 +334,7 @@ private boolean writeFile(String file, StringTemplate template) } private TemplateManager tmanager_ = null; - private StringTemplateGroup stg_ = null; + private STGroup stg_ = null; private String outputDir_ = null; private boolean replace_ = false; } 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 eaf5d8ab..5b106698 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg @@ -14,456 +14,16 @@ group FastCdrCommon; -paramRetType(typecode) ::= << -$if(typecode)$ -$typecode.cppTypename$ -$else$ -void -$endif$ ->> - -paramTypeByValue(typecode) ::= << -$if(typecode.primitive)$ -$typecode.cppTypename$ -$else$ -const $typecode.cppTypename$& -$endif$ ->> - -paramTypeByRef(typecode) ::= << -$typecode.cppTypename$& ->> - -paramDeclarations(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param | /*$param.comment$*/ $if(param.output)$$paramTypeByRef(typecode=param.typecode)$$else$$paramTypeByValue(typecode=param.typecode)$$endif$ $param.name$}; separator=", "$ ->> - -paramDeclarationsByValue(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param | /*$param.comment$*/ $paramTypeByValue(typecode=param.typecode)$ $param.name$}; separator=", "$ ->> - -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()); -$elseif(object.typecode.contentTypeCode.isBitmaskType)$ -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.isBitmaskType)$ -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.isBitmaskType)$ - scdr << static_cast(pair.first); -$elseif(object.typecode.keyTypeCode.isType_d)$ - scdr << pair.first$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$; -$elseif(object.typecode.keyTypeCode.isStringType)$ - scdr << pair.first$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$; -$elseif(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.isBitmaskType)$ - scdr << static_cast(pair.second); -$elseif(object.typecode.valueTypeCode.isType_d)$ - scdr << pair.second$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(object.typecode.valueTypeCode.isStringType)$ - scdr << pair.first$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(object.typecode.valueTypeCode.isWStringType)$ - scdr << pair.first$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$else$ - scdr << pair.second; -$endif$ -} ->> - -string_collection_serialization(ctx, object, preffix, array) ::= << -$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_serialization(ctx, object) ::= << +scdr << eprosima::fastcdr::MemberId($object.id$) << $object.name$(); >> bitfield_serialization(ctx, object) ::= <<$if(member.name)$ scdr << static_cast<$member.spec.cppTypename$>($member.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()); -$elseif(object.typecode.contentTypeCode.isBitmaskType)$ -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.isBitmaskType)$ -{ - $object.typecode.contentTypeCode.castingType$ seq_length = 0; - dcdr \>> seq_length; - $preffix$$object.name$.resize(seq_length); - dcdr.deserializeArray(reinterpret_cast<$object.typecode.contentTypeCode.castingType$*>($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)$ -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, object=object, preffix=preffix)$ - -$object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$elseif(object.typecode.valueTypeCode.isBitmaskType)$ -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, object=object, preffix=preffix)$ - -$object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$elseif(object.typecode.valueTypeCode.isStringType)$ -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, object=object, preffix=preffix)$ - - $object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$elseif(object.typecode.valueTypeCode.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, object=object, preffix=preffix)$ - - $object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$elseif(object.typecode.keyTypeCode.isStringType)$ -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, object=object, preffix=preffix)$ - - $object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$elseif(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, object=object, preffix=preffix)$ - - $object_map_value_deserialization(ctx=ctx, object=object, preffix=preffix)$ -} -$else$ - dcdr \>> $preffix$$object.name$; -$endif$ ->> - - -object_map_key_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.keyTypeCode.isStringType)$ - std::string key; - $if(object.typecode.keyTypeCode.isBounded)$ - std::string aux; - dcdr \>> aux; - key = aux.c_str(); - $else$ - dcdr \>> key; - $endif$ -$elseif(object.typecode.keyTypeCode.isWStringType)$ - std::wstring key; - $if(object.typecode.keyTypeCode.isBounded)$ - std::wstring aux; - dcdr \>> aux; - key = aux.c_str(); - $else$ - dcdr \>> key; - $endif$ -$else$ - $object.typecode.keyTypeCode.cppTypename$ key; - dcdr \>> key; -$endif$ ->> - -object_map_value_deserialization(ctx, object, preffix) ::= << -$if(object.typecode.valueTypeCode.isStringType)$ - std::string value; - dcdr \>> value; - $preffix$$object.name$[key$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$] = value$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(object.typecode.valueTypeCode.isWStringType)$ - std::wstring value; - dcdr \>> value; - $preffix$$object.name$[key$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$] = value$if(object.typecode.valueTypeCode.isStringType)$.c_str()$endif$; -$elseif(object.typecode.valueTypeCode.isType_c)$ - uint32_t value; - dcdr \>> value; - $preffix$$object.name$[key$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$] = static_cast<$object.typecode.valueTypeCode.cppTypename$>(value); -$elseif(object.typecode.valueTypeCode.isBitmaskType)$ - uint32_t value; - dcdr \>> value; - $preffix$$object.name$[key$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$] = static_cast<$object.typecode.valueTypeCode.cppTypename$>(value); -$else$ - $object.typecode.valueTypeCode.cppTypename$ value; - dcdr \>> value; - $preffix$$object.name$[key$if(object.typecode.keyTypeCode.isStringType)$.c_str()$endif$] = value$if(object.typecode.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$$if(object.typecode.forwarded)$->$else$.$endif$resize(sequence_size); -$endif$ - for (auto& item : $if(object.typecode.forwarded)$*$endif$$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$ +object_deserialization(ctx, object) ::= << +dcdr \>> $object.name$(); >> bitfield_deserialization(ctx, object) ::= <<$if(member.name)$$member.spec.cppTypename$ aux_$member.name$; @@ -471,353 +31,23 @@ dcdr \>> aux_$member.name$; $member.name$(aux_$member.name$);$endif$ >> -// TODO Todos los tipos. MEJORAR. size of 1 no deberia generar alignment. -max_serialized_size(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$; - -$elseif(typecode.isWStringType)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + ($typecode.maxsize$) * 4; // 32 bits -$elseif(typecode.isType_d)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $typecode.maxsize$ + 1; -$elseif(typecode.isMapType)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$map_max_serialized_size(ctx=ctx, typecodeMap=typecode, var=var, loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isType_e)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$sequence_max_serialized_size(ctx=ctx, typecodeSeq=typecode, var=var, loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isType_f)$ -$array_max_serialized_size(ctx=ctx, typecodeArr=typecode, var=var, loopvar=ctx.newLoopVarName)$ -$else$ -$var$ += $typecode.scopedname$::getMaxCdrSerializedSize($var$); -$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)$ -$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)$ -$else$ -$var$ += $object.typecode.scopedname$::getCdrSerializedSize($data$.$object.name$(), $var$); -$endif$ - ->> - -sequence_max_serialized_size(ctx, typecodeSeq, var, loopvar) ::= << -$if(typecodeSeq.contentTypeCode.primitive)$ -$var$ += ($if(typecodeSeq.unbound)$100$else$$typecodeSeq.maxsize$$endif$ * $typecodeSeq.contentTypeCode.size$)$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecodeSeq.contentTypeCode.size$)$endif$; - -$elseif(typecodeSeq.contentTypeCode.isType_d)$ - -for(size_t $loopvar$ = 0; $loopvar$ < $if(typecodeSeq.unbound)$100$else$$typecodeSeq.maxsize$$endif$; ++$loopvar$) -{ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $typecodeSeq.contentTypeCode.maxsize$ + 1; -} -$else$ - -for(size_t $loopvar$ = 0; $loopvar$ < $if(typecodeSeq.unbound)$100$else$$typecodeSeq.maxsize$$endif$; ++$loopvar$) -{ -$if(typecodeSeq.contentTypeCode.isMapType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $map_max_serialized_size(ctx=ctx, typecodeMap=typecodeSeq.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeSeq.contentTypeCode.isType_e)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $sequence_max_serialized_size(ctx=ctx, typecodeSeq=typecodeSeq.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeSeq.contentTypeCode.isType_f)$ -$array_max_serialized_size(ctx=ctx, typecodeArr=typecodeSeq.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$else$ - $var$ += $typecodeSeq.contentTypeCode.scopedname$::getMaxCdrSerializedSize($var$); -$endif$ -} -$endif$ ->> - -sequence_serialized_size(ctx, typecodeSeq, data, var, loopvar) ::= << -$if(typecodeSeq.contentTypeCode.primitive)$ -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_max_serialized_size(ctx, typecodeArr, var, loopvar) ::= << -$if(typecodeArr.contentTypeCode.primitive)$ -$var$ += ($typecodeArr.size$ * $typecodeArr.contentTypeCode.size$)$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, $typecodeArr.contentTypeCode.size$)$endif$; - -$elseif(typecodeArr.contentTypeCode.isType_d)$ - -for(size_t $loopvar$ = 0; $loopvar$ < $typecodeArr.size$; ++$loopvar$) -{ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $typecodeArr.contentTypeCode.maxsize$ + 1; -} -$else$ - -for(size_t $loopvar$ = 0; $loopvar$ < $typecodeArr.size$; ++$loopvar$) -{ -$if(typecodeArr.contentTypeCode.isMapType)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - $map_max_serialized_size(ctx=ctx, typecodeMap=typecodeArr.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeArr.contentTypeCode.isType_e)$ - $var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - - $sequence_max_serialized_size(ctx=ctx, typecodeSeq=typecodeArr.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeArr.contentTypeCode.isType_f)$ -$array_max_serialized_size(ctx=ctx, typecodeArr=typecodeArr.contentTypeCode, var=var, loopvar=ctx.nextLoopVarName)$ -$else$ - $var$ += $typecodeArr.contentTypeCode.scopedname$::getMaxCdrSerializedSize($var$); -$endif$ -} -$endif$ ->> - -array_serialized_size(ctx, typecodeArr, data, var, loopvar, dimensions) ::= << -$if(typecodeArr.contentTypeCode.primitive)$ -$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_max_serialized_size(ctx, typecodeMap, var, loopvar) ::= << -for(size_t $loopvar$ = 0; $loopvar$ < $typecodeMap.maxsize$; ++$loopvar$) -{ - $map_max_serialized_size_element(ctx=ctx, typecodeMapElement=typecodeMap.keyTypeCode, var=var, loopvar=loopvar)$ - - $map_max_serialized_size_element(ctx=ctx, typecodeMapElement=typecodeMap.valueTypeCode, var=var, loopvar=loopvar)$ -} -$endif$ ->> - -map_max_serialized_size_element(ctx, typecodeMapElement, var, loopvar) ::= <<รง -$if(typecodeMapElement.primitive)$ -$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$ + $typecodeMapElement.maxsize$ * 4; - -$elseif(typecodeMapElement.isType_d)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$ + $typecodeMapElement.maxsize$ + 1; - -$elseif(typecodeMapElement.isMapType)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$map_max_serialized_size(ctx=ctx, typecodeMap=typecodeMapElement, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeMapElement.isType_e)$ -$var$ += 4$if(ctx.cdr)$ + eprosima::fastcdr::Cdr::alignment($var$, 4)$endif$; - -$sequence_max_serialized_size(ctx=ctx, typecodeSeq=typecodeMapElement, var=var, loopvar=ctx.nextLoopVarName)$ -$elseif(typecodeMapElement.isType_f)$ -$array_max_serialized_size(ctx=ctx, typecodeArr=typecodeMapElement, var=var, loopvar=ctx.nextLoopVarName)$ -$else$ -$var$ += $typecodeMapElement.scopedname$::getMaxCdrSerializedSize($var$); -$endif$ ->> - -map_serialized_size(ctx, typecodeMap, data, var, loopvar) ::= << -for(auto $loopvar$ : $data$) -{ - (void)$loopvar$; +const_decl(ctx, parent, const) ::= <<>> - $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)$ -} -$endif$ +object_cpptypename(object) ::= << +$if(object.annotationOptional)$eprosima::fastcdr::optional<$endif$$object.typecode.cppTypename$$if(object.typecode.forwarded)$*$endif$$if(object.annotationOptional)$>$endif$ >> -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)$ - $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$ +member_type_declaration(member) ::= << +$if(member.annotationOptional)$eprosima::fastcdr::optional<$endif$$member.typecode.cppTypename$$if(member.annotationOptional)$>$endif$ >> -serializeCasting(typecode) ::= << -$if(typecode.isType_c)$(uint32_t)$elseif(typecode.isBitmaskType)$($typecode.castingType$)$elseif(typecode.forwarded)$*$endif$ ->> +member_destructor(ctx, member) ::= <<$if(member.typecode.forwarded)$delete m_$member.name$;$elseif(ctx.generateTypesC)$$if(member.typecode.isStringType)$free(m_$member.name$); +m_$member.name$ = nullptr;$elseif(member.typecode.isType_f)$$if(member.typecode.contentTypeCode.isStringType)$$member_array_cstring_destructor(ctx=ctx, name=memberName(member.name), loopvar=ctx.newLoopVarName, dims=member.typecode.dimensions)$$endif$$endif$$endif$>> -deserializePossibleEnum(typecode, name, preffix) ::= << -$if(typecode.isType_c)$ +member_array_cstring_destructor(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) { - 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)$ + $member_array_cstring_destructor(ctx=ctx, name=indexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims))$ +}$else$for (char* str : $name$) { - 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 \>> $if(typecode.forwarded)$*$endif$$preffix$$name$; -$endif$ -$elseif(typecode.isStringType)$ -$if(typecode.isBounded)$ -{ - std::string aux; - dcdr \>> aux; - $if(typecode.forwarded)$*$endif$$preffix$$name$ = aux.c_str(); -} -$else$ -dcdr \>> $if(typecode.forwarded)$*$endif$$preffix$$name$; -$endif$ -$else$ -dcdr \>> $if(typecode.forwarded)$*$endif$$preffix$$name$; -$endif$ - -$else$ -dcdr \>> $if(typecode.forwarded)$*$endif$$preffix$$name$; -$endif$ ->> - -cdrIndexName(name, loopvar) ::= <<$name$[$loopvar$]>> - -cdrMemberName(name, preffix) ::= <<$preffix$$name$>> - -const_decl(ctx, parent, const) ::= <<>> - -sizeFunction ::= [ - "type_e":"size()", - "type_d":"length()", - "type_15":"length()", - default: // not basic type. -] + free(str); +}$endif$>> 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 e5c17510..abbaf1ab 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -14,26 +14,31 @@ group TypesHeader; +import "com/eprosima/fastdds/idl/templates/eprosima.stg" +import "FastCdrCommon.stg" + main(ctx, definitions) ::= << -$fileHeader(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, ".h"], description=["This header file contains the declaration of the described types in the IDL file."])$ #ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ #define _FAST_DDS_GENERATED_$ctx.headerGuardName$_H_ +#include +#include +#include +#include +#include +#include + +#include +#include + $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 #if defined(_WIN32) #if defined(EPROSIMA_USER_DLL_EXPORT) @@ -63,6 +68,9 @@ $if(ctx.cdr)$ namespace eprosima { namespace fastcdr { class Cdr; +$if(ctx.cdr)$ +class CdrSizeCalculator; +$endif$ } // namespace fastcdr } // namespace eprosima @@ -78,8 +86,8 @@ class FastCdr; $endif$ $if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { -$sequences_definition(it.value)$ +$ctx.typeCodesToDefine : { type | +$sequences_definition(type.value)$ }; separator="\n"$ $endif$ @@ -103,11 +111,11 @@ $definitions; separator="\n"$ annotation(ctx, annotation) ::= << namespace $annotation.name$ { - $annotation.enums : {$enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ + $annotation.enums : { enum | $enum_type(ctx=ctx, parent=annotation, enum=enum)$}; separator="\n"$ - $annotation.typeDefs : {$typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ + $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef)$}; separator="\n"$ - $annotation.constDecls : {$const_decl(ctx=ctx, parent=annotation, const=it)$}; separator="\n"$ + $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const)$}; separator="\n"$ } // namespace $annotation.name$ >> @@ -129,73 +137,9 @@ 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; +exception(ctx, parent, exception) ::= <<>> -$endif$ ->> +operation(ctx, parent, operation, param_list) ::= <<>> param_list(parameters) ::= <<>> @@ -223,7 +167,7 @@ struct_type(ctx, parent, struct, extensions) ::= << * @brief This class represents the structure $struct.name$ defined by the user in the IDL file. * @ingroup $ctx.trimfilename$ */ -class $struct.name$$if(struct.inheritances)$ : public $struct.inheritances : {$public_struct_inheritances(it)$}; separator=", "$ $endif$ +class $struct.name$$if(struct.inheritances)$ : public $struct.inheritances : { inheritance | $public_struct_inheritances(inheritance)$}; separator=", "$ $endif$ { public: @@ -279,28 +223,12 @@ public: eProsima_user_DllExport bool operator !=( const $struct.name$& x) const; - $struct.members:{$public_member_declaration(it)$}; 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)$ - + $struct.members:{ member | $public_member_declaration(member)$}; separator="\n"$ $serialization_functions(struct)$ - - $extensions : {$it$}; separator="\n"$ - + $extensions : { extension | $extension$}; separator="\n"$ private: - $struct.members:{$private_member_declaration(member=it)$}; separator="\n"$ + $struct.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ }; >> @@ -386,19 +314,14 @@ public: */ eProsima_user_DllExport $union.discriminator.cppTypename$& _d(); - $union.members:{$public_unionmember_declaration(it)$}; separator="\n"$ - - $size_functions(union)$ - + $union.members:{ member | $public_unionmember_declaration(member)$}; separator="\n"$ $serialization_functions(union)$ - - $extensions : {$it$}; separator="\n"$ - + $extensions : {extension | $extension$}; separator="\n"$ private: - $private_declaration(typecode=union.discriminator, name="_d")$ + $union.discriminator.cppTypename$ m__d; - $union.members:{$private_member_declaration(member=it)$}; separator="\n"$ + $union.members:{ member | $private_member_declaration(member=member)$}; separator="\n"$ }; >> @@ -407,7 +330,7 @@ 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.parents)$ : public $bitset.parents : {$public_bitset_inheritances(it)$}; separator=", "$ $endif$ +class $bitset.name$$if(bitset.parents)$ : public $bitset.parents : { bitset | $public_bitset_inheritances(bitset)$}; separator=", "$ $endif$ { public: @@ -463,13 +386,15 @@ public: eProsima_user_DllExport bool operator !=( const $bitset.name$& x) const; - $bitset.bitfields:{$public_bitfield_declaration(it)$}; separator="\n"$ + $bitset.bitfields:{ bitset | $public_bitfield_declaration(bitset)$}; separator="\n"$ + + eProsima_user_DllExport std::bitset<$bitset.fullBitSize$> bitset() const; - $size_functions(bitset)$ + eProsima_user_DllExport void bitset(const std::bitset<$bitset.fullBitSize$>&); $serialization_functions(bitset)$ - $extensions : {$it$}; separator="\n"$ + $extensions : { extension | $extension$}; separator="\n"$ private: @@ -484,7 +409,7 @@ enum_type(ctx, parent, enum) ::= << */ enum $enum.name$ : uint32_t { - $enum.members:{$it.name$}; separator=",\n"$ + $enum.members:{ member | $member.name$}; separator=",\n"$ }; >> @@ -495,10 +420,15 @@ bitmask_type(ctx, parent, bitmask) ::= << */ enum $bitmask.name$$bitmask.boundType$ { - $bitmask.members:{$it.name$ = 0x01ull << $it.position$}; separator=",\n"$ + $bitmask.members:{ member | $member.name$ = 0x01ull << $member.position$}; separator=",\n"$ }; >> +fwd_decl(ctx, parent, type) ::= << +class $type.name$; + +>> + /***** Utils *****/ public_struct_inheritances(parent) ::= <<$parent.scopedname$>> @@ -506,7 +436,9 @@ public_struct_inheritances(parent) ::= <<$parent.scopedname$>> public_bitset_inheritances(parent) ::= <<$parent.scopedname$>> public_member_declaration(member) ::= << -$if(member.typecode.primitive)$ +$if(member.annotationOptional)$ +$public_member_common_declaration(member=member)$ +$elseif(member.typecode.primitive)$ $public_member_primitive_declaration(member=member)$ $elseif(ctx.generateTypesC)$ $if(member.typecode.isStringType)$ @@ -525,19 +457,19 @@ public_member_primitive_declaration(member) ::= << * @param _$member.name$ New value for member $member.name$ */ eProsima_user_DllExport void $member.name$( - $member.typecode.cppTypename$ _$member.name$); + $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 $member.typecode.cppTypename$ $member.name$() const; +eProsima_user_DllExport $member_type_declaration(member)$ $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$(); +eProsima_user_DllExport $member_type_declaration(member)$& $member.name$(); >> public_member_cstring_declaration(member) ::= << @@ -546,13 +478,13 @@ public_member_cstring_declaration(member) ::= << * @param _$member.name$ New value for member $member.name$ */ eProsima_user_DllExport void $member.name$( - const $member.typecode.cppTypename$ _$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.typecode.cppTypename$ $member.name$() const; +eProsima_user_DllExport const $member_type_declaration(member)$ $member.name$() const; >> public_member_common_declaration(member) ::= << @@ -561,26 +493,26 @@ 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.typecode.cppTypename$& _$member.name$); + const $member_type_declaration(member)$& _$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$); + $member_type_declaration(member)$&& _$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; +eProsima_user_DllExport const $member_type_declaration(member)$& $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$(); +eProsima_user_DllExport $member_type_declaration(member)$& $member.name$(); >> public_bitfield_declaration(member) ::= << @@ -601,7 +533,7 @@ $endif$ >> private_member_declaration(member) ::= << -$private_declaration(typecode=member.typecode, name=member.name)$ +$object_cpptypename(object=member)$ m_$member.name$$member_default_init(member)$; >> public_unionmember_declaration(member) ::= << @@ -687,61 +619,19 @@ eProsima_user_DllExport const $member.typecode.cppTypename$& $member.name$() con eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); >> -private_declaration(typecode, name) ::= << -$typecode.cppTypename$$if(typecode.forwarded)$*$endif$ 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); - +member_default_init(member) ::= <% +$if(!member.typecode.forwarded)$ +$if(member.annotationDefault)$ + {$member.annotationDefaultValue$} +$elseif(!member.annotationOptional)$ +$if(member.typecode.initialValue)$ + {$member.typecode.initialValue$} $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$ +$endif$ +%> +serialization_functions(type) ::= << $if(ctx.fastcdr)$ /*! * @brief This function serializes an object using FastCDR serialization. @@ -762,14 +652,14 @@ $endif$ sequences_definition(typecode) ::= << $if(typecode.contentTypeCode.isStructType)$ -$typecode.contentTypeCode.namespaces : { namespace $it$ \{ }; separator="\n"$ +$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ class $typecode.contentTypeCode.name$; -$typecode.contentTypeCode.namespaces : { \} }; separator="\n"$ +$reverse(typecode.contentTypeCode.namespaces) : { ns | \} // $ns$}; separator="\n"$ $endif$ $if(typecode.contentTypeCode.isUnionType)$ -$typecode.contentTypeCode.namespaces : { namespace $it$ \{ }; separator="\n"$ +$typecode.contentTypeCode.namespaces : { ns | namespace $ns$ \{ }; separator="\n"$ class $typecode.contentTypeCode.name$; -$typecode.contentTypeCode.namespaces : { \} }; separator="\n"$ +$reverse(typecode.contentTypeCode.namespaces) : { ns | \} // $ns$}; separator="\n"$ $endif$ $sequences_definition_impl(typecode=typecode, typename=typecode.cppTypename)$ @@ -831,16 +721,6 @@ public: 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; diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg index ffb02524..da32acdd 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg @@ -14,8 +14,11 @@ group TypesSource; +import "com/eprosima/fastdds/idl/templates/eprosima.stg" +import "FastCdrCommon.stg" + main(ctx, definitions, extensions) ::= << -$fileHeader(file=[ctx.filename, ".cpp"], description=["This source file contains the definition of the described types in the IDL file."])$ +$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 @@ -44,19 +47,17 @@ using namespace eprosima::fastcdr::exception; #include -$if(ctx.anyCdr)$ -$ctx.types:{ type | $if(type.typeCode.isStructType)$#define $type.typeCode.cScopedname$_max_cdr_typesize $type.typeCode.maxSerializedSize$ULL;$endif$}; separator="\n"$ -$endif$ - -$extensions : {$it$}; separator="\n"$ +$extensions : { extension | $extension$}; separator="\n"$ $if(ctx.generateTypesC)$ -$ctx.typeCodesToDefine : { -$sequences_definition(it.value)$ -}; separator="\n"$ +$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$ >> module(ctx, parent, module, definition_list) ::= << @@ -79,101 +80,7 @@ $exports; separator="\n"$ >> -exception(ctx, parent, exception) ::= << -$if(ctx.printexception)$ -$exception.scopedname$::$exception.name$() - : UserException() -{ - $exception.members : { member |$member_default_init(ctx=ctx, member=member, loopvar=ctx.newLoopVarName)$}; separator="\n"$ -} - -$exception.scopedname$::$exception.name$( - const $exception.name$& x) - : UserException(x) -{ - $exception.members : { member |$member_copy(ctx=ctx, member=member)$}; separator="\n"$ -} - -$exception.scopedname$::$exception.name$( - $exception.name$&& x) - : UserException(std::move(x)) -{ - $exception.members : { member |$member_move(member=member)$}; separator="\n"$ -} - -$exception.scopedname$& $exception.scopedname$::operator =( - const $exception.name$& x) -{ - UserException::operator =(x); - $exception.members : { member |$member_copy(ctx=ctx, member=member)$}; separator="\n"$ - return *this; -} - -$exception.scopedname$& $exception.scopedname$::operator =( - $exception.name$&& x) -{ - UserException::operator =(std::move(x)); - $exception.members : { member |$member_move(member=member)$}; separator="\n"$ - return *this; -} - -$exception.scopedname$::~$exception.name$() throw() -{ - $exception.members : { member |$varDel(variable=member)$}; separator="\n"$ -} - -void $exception.scopedname$::raise() const -{ - throw *this; -} - -$if(ctx.anyCdr)$ -size_t $exception.scopedname$::getCdrSerializedSize( - const $exception.scopedname$& data, - size_t current_alignment) -{ - (void)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.scopedname$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - $exception.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator=""$ -} - -void $exception.scopedname$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $exception.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$ -} - -$endif$ - -$if(ctx.fastcdr)$ -void $exception.scopedname$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - $exception.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator=""$ -} - -void $exception.scopedname$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) -{ - $exception.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$ -} - -$endif$ - -$endif$ ->> +exception(ctx, parent, exception) ::= <<>> operation(ctx, parent, operation, param_list) ::= <<>> @@ -191,9 +98,10 @@ const $const.typeCode.cppTypename$ $const.parent.scopedname$::$const.name$ = $co $endif$ $endif$ $endif$ -$endif$ >> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= << $typedefs : { typedef | @@ -206,8 +114,11 @@ $endif$ >> struct_type(ctx, parent, struct, extensions) ::= << -$struct.scopedname$::$struct.name$()$if(struct.inheritances)$ - : $struct.inheritances : {$struct_inherit_default_init(it)$}; separator=",\n"$ $endif$ +$struct.scopedname$::$struct.name$() + $if(struct.inheritances)$ + : $struct.inheritances : { inheritance | $struct_inherit_default_init(inheritance)$ }; separator=",\n"$ + $endif$ + { $struct.members:{ member |$member_default_init(ctx=ctx, member=member, loopvar=ctx.newLoopVarName)$}; separator="\n"$ @@ -223,25 +134,31 @@ $struct.scopedname$::~$struct.name$() } $struct.scopedname$::$struct.name$( - const $struct.name$& x)$if(struct.inheritances)$ - : $struct.inheritances : {$struct_inherit_copy_init(it)$}; separator=",\n"$ $endif$ + const $struct.name$& x) + $if(struct.inheritances)$ + : $struct.inheritances : { inheritance | $struct_inherit_copy_init(inheritance)$ }; separator=",\n"$ + $endif$ + { - $struct.members:{$member_copy(ctx=ctx, member=it)$}; separator="\n"$ + $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ } $struct.scopedname$::$struct.name$( - $struct.name$&& x) noexcept $if(struct.inheritances)$ - : $struct.inheritances : {$struct_inherit_move_init(it)$}; separator=",\n"$ $endif$ + $struct.name$&& x) noexcept + $if(struct.inheritances)$ + : $struct.inheritances : { inheritance | $struct_inherit_move_init(inheritance)$}; separator=",\n"$ + $endif$ + { - $struct.members:{$member_move(member=it)$}; separator="\n"$ + $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ } $struct.scopedname$& $struct.scopedname$::operator =( const $struct.name$& x) { - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::operator =(x);}; separator="\n"$ $endif$ + $if(struct.inheritances)$$struct.inheritances : { inheritance | $inheritance.scopedname$::operator =(x);}; separator="\n"$$endif$ - $struct.members:{$member_copy(ctx=ctx, member=it)$}; separator="\n"$ + $struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$ return *this; } @@ -249,9 +166,9 @@ $struct.scopedname$& $struct.scopedname$::operator =( $struct.scopedname$& $struct.scopedname$::operator =( $struct.name$&& x) noexcept { - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::operator =(std::move(x));}; separator="\n"$ $endif$ + $if(struct.inheritances)$$struct.inheritances : { inheritance | $inheritance.scopedname$::operator =(std::move(x));}; separator="\n"$$endif$ - $struct.members:{$member_move(member=it)$}; separator="\n"$ + $struct.members:{ member | $member_move(member=member)$}; separator="\n"$ return *this; } @@ -259,9 +176,13 @@ $struct.scopedname$& $struct.scopedname$::operator =( bool $struct.scopedname$::operator ==( const $struct.name$& x) const { - $if(struct.inheritances)$ $struct.inheritances : { if ($it.scopedname$::operator !=(x)) return false;}; separator="\n"$ $endif$ + $if(struct.inheritances)$$struct.inheritances : { inheritance | if ($inheritance.scopedname$::operator !=(x)) + { + return false; + \} + }; separator="\n"$$endif$ - return $if(struct.members)$($struct.members:{m_$it.name$ == x.m_$it.name$}; separator=" && "$)$else$true$endif$; + return $if(struct.members)$($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$)$else$true$endif$; } bool $struct.scopedname$::operator !=( @@ -270,76 +191,30 @@ bool $struct.scopedname$::operator !=( return !(*this == x); } -$if(ctx.anyCdr)$ -size_t $struct.scopedname$::getMaxCdrSerializedSize( - size_t current_alignment) -{ - static_cast(current_alignment); - return $struct.cScopedname$_max_cdr_typesize; -} - -size_t $struct.scopedname$::getCdrSerializedSize( - const $struct.scopedname$& data, - size_t current_alignment) -{ - (void)data; - size_t initial_alignment = current_alignment; - - $if(struct.inheritances)$ $struct.inheritances : {current_alignment += $it.scopedname$::getCdrSerializedSize(data, current_alignment);}; separator="\n"$ $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.scopedname$::serialize( - eprosima::fastcdr::Cdr& scdr) const -{ - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator=""$ -} - -void $struct.scopedname$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ - - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator="\n"$ -} - -$endif$ - $if(ctx.fastcdr)$ void $struct.scopedname$::serialize( eprosima::fastcdr::FastCdr &scdr) const { - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ + $if(struct.inheritances)$ $struct.inheritances : { inheritance | $inheritance.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator=""$ + $struct.members : { member |$if(!member.annotationNonSerialized)$$object_serialization(ctx=ctx, object=member)$$endif$}; separator=""$ } void $struct.scopedname$::deserialize( eprosima::fastcdr::FastCdr& dcdr) { - $if(struct.inheritances)$ $struct.inheritances : {$it.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ + $if(struct.inheritances)$ $struct.inheritances : { inheritance | $inheritance.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ - $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member, preffix="m_")$$endif$}; separator="\n"$ + $struct.members : { member |$if(!member.annotationNonSerialized)$$object_deserialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ } - $endif$ - -$struct.members:{$public_member_declaration(class=struct.scopedname, member=it)$}; separator="\n"$ - -$extensions : {$it$}; separator="\n"$ +$struct.members:{ member | $public_member_declaration(class=struct.scopedname, member=member)$}; separator="\n"$ +$extensions : { extension | $extension$}; separator="\n"$ >> bitset_type(ctx, parent, bitset) ::= << $bitset.scopedname$::$bitset.name$()$if(bitset.parents)$ - : $bitset.parents : {$bitset_inherit_default_init(it)$}; separator=",\n"$ $endif$ + : $bitset.parents : { bitset | $bitset_inherit_default_init(bitset)$}; separator=",\n"$ $endif$ { $if(ctx.generateTypeObject)$ // Just to register all known types @@ -353,14 +228,14 @@ $bitset.scopedname$::~$bitset.name$() $bitset.scopedname$::$bitset.name$( const $bitset.name$& x)$if(bitset.parents)$ - : $bitset.parents : {$bitset_inherit_copy_init(it)$}; separator=",\n"$ $endif$ + : $bitset.parents : { bitset | $bitset_inherit_copy_init(bitset)$}; separator=",\n"$ $endif$ { m_bitset = x.m_bitset; } $bitset.scopedname$::$bitset.name$( $bitset.name$&& x) noexcept $if(bitset.parents)$ - : $bitset.parents : {$bitset_inherit_move_init(it)$}; separator=",\n"$ $endif$ + : $bitset.parents : { bitset | $bitset_inherit_move_init(bitset)$}; separator=",\n"$ $endif$ { m_bitset = x.m_bitset; } @@ -368,7 +243,7 @@ $bitset.scopedname$::$bitset.name$( $bitset.scopedname$& $bitset.scopedname$::operator =( const $bitset.name$& x) { - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::operator =(x);}; separator="\n"$ $endif$ + $if(bitset.parents)$ $bitset.parents : { bitset | $bitset.scopedname$::operator =(x);}; separator="\n"$ $endif$ m_bitset = x.m_bitset; @@ -378,7 +253,7 @@ $bitset.scopedname$& $bitset.scopedname$::operator =( $bitset.scopedname$& $bitset.scopedname$::operator =( $bitset.name$&& x) noexcept { - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::operator =(std::move(x));}; separator="\n"$ $endif$ + $if(bitset.parents)$ $bitset.parents : { bitset | $bitset.scopedname$::operator =(std::move(x));}; separator="\n"$ $endif$ m_bitset = x.m_bitset; @@ -388,7 +263,7 @@ $bitset.scopedname$& $bitset.scopedname$::operator =( bool $bitset.scopedname$::operator ==( const $bitset.name$& x) const { - $if(bitset.parents)$ $bitset.parents : { if ($it.scopedname$::operator !=(x)) return false;}; separator="\n"$ $endif$ + $if(bitset.parents)$ $bitset.parents : { bitset | if ($bitset.scopedname$::operator !=(x)) return false;}; separator="\n"$ $endif$ return m_bitset == x.m_bitset; } @@ -399,68 +274,65 @@ bool $bitset.scopedname$::operator !=( return !(*this == x); } -$if(ctx.anyCdr)$ -size_t $bitset.scopedname$::getCdrSerializedSize( - const $bitset.scopedname$& $if(bitset.parents)$data$endif$, - size_t current_alignment) -{ - size_t initial_alignment = current_alignment; - - $if(bitset.parents)$ $bitset.parents : {current_alignment += $it.scopedname$::getCdrSerializedSize(data, current_alignment);}; separator="\n"$ $endif$ - - $bitset.bitfields : { member | $if(!member.annotationNonSerialized)$$if(member.name)$$serialized_size_type(ctx=ctx, typecode=member.spec.typecode, var="current_alignment")$$endif$$endif$}; separator="\n"$ - - return current_alignment - initial_alignment; -} - -$endif$ - -$if(ctx.cdr)$ +$if(ctx.fastcdr)$ void $bitset.scopedname$::serialize( - eprosima::fastcdr::Cdr& scdr) const + eprosima::fastcdr::FastCdr& scdr) const { - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ + $if(bitset.parents)$ $bitset.parents : { bitset | $bitset.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_serialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ } void $bitset.scopedname$::deserialize( - eprosima::fastcdr::Cdr& dcdr) + eprosima::fastcdr::FastCdr& dcdr) { - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ + $if(bitset.parents)$ $bitset.parents : { bitset | $bitset.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_deserialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ } $endif$ -$if(ctx.fastcdr)$ -void $bitset.scopedname$::serialize( - eprosima::fastcdr::FastCdr& scdr) const -{ - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::serialize(scdr);}; separator="\n"$ $endif$ - $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_serialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ -} +$bitset.bitfields:{ member | $public_bitfield_definition(class=bitset.scopedname, member=member)$}; separator="\n"$ -void $bitset.scopedname$::deserialize( - eprosima::fastcdr::FastCdr& dcdr) +std::bitset<$bitset.fullBitSize$> $bitset.scopedname$::bitset() const { - $if(bitset.parents)$ $bitset.parents : {$it.scopedname$::deserialize(dcdr);}; separator="\n"$ $endif$ + std::string str_value; - $bitset.bitfields : { member |$if(!member.annotationNonSerialized)$$bitfield_deserialization(ctx=ctx, object=member)$$endif$}; separator="\n"$ + $bitset.parents : { bitset | + str_value = static_cast(this)->bitset().to_string() + str_value; + }; separator="\n"$ + + str_value = m_bitset.to_string() + str_value; + + return std::bitset<$bitset.fullBitSize$>(str_value); } -$endif$ +void $bitset.scopedname$::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}; + $bitset.parents : { bitset | + { + base_diff += $bitset.fullBitSize$; + std::bitset<$bitset.fullBitSize$> internal_bitset(str_value.substr(str_value.length() - base_diff, last_post)); + static_cast<$bitset.scopedname$*>(this)->bitset(internal_bitset); + last_post = base_diff; + \} + }; separator="\n"$ -$bitset.bitfields:{$public_bitfield_definition(it)$}; separator="\n"$ + base_diff += $bitset.bitSize$; + m_bitset = std::bitset<$bitset.bitSize$>(str_value.substr(str_value.length() - base_diff, last_post)); +} >> -public_bitfield_definition(member) ::= << +public_bitfield_definition(class, member) ::= << $if(member.name)$ -void $bitset.scopedname$::$member.name$( +void $class$::$member.name$( $member.spec.cppTypename$ _$member.name$) { int base = $member.basePosition$; @@ -477,7 +349,7 @@ $endif$ } -$member.spec.cppTypename$ $bitset.scopedname$::$member.name$() const +$member.spec.cppTypename$ $class$::$member.name$() const { int base = $member.basePosition$; $if(member.spec.typecode.isType_7)$ @@ -517,9 +389,9 @@ $union.scopedname$::$union.name$( { m__d = x.m__d; - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_copy(it)$}; separator="\n"$ + $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ $unionmemberdefault_copy(union.defaultMember)$ } } @@ -529,9 +401,9 @@ $union.scopedname$::$union.name$( { m__d = x.m__d; - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_move(it)$}; separator="\n"$ + $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ $unionmemberdefault_move(union.defaultMember)$ } } @@ -541,9 +413,9 @@ $union.scopedname$& $union.scopedname$::operator =( { m__d = x.m__d; - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_copy(it)$}; separator="\n"$ + $union.members:{ member | $unionmember_copy(member)$}; separator="\n"$ $unionmemberdefault_copy(union.defaultMember)$ } @@ -555,9 +427,9 @@ $union.scopedname$& $union.scopedname$::operator =( { m__d = x.m__d; - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_move(it)$}; separator="\n"$ + $union.members:{ member | $unionmember_move(member)$}; separator="\n"$ $unionmemberdefault_move(union.defaultMember)$ } @@ -572,9 +444,9 @@ bool $union.scopedname$::operator ==( return false; } - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_compare(it)$}; separator="\n"$ + $union.members:{ member | $unionmember_compare(member)$}; separator="\n"$ $unionmemberdefault_compare(union.defaultMember)$ } return false; @@ -591,12 +463,12 @@ void $union.scopedname$::_d( { bool b = false; - switch(m__d) + switch (m__d) { - $union.members:{$unionmember_discriminator_case(member=it, totallabels=union.totallabels)$}; separator="\n"$ + $union.members:{ member | $unionmember_discriminator_case(member=member, totallabels=union.totallabels)$}; separator="\n"$ } - if(!b) + if (!b) { throw BadParamException("Discriminator doesn't correspond with the selected union member"); } @@ -614,64 +486,14 @@ $union.discriminator.cppTypename$& $union.scopedname$::_d() return m__d; } -$union.members:{$public_unionmember_declaration(class=union.scopedname, member=it, defaultvalue=union.defaultvalue, totallabels=union.totallabels)$}; separator="\n"$ - -$if(ctx.anyCdr)$ -// TODO(Ricardo) Review -size_t $union.scopedname$::getCdrSerializedSize( - const $union.scopedname$& 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.scopedname$::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.scopedname$::deserialize( - eprosima::fastcdr::Cdr& dcdr) -{ - $deserializePossibleEnum(typecode=union.discriminator, name="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$ - +$union.members:{ member | $public_unionmember_declaration(class=union.scopedname, member=member, defaultvalue=union.defaultvalue, totallabels=union.totallabels)$}; separator="\n"$ $if(ctx.fastcdr)$ void $union.scopedname$::serialize( eprosima::fastcdr::FastCdr& scdr) const { - scdr << $serializeCasting(typecode=union.discriminator)$m__d; + scdr << m__d; - switch(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)$ @@ -681,17 +503,15 @@ void $union.scopedname$::serialize( void $union.scopedname$::deserialize( eprosima::fastcdr::FastCdr& dcdr) { - $deserializePossibleEnum(typecode=union.discriminator, name="m__d")$ + dcdr \>> m__d; - switch(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$ - >> enum_type(ctx, parent, enum) ::= <<>> @@ -701,7 +521,9 @@ bitmask_type(ctx, parent, bitmask) ::= <<>> /***** Utils *****/ public_member_declaration(class, member) ::= << -$if(member.typecode.primitive)$ +$if(member.annotationOptional)$ +$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)$ @@ -720,16 +542,16 @@ public_primitive_member_declaration(class, member) ::= << * @param _$member.name$ New value for member $member.name$ */ void $class$::$member.name$( - $member.typecode.cppTypename$ _$member.name$) + $member_type_declaration(member)$ _$member.name$) { - $if(member.typecode.forwarded)$ *$else$ $endif$m_$member.name$ = _$member.name$; + $\ $$if(member.typecode.forwarded)$*$endif$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 +$member_type_declaration(member)$ $class$::$member.name$() const { return $if(member.typecode.forwarded)$*$endif$m_$member.name$; } @@ -738,7 +560,7 @@ $member.typecode.cppTypename$ $class$::$member.name$() const * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ */ -$member.typecode.cppTypename$& $class$::$member.name$() +$member_type_declaration(member)$& $class$::$member.name$() { return $if(member.typecode.forwarded)$*$endif$m_$member.name$; } @@ -773,9 +595,9 @@ public_object_member_declaration(class, member) ::= << * @param _$member.name$ New value to be copied in member $member.name$ */ void $class$::$member.name$( - const $member.typecode.cppTypename$& _$member.name$) + const $member_type_declaration(member)$& _$member.name$) { - $if(member.typecode.forwarded)$ *$else$ $endif$m_$member.name$ = _$member.name$; + $\ $$if(member.typecode.forwarded)$*$endif$m_$member.name$ = _$member.name$; } /*! @@ -783,16 +605,16 @@ void $class$::$member.name$( * @param _$member.name$ New value to be moved in member $member.name$ */ void $class$::$member.name$( - $member.typecode.cppTypename$&& _$member.name$) + $member_type_declaration(member)$&& _$member.name$) { - $if(member.typecode.forwarded)$ *$else$ $endif$m_$member.name$ = std::move(_$member.name$); + $\ $$if(member.typecode.forwarded)$*$endif$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 +const $member_type_declaration(member)$& $class$::$member.name$() const { return $if(member.typecode.forwarded)$*$endif$m_$member.name$; } @@ -801,7 +623,7 @@ const $member.typecode.cppTypename$& $class$::$member.name$() const * @brief This function returns a reference to member $member.name$ * @return Reference to member $member.name$ */ -$member.typecode.cppTypename$& $class$::$member.name$() +$member_type_declaration(member)$& $class$::$member.name$() { return $if(member.typecode.forwarded)$*$endif$m_$member.name$; } @@ -882,7 +704,7 @@ $member.typecode.cppTypename$& $class$::$member.name$() $endif$ >> -member_copy(ctx, member) ::= << +member_copy(ctx, member) ::= <% $if(member.typecode.forwarded)$ m_$member.name$ = new $member.typecode.cppTypename$(); *m_$member.name$ = *x.m_$member.name$; @@ -897,9 +719,9 @@ $endif$ $else$ m_$member.name$ = x.m_$member.name$; $endif$ ->> +%> -member_move(member) ::= << +member_move(member) ::= <% $if(member.typecode.primitive)$ m_$member.name$ = x.m_$member.name$; $else$ @@ -910,41 +732,40 @@ $else$ m_$member.name$ = std::move(x.m_$member.name$); $endif$ $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:{case $it$:}; separator="\n"$ - b = false; - break; - default: - break; -} -break; -$else$ -$member.labels:{case $it$:}; separator="\n"$ -switch(__d) -{ - $member.labels:{case $it$:}; separator="\n"$ b = true; + switch (__d) + { + $totallabels:{ label | case $label$:}; separator="\n"$ + b = false; + break; + default: + break; + } break; - default: +$else$ +$member.labels:{ label | case $label$:}; separator="\n"$ + switch (__d) + { + $member.labels:{ label | case $label$:}; separator="\n"$ + b = true; + break; + default: + break; + } break; -} -break; $endif$ >> unionmember_copy(member) ::= << $if(member.labels)$ -$member.labels:{case $it$:}; separator="\n"$ -m_$member.name$ = x.m_$member.name$; -break; +$member.labels:{ label | case $label$:}; separator="\n"$ + m_$member.name$ = x.m_$member.name$; + break; $endif$ >> @@ -952,23 +773,23 @@ unionmemberdefault_copy(member) ::= << default: $if(member)$ $if(member.default)$ -m_$member.name$ = x.m_$member.name$; + m_$member.name$ = x.m_$member.name$; $endif$ $endif$ -break; + break; >> unionmember_move(member) ::= << $if(member.labels)$ -$member.labels:{case $it$:}; separator="\n"$ +$member.labels:{ label | case $label$:}; separator="\n"$ $if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; + m_$member.name$ = x.m_$member.name$; $else$ -m_$member.name$ = std::move(x.m_$member.name$); + m_$member.name$ = std::move(x.m_$member.name$); $endif$ -break; + break; $endif$ >> @@ -977,20 +798,20 @@ default: $if(member)$ $if(member.default)$ $if(member.typecode.primitive)$ -m_$member.name$ = x.m_$member.name$; + m_$member.name$ = x.m_$member.name$; $else$ -m_$member.name$ = std::move(x.m_$member.name$); + m_$member.name$ = std::move(x.m_$member.name$); $endif$ $endif$ $endif$ -break; + break; >> unionmember_compare(member) ::= << $if(member.labels)$ -$member.labels:{case $it$:}; separator="\n"$ - return (m_$it.name$ == x.m_$it.name$); +$member.labels:{ label | case $label$:}; separator="\n"$ + return (m_$member.name$ == x.m_$member.name$); break; $endif$ >> @@ -999,11 +820,11 @@ unionmemberdefault_compare(member) ::= << default: $if(member)$ $if(member.default)$ -return m_$member.name$ == x.m_$member.name$; + return m_$member.name$ == x.m_$member.name$; $endif$ $endif$ -break; + break; >> unionmember_set_discriminator(member, defaultvalue) ::= << @@ -1018,28 +839,28 @@ unionmember_check_case_list(member, totallabels) ::= << $if(member.default)$ bool b = true; -switch(m__d) +switch (m__d) { - $totallabels:{case $it$:}; separator="\n"$ - b = false; - break; + $totallabels:{ label | case $label$:}; separator="\n"$ + b = false; + break; default: - break; + break; } $else$ bool b = false; -switch(m__d) +switch (m__d) { - $member.labels:{case $it$:}; separator="\n"$ - b = true; - break; + $member.labels:{ label | case $label$:}; separator="\n"$ + b = true; + break; default: - break; + break; } $endif$ -if(!b) +if (!b) { throw BadParamException("This member has not been selected"); } @@ -1048,7 +869,7 @@ if(!b) unionmember_case_selection_se(ctx, member) ::= << $if(member.labels)$ $member.labels:{ label |case $label$:}; separator="\n"$ -$object_serialization(ctx=ctx, object=member, preffix="m_")$ +$object_serialization(ctx=ctx, object=member)$ break; $endif$ >> @@ -1057,18 +878,18 @@ unionmemberdefault_case_selection_se(ctx, member) ::= << default: $if(member)$ $if(member.default)$ -$object_serialization(ctx=ctx, object=member, preffix="m_")$ + $object_serialization(ctx=ctx, object=member)$ $endif$ $endif$ -break; + 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; + $object_deserialization(ctx=ctx, object=member)$ + break; $endif$ >> @@ -1076,30 +897,11 @@ unionmemberdefault_case_selection_de(ctx, member) ::= << default: $if(member)$ $if(member.default)$ -$object_deserialization(ctx=ctx, object=member, preffix="m_")$ -$endif$ + $object_deserialization(ctx=ctx, object=member)$ $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; + break; >> sequences_definition(typecode) ::= << @@ -1422,18 +1224,20 @@ bool& $scopedtypename$::release() } $if(ctx.anyCdr)$ -size_t $scopedtypename$::getCdrSerializedSize( +size_t $scopedtypename$::calculate_serialized_size( const $scopedtypename$& data, - size_t current_alignment) + 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)$ + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + return calculate_serialized_size(calculator, data, current_alignment); +} - return current_alignment - initial_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$ @@ -1520,3 +1324,9 @@ void $scopedtypename$::free_memory() $endif$ >> + +member_default_init(ctx, member, loopvar) ::= << +$if(member.typecode.forwarded)$ +m_$member.name$ = new $member.typecode.cppTypename$($if(member.annotationDefault)$$member.annotationDefaultValue$$endif$); +$endif$ +>> 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 afd9fc6a..98cc2e01 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -14,17 +14,19 @@ group TypesSwigInterface; +import "com/eprosima/fastdds/idl/templates/eprosima.stg" + main(ctx, definitions) ::= << -$fileHeader(file=[ctx.filename, ".i"], description=["This header file contains the SWIG interface of the described types in the IDL file."])$ +$fileHeader(ctx=ctx, file=[ctx.filename, ".i"], description=["This header file contains the SWIG interface of the described types in the IDL file."])$ %module $ctx.filename$ // SWIG helper modules %include "stdint.i" -%include "std_string.i" -%include "std_vector.i" %include "std_array.i" %include "std_map.i" +%include "std_string.i" +%include "std_vector.i" %include "typemaps.i" // Assignemt operators are ignored, as there is no such thing in Python. @@ -82,7 +84,7 @@ struct_type(ctx, parent, struct, extensions) ::= << // Overloaded getter methods shadow each other and are equivalent in python // Avoid a warning ignoring all but one -$struct.members : {$member_getters(struct_name=struct.scopedname, member=it)$}; separator="\n"$ +$struct.members : { member | $member_getters(struct_name=struct.scopedname, member=member)$}; separator="\n"$ %template(_$struct.name$Seq) eprosima::fastdds::dds::LoanableTypedCollection<$struct.scopedname$, std::false_type>; %template($struct.name$Seq) eprosima::fastdds::dds::LoanableSequence<$struct.scopedname$, std::false_type>; @@ -171,7 +173,7 @@ union_type(ctx, parent, union, extensions) ::= << // Overloaded getter methods shadow each other and are equivalent in python // Avoid a warning ignoring all but one %ignore $union.name$::_d() const; -$union.members : {$member_getters(struct_name=union.name, member=it)$}; separator="\n"$ +$union.members : { member | $member_getters(struct_name=union.name, member=member)$}; separator="\n"$ >> @@ -187,18 +189,19 @@ bitset_type(ctx, parent, bitset, extensions) ::= << >> // Enums are ported as constants in the target language -enum_type(ctx, parent, enum) ::= << ->> +enum_type(ctx, parent, enum) ::= <<>> // bitmasks are implemented as enums. Therefore, are ported as constants in the target language -bitmask_type(ctx, parent, bitmask) ::= << ->> +bitmask_type(ctx, parent, bitmask) ::= <<>> -annotation(ctx, annotation) ::= << ->> +const_decl(ctx, parent, const) ::= <<>> -interface(ctx, parent, interface, export_list) ::= << ->> +typedef_decl(ctx, parent, typedefs) ::= <<>> -exception(ctx, parent, exception) ::= << ->> +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/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index 11320609..e416e964 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -21,7 +21,6 @@ import com.eprosima.fastdds.solution.Solution; import com.eprosima.fastdds.util.Utils; import com.eprosima.fastdds.util.VSConfiguration; -import com.eprosima.idl.generator.manager.TemplateExtension; import com.eprosima.idl.generator.manager.TemplateGroup; import com.eprosima.idl.generator.manager.TemplateManager; import com.eprosima.idl.parser.grammar.IDLLexer; @@ -42,6 +41,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -49,11 +49,9 @@ import java.util.Vector; import java.util.Map; import java.util.HashMap; -import org.antlr.stringtemplate.StringTemplate; -import org.antlr.stringtemplate.StringTemplateErrorListener; -import org.antlr.stringtemplate.StringTemplateGroup; -import org.antlr.stringtemplate.language.DefaultTemplateLexer; -import org.antlr.v4.runtime.ANTLRFileStream; +import org.stringtemplate.v4.*; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; @@ -329,30 +327,6 @@ else if (arg.equals("-cs")) } - /* - * ---------------------------------------------------------------------------------------- - * - * Listener classes - */ - - class TemplateErrorListener implements StringTemplateErrorListener - { - public void error( - String arg0, - Throwable arg1) - { - System.out.println(ColorMessage.error() + arg0); - arg1.printStackTrace(); - } - - public void warning( - String arg0) - { - System.out.println(ColorMessage.warning() + arg0); - } - - } - /* * ---------------------------------------------------------------------------------------- * @@ -381,27 +355,6 @@ public boolean execute() Solution solution = new Solution(m_languageOption, m_exampleOption, getVersion(), m_publishercode, m_subscribercode); - // Load string templates - System.out.println("Loading templates from " + System.getProperty("java.class.path")); - // Add path of custom templates to manager search path - String extraPaths = ""; - for (Map.Entry entry : m_customStgOutput.entrySet()) - { - Path path = Paths.get(entry.getKey()).getParent(); - if (path != null) - { - extraPaths += ":" + path.toString().replace("\\", "/"); - } - else - { - extraPaths += ":./"; - } - } - - String templatePaths = "com/eprosima/fastdds/idl/templates:com/eprosima/fastcdr/idl/templates" + extraPaths; - System.out.println("Template resource folders: " + templatePaths); - TemplateManager.setGroupLoaderDirectories(templatePaths); - // In local for all products if (m_os.contains("Windows")) { @@ -444,21 +397,21 @@ public boolean execute() { solution.addProject(project); } + + for (String include : project.getIDLIncludeFiles()) + { + 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); + } + } } else { returnedValue = false; } - - for (String include : project.getIDLIncludeFiles()) - { - 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); - } - } } if (returnedValue && m_python) @@ -608,8 +561,7 @@ private Project process( try { - // Protocol CDR - project = parseIDL(idlFilename, dependant_idl_dir, processCustomTemplates); // TODO: Quitar archivos copiados TypesHeader.stg, TypesSource.stg, PubSubTypeHeader.stg de la carpeta com.eprosima.fastdds.idl.templates + project = parseIDL(idlFilename, dependant_idl_dir, processCustomTemplates); } catch (Exception ioe) { @@ -680,58 +632,45 @@ private Project parseIDL( // Create template manager TemplateManager tmanager = new TemplateManager("FastCdrCommon:eprosima:Common", ctx, m_typesc); - List extensions = new ArrayList(); - // Load common types template - /// Add extension for @key related function definitions for each struct_type. - extensions.add(new TemplateExtension("struct_type", "keyFunctionHeadersStruct")); - tmanager.addGroup("TypesHeader", extensions); - if (m_type_object_files) - { - tmanager.addGroup("TypeObjectHeader", extensions); - } - extensions.clear(); - /// Add extension for @key related function declarations for each struct_type. - extensions.add(new TemplateExtension("struct_type", "keyFunctionSourcesStruct")); - tmanager.addGroup("TypesSource", extensions); + tmanager.addGroup("com/eprosima/fastcdr/idl/templates/TypesHeader.stg"); + tmanager.addGroup("com/eprosima/fastcdr/idl/templates/TypesSource.stg"); if (m_type_object_files) { - tmanager.addGroup("TypeObjectSource", extensions); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypeObjectSource.stg"); } - extensions.clear(); - /// Add extension for @key related preprocessor definitions in main for each struct typecode. - extensions.add(new TemplateExtension("main", "keyFunctionSourcesMain")); - tmanager.addGroup("TypesSource", extensions); - // Load Types common templates - tmanager.addGroup("DDSPubSubTypeHeader"); - tmanager.addGroup("DDSPubSubTypeSource"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg"); // Load Publisher templates - tmanager.addGroup("DDSPublisherHeader"); - tmanager.addGroup("DDSPublisherSource"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPublisherHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg"); // Load Subscriber templates - tmanager.addGroup("DDSSubscriberHeader"); - tmanager.addGroup("DDSSubscriberSource"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg"); // Load PubSubMain template - tmanager.addGroup("DDSPubSubMain"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg"); if (m_test) { // Load test template - tmanager.addGroup("SerializationTestSource"); - tmanager.addGroup("SerializationHeader"); - tmanager.addGroup("SerializationSource"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationTestSource.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationSource.stg"); } // Add JNI sources. if (m_languageOption == LANGUAGE.JAVA) { - tmanager.addGroup("JNIHeader"); - tmanager.addGroup("JNISource"); - tmanager.addGroup("JavaSource"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/JNIHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/JNISource.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/JavaSource.stg"); // Set package in context. ctx.setPackage(m_package); @@ -739,8 +678,8 @@ private Project parseIDL( if (m_python) { - tmanager.addGroup("TypesSwigInterface"); - tmanager.addGroup("DDSPubSubTypeSwigInterface"); + tmanager.addGroup("com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg"); } // Load custom templates into manager @@ -751,7 +690,13 @@ private Project parseIDL( System.out.println("Loading custom template " + entry.getKey() + "..."); Path path = Paths.get(entry.getKey()); String templateName = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf('.')); - tmanager.addGroup(templateName); + try { + String content = new String(Files.readAllBytes(path)); + tmanager.addGroupFromString(templateName, content); + } catch(IOException e){ + System.out.println(ColorMessage.error( + "IOException") + "Cannot read content from " + path.toString()); + } } } @@ -761,7 +706,7 @@ private Project parseIDL( try { - ANTLRFileStream input = new ANTLRFileStream(idlParseFileName); + CharStream input = CharStreams.fromFileName(idlParseFileName); IDLLexer lexer = new IDLLexer(input); lexer.setContext(ctx); CommonTokenStream tokens = new CommonTokenStream(lexer); @@ -820,12 +765,12 @@ private Project parseIDL( System.out.println("Generating Type definition files..."); if ((returnedValue) && (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + ".h", - maintemplates.getTemplate("TypesHeader"), + maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesHeader.stg"), m_replace))) { if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + ".cxx", - maintemplates.getTemplate("TypesSource"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesSource.stg"), m_replace)) { project.addCommonIncludeFile(relative_dir + ctx.getFilename() + ".h"); project.addCommonSrcFile(relative_dir + ctx.getFilename() + ".cxx"); @@ -833,10 +778,10 @@ private Project parseIDL( { System.out.println("Generating TypeObject files..."); if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "TypeObject.h", - maintemplates.getTemplate("TypeObjectHeader"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg"), m_replace)) { if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "TypeObject.cxx", - maintemplates.getTemplate("TypeObjectSource"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypeObjectSource.stg"), m_replace)) { project.addCommonIncludeFile(relative_dir + ctx.getFilename() + "TypeObject.h"); project.addCommonSrcFile(relative_dir + ctx.getFilename() + "TypeObject.cxx"); @@ -848,7 +793,7 @@ private Project parseIDL( System.out.println("Generating Swig interface files..."); if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + ".i", - maintemplates.getTemplate("TypesSwigInterface"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg"), m_replace)) { } @@ -861,19 +806,19 @@ private Project parseIDL( System.out.println("Generating Serialization Test file..."); String fileName = output_dir + ctx.getFilename() + "SerializationTest.cpp"; returnedValue = - Utils.writeFile(fileName, maintemplates.getTemplate("SerializationTestSource"), m_replace); + Utils.writeFile(fileName, maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/SerializationTestSource.stg"), m_replace); project.addCommonTestingFile(relative_dir + ctx.getFilename() + "SerializationTest.cpp"); System.out.println("Generating Serialization Source file..."); String fileNameS = output_dir + ctx.getFilename() + "Serialization.cpp"; returnedValue = - Utils.writeFile(fileNameS, maintemplates.getTemplate("SerializationSource"), m_replace); + Utils.writeFile(fileNameS, maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/SerializationSource.stg"), m_replace); project.addCommonTestingFile(relative_dir + ctx.getFilename() + "Serialization.cpp"); System.out.println("Generating Serialization Header file..."); String fileNameH = output_dir + ctx.getFilename() + "Serialization.h"; returnedValue = - Utils.writeFile(fileNameH, maintemplates.getTemplate("SerializationHeader"), m_replace); + Utils.writeFile(fileNameH, maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/SerializationHeader.stg"), m_replace); project.addCommonTestingFile(relative_dir + ctx.getFilename() + "PubSubTypes.cxx"); for (String element : project.getFullDependencies()) @@ -883,29 +828,39 @@ private Project parseIDL( } } - // TODO: Uncomment following lines and create templates System.out.println("Generating TopicDataTypes files..."); - returnedValue &= - Utils.writeFile(output_dir + ctx.getFilename() + "PubSubTypes.h", - maintemplates.getTemplate("DDSPubSubTypeHeader"), m_replace); - + if (ctx.isThereIsStructOrUnion()) + { + if (returnedValue &= + Utils.writeFile(output_dir + ctx.getFilename() + "CdrAux.hpp", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg"), m_replace)) + { + project.addProjectIncludeFile(relative_dir + ctx.getFilename() + "CdrAux.hpp"); + returnedValue &= + Utils.writeFile(output_dir + ctx.getFilename() + "CdrAux.ipp", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg"), m_replace); + } + } + returnedValue &= + Utils.writeFile(output_dir + ctx.getFilename() + "PubSubTypes.h", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg"), m_replace); + project.addProjectIncludeFile(relative_dir + ctx.getFilename() + "PubSubTypes.h"); if (ctx.existsLastStructure()) { m_atLeastOneStructure = true; project.setHasStruct(true); - if (returnedValue = + if (returnedValue &= Utils.writeFile(output_dir + ctx.getFilename() + "PubSubTypes.cxx", - maintemplates.getTemplate("DDSPubSubTypeSource"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg"), m_replace)) { - project.addProjectIncludeFile(relative_dir + ctx.getFilename() + "PubSubTypes.h"); project.addProjectSrcFile(relative_dir + ctx.getFilename() + "PubSubTypes.cxx"); if (m_python) { System.out.println("Generating Swig interface files..."); - returnedValue = Utils.writeFile( - output_dir + ctx.getFilename() + "PubSubTypes.i", - maintemplates.getTemplate("DDSPubSubTypeSwigInterface"), m_replace); + returnedValue &= Utils.writeFile( + output_dir + ctx.getFilename() + "PubSubTypes.i", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg"), m_replace); } } @@ -914,11 +869,11 @@ private Project parseIDL( System.out.println("Generating Publisher files..."); if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "Publisher.h", - maintemplates.getTemplate("DDSPublisherHeader"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPublisherHeader.stg"), m_replace)) { if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "Publisher.cxx", - maintemplates.getTemplate("DDSPublisherSource"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg"), m_replace)) { project.addProjectIncludeFile(relative_dir + ctx.getFilename() + "Publisher.h"); project.addProjectSrcFile(relative_dir + ctx.getFilename() + "Publisher.cxx"); @@ -928,11 +883,11 @@ private Project parseIDL( System.out.println("Generating Subscriber files..."); if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "Subscriber.h", - maintemplates.getTemplate("DDSSubscriberHeader"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg"), m_replace)) { if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "Subscriber.cxx", - maintemplates.getTemplate("DDSSubscriberSource"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg"), m_replace)) { project.addProjectIncludeFile(relative_dir + ctx.getFilename() + "Subscriber.h"); project.addProjectSrcFile(relative_dir + ctx.getFilename() + "Subscriber.cxx"); @@ -942,7 +897,7 @@ private Project parseIDL( System.out.println("Generating main file..."); if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "PubSubMain.cxx", - maintemplates.getTemplate("DDSPubSubMain"), m_replace)) + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg"), m_replace)) { project.addProjectSrcFile(relative_dir + ctx.getFilename() + "PubSubMain.cxx"); } @@ -982,7 +937,7 @@ private Project parseIDL( if (ctx.existsLastStructure()) { - System.out.println("Generando fichero " + output_dir + ctx.getFilename() + "PubSub.java"); + System.out.println("Generating file " + output_dir + ctx.getFilename() + "PubSub.java"); if (!Utils.writeFile(outputDir + File.separator + ctx.getFilename() + "PubSub.java", maintemplates.getTemplate("JavaSource"), m_replace)) { @@ -1007,7 +962,7 @@ private Project parseIDL( return null; } - StringTemplate jnisourceTemplate = maintemplates.getTemplate("JNISource"); + ST jnisourceTemplate = maintemplates.getTemplate("JNISource"); if (Utils.writeFile(output_dir + ctx.getFilename() + "PubSubJNI.cxx", jnisourceTemplate, m_replace)) { project.addJniSrcFile(relative_dir + ctx.getFilename() + "PubSubJNI.cxx"); @@ -1102,66 +1057,67 @@ private boolean genVS( final String METHOD_NAME = "genVS"; boolean returnedValue = false; - StringTemplateGroup vsTemplates = StringTemplateGroup.loadGroup("VS", DefaultTemplateLexer.class, null); + STGroupFile vsTemplates = new STGroupFile("com/eprosima/fastdds/idl/templates/VS.stg", '$', '$'); if (vsTemplates != null) { - StringTemplate tsolution = vsTemplates.getInstanceOf("solution"); - StringTemplate tproject = vsTemplates.getInstanceOf("project"); - StringTemplate tprojectFiles = vsTemplates.getInstanceOf("projectFiles"); - StringTemplate tprojectPubSub = vsTemplates.getInstanceOf("projectPubSub"); - StringTemplate tprojectFilesPubSub = vsTemplates.getInstanceOf("projectFilesPubSub"); - StringTemplate tprojectJNI = null; - StringTemplate tprojectFilesJNI = null; - if (m_languageOption == LANGUAGE.JAVA) - { - tprojectJNI = vsTemplates.getInstanceOf("projectJNI"); - tprojectFilesJNI = vsTemplates.getInstanceOf("projectFilesJNI"); - } + ST tsolution = vsTemplates.getInstanceOf("solution"); returnedValue = true; for (int count = 0; returnedValue && (count < solution.getProjects().size()); ++count) { + ST tproject = vsTemplates.getInstanceOf("project"); + ST tprojectFiles = vsTemplates.getInstanceOf("projectFiles"); + ST tprojectPubSub = vsTemplates.getInstanceOf("projectPubSub"); + ST tprojectFilesPubSub = vsTemplates.getInstanceOf("projectFilesPubSub"); + ST tprojectJNI = null; + ST tprojectFilesJNI = null; + if (m_languageOption == LANGUAGE.JAVA) + { + tprojectJNI = vsTemplates.getInstanceOf("projectJNI"); + tprojectFilesJNI = vsTemplates.getInstanceOf("projectFilesJNI"); + } + Project project = (Project) solution.getProjects().get(count); - tproject.setAttribute("solution", solution); - tproject.setAttribute("project", project); - tproject.setAttribute("example", m_exampleOption); - tproject.setAttribute("vsVersion", vsVersion); - tproject.setAttribute("toolset", toolset); + tproject.add("solution", solution); + tproject.add("project", project); + tproject.add("example", m_exampleOption); + tproject.add("vsVersion", vsVersion); + tproject.add("toolset", toolset); - tprojectFiles.setAttribute("project", project); - tprojectFiles.setAttribute("vsVersion", vsVersion); + tprojectFiles.add("project", project); + tprojectFiles.add("vsVersion", vsVersion); - tprojectPubSub.setAttribute("solution", solution); - tprojectPubSub.setAttribute("project", project); - tprojectPubSub.setAttribute("example", m_exampleOption); - tprojectPubSub.setAttribute("vsVersion", vsVersion); - tprojectPubSub.setAttribute("toolset", toolset); + tprojectPubSub.add("solution", solution); + tprojectPubSub.add("project", project); + tprojectPubSub.add("example", m_exampleOption); + tprojectPubSub.add("vsVersion", vsVersion); + tprojectPubSub.add("toolset", toolset); - tprojectFilesPubSub.setAttribute("project", project); - tprojectFilesPubSub.setAttribute("vsVersion", vsVersion); + tprojectFilesPubSub.add("project", project); + tprojectFilesPubSub.add("vsVersion", vsVersion); if (m_languageOption == LANGUAGE.JAVA) { - tprojectJNI.setAttribute("solution", solution); - tprojectJNI.setAttribute("project", project); - tprojectJNI.setAttribute("example", m_exampleOption); - tprojectJNI.setAttribute("vsVersion", vsVersion); - tprojectJNI.setAttribute("toolset", toolset); - - tprojectFilesJNI.setAttribute("project", project); - tprojectFilesJNI.setAttribute("vsVersion", vsVersion); + tprojectJNI.add("solution", solution); + tprojectJNI.add("project", project); + tprojectJNI.add("example", m_exampleOption); + tprojectJNI.add("vsVersion", vsVersion); + tprojectJNI.add("toolset", toolset); + + tprojectFilesJNI.add("project", project); + tprojectFilesJNI.add("vsVersion", vsVersion); } for (int index = 0; index < m_vsconfigurations.length; index++) { - tproject.setAttribute("configurations", m_vsconfigurations[index]); - tprojectPubSub.setAttribute("configurations", m_vsconfigurations[index]); + tproject.add("configurations", m_vsconfigurations[index]); + tprojectPubSub.add("configurations", m_vsconfigurations[index]); if (m_languageOption == LANGUAGE.JAVA) { - tprojectJNI.setAttribute("configurations", m_vsconfigurations[index]); + tprojectJNI.add("configurations", m_vsconfigurations[index]); } } @@ -1198,37 +1154,26 @@ private boolean genVS( m_replace); } } - - tproject.reset(); - tprojectFiles.reset(); - tprojectPubSub.reset(); - tprojectFilesPubSub.reset(); - if (m_languageOption == LANGUAGE.JAVA) - { - tprojectJNI.reset(); - tprojectFilesJNI.reset(); - } - } if (returnedValue) { - tsolution.setAttribute("solution", solution); - tsolution.setAttribute("example", m_exampleOption); + tsolution.add("solution", solution); + tsolution.add("example", m_exampleOption); // Project configurations for (int index = 0; index < m_vsconfigurations.length; index++) { - tsolution.setAttribute("configurations", m_vsconfigurations[index]); + tsolution.add("configurations", m_vsconfigurations[index]); } if (m_languageOption == LANGUAGE.JAVA) { - tsolution.setAttribute("generateJava", true); + tsolution.add("generateJava", true); } String vsVersion_sol = "2019"; - tsolution.setAttribute("vsVersion", vsVersion_sol); + tsolution.add("vsVersion", vsVersion_sol); returnedValue = Utils.writeFile(m_outputDir + "solution-" + m_exampleOption + ".sln", tsolution, m_replace); @@ -1249,17 +1194,17 @@ private boolean genMakefile( { boolean returnedValue = false; - StringTemplate makecxx = null; + ST makecxx = null; - StringTemplateGroup makeTemplates = StringTemplateGroup.loadGroup("makefile", DefaultTemplateLexer.class, null); + STGroupFile makeTemplates = new STGroupFile("com/eprosima/fastdds/idl/templates/makefile.stg", '$', '$'); if (makeTemplates != null) { makecxx = makeTemplates.getInstanceOf("makecxx"); - makecxx.setAttribute("solution", solution); - makecxx.setAttribute("example", m_exampleOption); - makecxx.setAttribute("arch", arch); + makecxx.add("solution", solution); + makecxx.add("example", m_exampleOption); + makecxx.add("arch", arch); returnedValue = Utils.writeFile(m_outputDir + "makefile_" + m_exampleOption, makecxx, m_replace); @@ -1273,17 +1218,16 @@ private boolean genCMakeLists( { boolean returnedValue = false; - StringTemplate cmake = null; + ST cmake = null; - StringTemplateGroup cmakeTemplates = StringTemplateGroup.loadGroup("CMakeLists", DefaultTemplateLexer.class, - null); + STGroupFile cmakeTemplates = new STGroupFile("com/eprosima/fastdds/idl/templates/CMakeLists.stg", '$', '$'); if (cmakeTemplates != null) { cmake = cmakeTemplates.getInstanceOf("cmakelists"); - cmake.setAttribute("solution", solution); - cmake.setAttribute("test", m_test); + cmake.add("solution", solution); + cmake.add("test", m_test); returnedValue = Utils.writeFile(m_outputDir + "CMakeLists.txt", cmake, m_replace); } @@ -1295,15 +1239,14 @@ private boolean genSwigCMake( { boolean returnedValue = false; - StringTemplate swig = null; + ST swig = null; - StringTemplateGroup swigTemplates = - StringTemplateGroup.loadGroup("SwigCMake", DefaultTemplateLexer.class, null); + STGroupFile swigTemplates = new STGroupFile("com/eprosima/fastdds/idl/templates/SwigCMake.stg", '$', '$'); if (swigTemplates != null) { swig = swigTemplates.getInstanceOf("swig_cmake"); - swig.setAttribute("solution", solution); + swig.add("solution", solution); returnedValue = Utils.writeFile(m_outputDir + "CMakeLists.txt", swig, m_replace); diff --git a/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java b/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java index 9fb7458c..fc3ba60a 100644 --- a/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java +++ b/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java @@ -303,6 +303,20 @@ else if (content.getKind() == Kind.KIND_MAP) typecodes.add(new SimpleEntry(sequence.getCppTypename(), sequence)); } + public boolean isThereIsStructOrUnion() + { + for (TypeDeclaration type : m_types.values()) + { + if (type.getTypeCode() instanceof StructTypeCode || + type.getTypeCode() instanceof UnionTypeCode) + { + return true; + } + } + + return false; + } + /*** Functions inherited from FastCDR Context ***/ @Override @@ -319,7 +333,7 @@ public boolean isPrintoperation() public String getProduct() { - return "fastcdr"; + return "fastdds"; } public String getNamespace() diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/AliasTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/AliasTypeCode.java index 55a75f22..b7eb2d08 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/AliasTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/AliasTypeCode.java @@ -24,6 +24,7 @@ public AliasTypeCode( super(scope, name); } + @Override public long maxSerializedSize( long current_alignment) { diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/ArrayTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/ArrayTypeCode.java index 32fb0914..6a1aa96f 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/ArrayTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/ArrayTypeCode.java @@ -18,10 +18,19 @@ public class ArrayTypeCode extends com.eprosima.idl.parser.typecode.ArrayTypeCod implements TypeCode { + @Override public long maxSerializedSize( long current_alignment) { long initial_alignment = current_alignment; + + if (!getContentTypeCode().isPrimitive() && + !getContentTypeCode().isIsType_c() /*enum*/) + { + // DHEADER if XCDRv2 + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); + } + long size = 1; for (int count = 0; count < getDimensions().size(); ++count) { diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitmaskTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitmaskTypeCode.java index 964f86d9..7bad39fb 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitmaskTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitmaskTypeCode.java @@ -32,6 +32,7 @@ public BitmaskTypeCode( super(scope, name, bit_bound); } + @Override public long maxSerializedSize( long current_alignment) { diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitsetTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitsetTypeCode.java index e412f788..60fd18a6 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitsetTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/BitsetTypeCode.java @@ -27,17 +27,29 @@ public BitsetTypeCode( super(scope, name); } + @Override public long maxSerializedSize( long current_alignment) { long initial_alignment = current_alignment; - for (Bitfield member : getBitfields(true)) + int full_bit_size = getFullBitSize(); + + if (9 > full_bit_size) + { + current_alignment += 1; + } + else if (17 > full_bit_size) + { + current_alignment += 2 + TypeCode.cdr_alignment(current_alignment, 2); + } + else if (33 > full_bit_size) + { + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); + } + else { - if (!member.isAnnotationNonSerialized()) - { - current_alignment += ((TypeCode)member.getSpec().getTypecode()).maxSerializedSize(current_alignment); - } + current_alignment += 8 + TypeCode.cdr_alignment(current_alignment, 8); } return current_alignment - initial_alignment; diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/EnumTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/EnumTypeCode.java index 7df797cc..d99a4a15 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/EnumTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/EnumTypeCode.java @@ -24,6 +24,7 @@ public EnumTypeCode( super(scope, name); } + @Override public long maxSerializedSize( long current_alignment) { diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MapTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MapTypeCode.java index d43e053e..d9ba3f05 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MapTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MapTypeCode.java @@ -23,12 +23,21 @@ public MapTypeCode( super(maxsize); } + @Override public long maxSerializedSize( long current_alignment) { long initial_alignment = current_alignment; long maxsize = Long.parseLong(getMaxsize(), 10); + + if (!getValueTypeCode().isPrimitive() && + !getValueTypeCode().isIsType_c() /*enum*/) + { + // DHEADER if XCDRv2 + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); + } + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); for (long count = 0; count < maxsize; ++count) diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MemberedTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MemberedTypeCode.java new file mode 100644 index 00000000..d3e52e18 --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/MemberedTypeCode.java @@ -0,0 +1,78 @@ +// Copyright 2023 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. + +package com.eprosima.fastdds.idl.parser.typecode; + +public interface MemberedTypeCode extends TypeCode +{ + static long xcdr_extra_header_serialized_size( + long current_alignment, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind memberedtypecode_ext_kind) + { + long returned_alignment = current_alignment; + + if (com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.FINAL.get_value() < memberedtypecode_ext_kind.get_value()) + { + // For APPENDABLE and MUTABLE, the maximum is the XCDR2 header (DHEADER(0) : Int32). + returned_alignment += 4 + TypeCode.cdr_alignment(returned_alignment, 4); + } + + return returned_alignment; + } + + static long xcdr_extra_endheader_serialized_size( + long current_alignment, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind memberedtypecode_ext_kind) + { + long returned_alignment = current_alignment; + + if (com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.MUTABLE.get_value() == memberedtypecode_ext_kind.get_value()) + { + // For MUTABLE, extra alignment for the PID_SENTINAL. + returned_alignment += TypeCode.cdr_alignment(returned_alignment, 4); + } + + return returned_alignment; + } + + static long xcdr_extra_member_serialized_size( + long current_alignment, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind memberedtypecode_ext_kind, + boolean member_optional, + int member_size) + { + long returned_alignment = current_alignment; + + if (com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.MUTABLE.get_value() == memberedtypecode_ext_kind.get_value() || + member_optional) + { + if (5 > member_size) + { + returned_alignment += 4 + TypeCode.cdr_alignment(returned_alignment, 4); + } + else + { + // If member is from a MUTABLE type (or it is optional member) the maximum is XCDR1 LongMemberHeader. + // << ALIGN(4) + // << { FLAG_I + FLAG_M + PID_EXTENDED : UInt16 } + // << { slength=8 : UInt16 } + // << { M.id : <<: UInt32 } + // << { M.value.ssize : UInt32 } + returned_alignment += 4 + 4 + 4 + TypeCode.cdr_alignment(returned_alignment, 4); + } + } + + return returned_alignment; + } +} diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/PrimitiveTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/PrimitiveTypeCode.java index 1296a4b7..d8a5f6fd 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/PrimitiveTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/PrimitiveTypeCode.java @@ -24,6 +24,7 @@ public PrimitiveTypeCode( super(kind); } + @Override public long maxSerializedSize( long current_alignment) { @@ -42,11 +43,11 @@ public long maxSerializedSize( case com.eprosima.idl.parser.typecode.Kind.KIND_LONG: case com.eprosima.idl.parser.typecode.Kind.KIND_ULONG: case com.eprosima.idl.parser.typecode.Kind.KIND_FLOAT: - case com.eprosima.idl.parser.typecode.Kind.KIND_WCHAR: current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); break; case com.eprosima.idl.parser.typecode.Kind.KIND_SHORT: case com.eprosima.idl.parser.typecode.Kind.KIND_USHORT: + case com.eprosima.idl.parser.typecode.Kind.KIND_WCHAR: current_alignment += 2 + TypeCode.cdr_alignment(current_alignment, 2); break; case com.eprosima.idl.parser.typecode.Kind.KIND_BOOLEAN: diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SequenceTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SequenceTypeCode.java index f586ad2f..24b1040c 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SequenceTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SequenceTypeCode.java @@ -23,6 +23,7 @@ public SequenceTypeCode( super(maxsize); } + @Override public long maxSerializedSize( long current_alignment) { @@ -38,6 +39,13 @@ public long maxSerializedSize( detect_recursive_ = true; } + if (!getContentTypeCode().isPrimitive() && + !getContentTypeCode().isIsType_c() /*enum*/) + { + // DHEADER if XCDRv2 + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); + } + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4); for (long count = 0; count < maxsize; ++count) diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SetTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SetTypeCode.java index 4472a058..b839fddc 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SetTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/SetTypeCode.java @@ -23,6 +23,7 @@ public SetTypeCode( super(maxsize); } + @Override public long maxSerializedSize( long current_alignment) { diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StringTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StringTypeCode.java index 6fb09696..60a5f3c9 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StringTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StringTypeCode.java @@ -39,7 +39,7 @@ public long maxSerializedSize( current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4) + maxsize + 1; break; case Kind.KIND_WSTRING: - current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4) + (maxsize * 4); + current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4) + (maxsize * 2); break; } diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StructTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StructTypeCode.java index 36c70ec1..6ac23165 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StructTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/StructTypeCode.java @@ -20,7 +20,7 @@ import java.util.ArrayList; public class StructTypeCode extends com.eprosima.idl.parser.typecode.StructTypeCode - implements TypeCode + implements MemberedTypeCode { public StructTypeCode( String scope, @@ -33,6 +33,11 @@ public boolean isHasKey() { boolean returnedValue = false; + for (com.eprosima.idl.parser.typecode.TypeCode parent : getInheritances()) + { + returnedValue |= ((StructTypeCode)parent).isHasKey(); + } + for (int count = 0; count < getMembers().size() && !returnedValue; ++count) { Member member = getMembers().get(count); @@ -44,26 +49,33 @@ public boolean isHasKey() public String getMaxSerializedSize() { - return Long.toString(maxSerializedSize(0)); + return Long.toString(maxSerializedSize(0, false, get_extensibility())); } + @Override public long maxSerializedSize( long current_alignment) { - return maxSerializedSize(current_alignment, false); + return maxSerializedSize(current_alignment, false, get_extensibility()); } + private long maxSerializedSize( long current_alignment, - boolean only_keys) + boolean only_keys, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind struct_ext_kind) { long initial_alignment = current_alignment; + current_alignment = MemberedTypeCode.xcdr_extra_header_serialized_size(current_alignment, struct_ext_kind); for (com.eprosima.idl.parser.typecode.TypeCode parent : getInheritances()) { - current_alignment += ((StructTypeCode)parent).maxSerializedSize(current_alignment, only_keys); + current_alignment += ((StructTypeCode)parent).maxSerializedSize(current_alignment, only_keys, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.FINAL); // FINAL to avoid calculation + // of any XCDR header. } + // TODO if only_key, get members sorted. for (Member member : getMembers()) { if (member.isAnnotationNonSerialized()) @@ -77,7 +89,9 @@ private long maxSerializedSize( if (member.getTypecode() instanceof StructTypeCode && ((StructTypeCode)member.getTypecode()).isHasKey()) { current_alignment += - ((StructTypeCode)member.getTypecode()).maxSerializedSize(current_alignment, true); + ((StructTypeCode)member.getTypecode()).maxSerializedSize(current_alignment, true, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.FINAL); // FINAL to avoid calculation + // of any XCDR header. } else { @@ -87,16 +101,21 @@ private long maxSerializedSize( } else if (!only_keys) { + current_alignment = MemberedTypeCode.xcdr_extra_member_serialized_size(current_alignment, struct_ext_kind, member.isAnnotationOptional(), + member.getTypecode() instanceof PrimitiveTypeCode ? Integer.parseInt(((PrimitiveTypeCode)member.getTypecode()).getSize()) : 8); current_alignment += ((TypeCode)member.getTypecode()).maxSerializedSize(current_alignment); } } + current_alignment = MemberedTypeCode.xcdr_extra_endheader_serialized_size(current_alignment, struct_ext_kind); + return current_alignment - initial_alignment; } public String getMaxKeySerializedSize() { - return Long.toString(maxSerializedSize(0, true)); + return Long.toString(maxSerializedSize(0, true, + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.FINAL)); } public void setIsTopic( diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/TypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/TypeCode.java index 6b7eddd5..3e9136be 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/TypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/TypeCode.java @@ -23,6 +23,9 @@ static long cdr_alignment( return (data_size - (current_alignment % data_size)) & (data_size - 1); } + /* + * Returns the maximum serialized size between XCDRv1 and XCDRv2. + */ public long maxSerializedSize( long current_alignment); } diff --git a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/UnionTypeCode.java b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/UnionTypeCode.java index 82af7470..dd3160d3 100644 --- a/src/main/java/com/eprosima/fastdds/idl/parser/typecode/UnionTypeCode.java +++ b/src/main/java/com/eprosima/fastdds/idl/parser/typecode/UnionTypeCode.java @@ -34,12 +34,16 @@ public UnionTypeCode( super(scope, name, discriminatorTypeCode); } + @Override public long maxSerializedSize( long current_alignment) { long initial_alignment = current_alignment; long reset_alignment = 0; long union_max_size_serialized = 0; + com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind union_ext_kind = get_extensibility(); + + current_alignment = MemberedTypeCode.xcdr_extra_header_serialized_size(current_alignment, union_ext_kind); current_alignment += ((TypeCode)getDiscriminator()).maxSerializedSize(current_alignment); @@ -53,7 +57,8 @@ public long maxSerializedSize( } } - return union_max_size_serialized - initial_alignment; - } + current_alignment = MemberedTypeCode.xcdr_extra_endheader_serialized_size(union_max_size_serialized, union_ext_kind); + return current_alignment - initial_alignment; + } } diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg b/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg index 8fc06de8..62078d2b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg @@ -27,30 +27,29 @@ set(CMAKE_CXX_EXTENSIONS OFF) find_package(fastcdr REQUIRED) find_package(fastrtps REQUIRED) -$solution.projects : {$pub_sub_execs(project=it, libraries=solution.libraries, test=test)$}; separator="\n"$ +$solution.projects : { project | $pub_sub_execs(project=project, libraries=solution.libraries, test=test)$}; separator="\n"$ >> pub_sub_execs(project, libraries, test) ::= << message(STATUS "Configuring $project.name$...") -add_library($project.name$_lib $project.commonSrcFiles : {$it$}; separator=" "$) -target_link_libraries($project.name$_lib $solution.libraries : {$it$}; separator=" "$) +add_library($project.name$_lib $project.commonSrcFiles : { file | $file$}; separator=" "$) +target_link_libraries($project.name$_lib $solution.libraries : { library | $library$}; separator=" "$) $if(!project.projectSrcFiles.empty)$ -add_executable($project.name$ $project.projectSrcFiles : {$it$}; separator=" "$) -target_link_libraries($project.name$ $solution.libraries : {$it$}; separator=" "$ - $project.name$_lib $project.dependencies : {$it$_lib}; separator=" "$) +add_executable($project.name$ $project.projectSrcFiles : { file | $file$}; separator=" "$) +target_link_libraries($project.name$ $solution.libraries : { library | $library$}; separator=" "$ + $project.name$_lib $project.dependencies : { dep | $dep$_lib}; separator=" "$) $endif$ - $if(test)$ # $project.name$ Serialization Test add_executable($project.name$SerializationTest - $project.commonTestingFiles : {$it$}; separator="\n"$ + $project.commonTestingFiles : { file | $file$}; separator="\n"$ ) -target_link_libraries($project.name$SerializationTest $solution.libraries : {$it$}; separator=" "$ - $project.name$_lib $project.dependencies : {$it$_lib}; separator=" "$) +target_link_libraries($project.name$SerializationTest $solution.libraries : { library | $library$}; separator=" "$ + $project.name$_lib $project.dependencies : { dep | $dep$_lib}; separator=" "$) $endif$ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/Common.stg b/src/main/java/com/eprosima/fastdds/idl/templates/Common.stg deleted file mode 100644 index f250b9f8..00000000 --- a/src/main/java/com/eprosima/fastdds/idl/templates/Common.stg +++ /dev/null @@ -1,135 +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 Common; - -fileHeader(ctx, file, description) ::= << -// 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. - -/*! - * @file $file$ - * $description$ - * - * This file was generated by the tool $ctx.product$gen. - */ ->> - -paramRetType(typecode) ::= << -$if(typecode)$ -$typecode.cppTypename$ -$else$ -void -$endif$ ->> - -paramTypeByRef(typecode) ::= << -$typecode.cppTypename$& ->> - -paramDeclsByValue(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param |/*$param.comment$*/ $paramTypeByValue(typecode=param.typecode)$ $param.name$}; separator=", "$ ->> - -paramDeclsByRef(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param |/*$param.comment$*/ $paramTypeByRef(typecode=param.typecode)$ $param.name$}; separator=", "$ ->> - -paramDeclsOnlyOutByRef(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param | /*$param.comment$*/ $if(param.output)$$paramTypeByRef(typecode=param.typecode)$$else$$paramTypeByValue(typecode=param.typecode)$$endif$ $param.name$}; separator=", "$ ->> - -extractParams(params, separatorInicial) ::= << -$if(params)$$separatorInicial$$endif$$params : {param | $param.name$};separator=", "$ ->> - -/** Extensions **/ - -keyFunctionHeaders(type) ::= << -/*! - * @brief This function returns the maximum serialized size of the Key of an object - * depending on the buffer alignment. - * @param current_alignment Buffer alignment. - * @return Maximum serialized size. - */ -eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( - size_t current_alignment = 0); - -/*! - * @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; ->> - -keyFunctionHeadersStruct(ctx, parent, struct) ::= << -$keyFunctionHeaders(struct)$ ->> - -keyFunctionSourcesStruct(ctx, parent, struct) ::= << - -size_t $struct.scopedname$::getKeyMaxCdrSerializedSize( - size_t current_alignment) -{ - static_cast(current_alignment); - return $struct.cScopedname$_max_key_cdr_typesize; -} - -bool $struct.scopedname$::isKeyDefined() -{ - $if(struct.inheritances)$ $struct.inheritances : {if ($it.scopedname$::isKeyDefined())$\n$ return true;$\n$}; separator=" else\n "$ $endif$ return $if(struct.hasKey)$true$else$false$endif$; -} - -void $struct.scopedname$::serializeKey( - eprosima::fastcdr::Cdr& scdr) const -{ - (void) scdr; - $if(struct.inheritances)$ $struct.inheritances : { $it.scopedname$::serializeKey(scdr); }; separator="\n"$ $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$ -} -$"\n"$ ->> - -keyFunctionSourcesMain(ctx, definitions) ::= << -$ctx.types:{ type | $if(type.typeCode.isStructType)$#define $type.typeCode.cScopedname$_max_key_cdr_typesize $type.typeCode.maxKeySerializedSize$ULL;$endif$}; separator="\n"$ ->> - -fwd_decl(ctx, parent, type) ::= << -class $type.name$; - ->> - -boolean_converter ::= [ - "true":"true", - default: -] - -/**** NEW OUR_TYPES ****/ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg index 38096283..85c8f12b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubMain.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubMain.cpp"], description=["This file acts as a main entry point to the application."])$ @@ -108,6 +110,8 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg index 9de32f32..d3c23ebe 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.h"], description=["This header file contains the declaration of the serialization functions."])$ @@ -21,14 +23,17 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.h"], description=["This h #ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_PUBSUBTYPES_H_ #define _FAST_DDS_GENERATED_$ctx.headerGuardName$_PUBSUBTYPES_H_ +#include #include +#include +#include #include #include "$ctx.filename$.h" $ctx.directIncludeDependencies : {include | #include "$include$PubSubTypes.h"}; separator="\n"$ -#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) #error \ Generated $ctx.filename$ is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. #endif // GEN_API_VER @@ -61,7 +66,7 @@ export_list(exports) ::= << $exports; separator="\n"$ >> -exception(ctx, parent, exception) ::= << >> +exception(ctx, parent, exception) ::= <<>> operation(ctx, parent, operation, param_list) ::= <<>> @@ -69,8 +74,9 @@ param_list(parameters) ::= <<>> param(parameter) ::= <<>> -const_decl(ctx, parent, const) ::= << ->> +const_decl(ctx, parent, const) ::= <<>> + +fwd_decl(ctx, parent, type) ::= <<>> typedef_decl(ctx, parent, typedefs) ::= << $typedefs : { typedef |typedef $typedef.typedefContentTypeCode.cppTypename$ $typedef.name$;}; separator="\n"$ @@ -83,31 +89,34 @@ $if(struct.members)$ #ifndef SWIG namespace detail { - template - struct $struct.name$_rob - { - friend constexpr typename Tag::type get( - Tag) - { - return M; - } - }; - - struct $struct.name$_f +template +struct $struct.name$_rob +{ + friend constexpr typename Tag::type get( + Tag) { - typedef $last(struct.members).typecode.cppTypename$ $struct.name$::* type; - friend constexpr type get( - $struct.name$_f); - }; + return M; + } - template struct $struct.name$_rob<$struct.name$_f, &$struct.name$::m_$last(struct.members).name$>; +}; - template - inline size_t constexpr $struct.name$_offset_of() { - return ((::size_t) &reinterpret_cast((((T*)0)->*get(Tag())))); - } +struct $struct.name$_f +{ + typedef $last(struct.members).typecode.cppTypename$ $struct.name$::* type; + friend constexpr type get( + $struct.name$_f); +}; + +template struct $struct.name$_rob<$struct.name$_f, &$struct.name$::m_$last(struct.members).name$>; + +template +inline size_t constexpr $struct.name$_offset_of() +{ + return ((::size_t) &reinterpret_cast((((T*)0)->*get(Tag())))); } -#endif + +} // namespace detail +#endif // ifndef SWIG $endif$ $endif$ @@ -124,27 +133,42 @@ public: eProsima_user_DllExport $if(parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType(); - eProsima_user_DllExport virtual ~$if(parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType() override; + eProsima_user_DllExport ~$if(parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType() override; - eProsima_user_DllExport virtual bool serialize( + eProsima_user_DllExport bool serialize( void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } - eProsima_user_DllExport virtual bool deserialize( + eProsima_user_DllExport bool serialize( + void* data, eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + eProsima_user_DllExport bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport virtual bool getKey( + eProsima_user_DllExport std::function getSerializedSizeProvider( + void* data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + void* data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( void* data, eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport virtual void* createData() override; + eProsima_user_DllExport void* createData() override; - eProsima_user_DllExport virtual void deleteData( + eProsima_user_DllExport void deleteData( void* data) override; #ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED @@ -167,7 +191,7 @@ public: eProsima_user_DllExport inline bool construct_sample( void* memory) const override { - $if (struct.isPlain)$ new (memory) $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$()$else$ (void)memory$endif$; + $if (struct.isPlain)$new (memory) $if(parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$()$else$static_cast(memory)$endif$; return $if (struct.isPlain)$true$else$false$endif$; } @@ -182,10 +206,14 @@ private: static constexpr bool is_plain_impl() { $if(struct.members)$ - return $struct.maxSerializedSize$ULL == (detail::$struct.name$_offset_of<$struct.name$, detail::$struct.name$_f>() + sizeof($last(struct.members).typecode.cppTypename$)); + return $struct.maxSerializedSize$ULL == + (detail::$struct.name$_offset_of<$struct.name$, detail::$struct.name$_f>() + + sizeof($last(struct.members).typecode.cppTypename$)); $elseif(struct.inheritances)$ $if(last(struct.inheritances).isPlain)$ - return $struct.maxSerializedSize$ULL == (detail::$last(struct.inheritances).name$_offset_of<$last(struct.inheritances).name$, detail::$last(struct.inheritances).name$_f>() + sizeof($last(last(struct.inheritances).members).typecode.cppTypename$)); + return $struct.maxSerializedSize$ULL == + (detail::$last(struct.inheritances).name$_offset_of<$last(struct.inheritances).name$, detail::$last(struct.inheritances).name$_f>() + + sizeof($last(last(struct.inheritances).members).typecode.cppTypename$)); $else$ return true; $endif$ @@ -193,6 +221,7 @@ private: return true; $endif$ } + $endif$ }; >> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg index f86ba87d..9c901f62 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg @@ -14,17 +14,22 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.cpp"], description=["This header file contains the implementation of the serialization functions."])$ #include #include +#include #include "$ctx.filename$PubSubTypes.h" +#include "$ctx.filename$CdrAux.hpp" using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; $definitions; separator="\n"$ @@ -63,18 +68,19 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= << $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::$if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType() { - $if (ctx.GenerateTypesROS2)$ setName("$struct.ROS2Scopedname$");$else$ setName("$struct.scopedname$");$endif$ - auto type_size = $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::getMaxCdrSerializedSize(); - type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ - m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ - m_isGetKeyDefined = $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::isKeyDefined(); - size_t keyLength = $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::getKeyMaxCdrSerializedSize() > 16 ? - $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::getKeyMaxCdrSerializedSize() : 16; + $if(ctx.GenerateTypesROS2)$setName("$struct.ROS2Scopedname$");$else$setName("$struct.scopedname$");$endif$ + uint32_t type_size = $struct.cScopedname$_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = $if(struct.hasKey)$true$else$false$endif$; + uint32_t keyLength = $struct.cScopedname$_max_key_cdr_typesize > 16 ? $struct.cScopedname$_max_key_cdr_typesize : 16; m_keyBuffer = reinterpret_cast(malloc(keyLength)); memset(m_keyBuffer, 0, keyLength); } @@ -89,22 +95,29 @@ $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::~$if (par bool $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::serialize( void* data, - SerializedPayload_t* payload) + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) { $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$* p_type = static_cast<$if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$*>(data); // Object that manages the raw buffer. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + $if(struct.annotationFinal || struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR $elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$ : + $if(struct.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$); try { // Serialize encapsulation ser.serialize_encapsulation(); // Serialize the object. - p_type->serialize(ser); + ser << *p_type; } catch (eprosima::fastcdr::exception::Exception& /*exception*/) { @@ -112,7 +125,7 @@ bool $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::seri } // Get the serialized length - payload->length = static_cast(ser.getSerializedDataLength()); + payload->length = static_cast(ser.get_serialized_data_length()); return true; } @@ -129,14 +142,14 @@ bool $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::dese eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN); // Deserialize encapsulation. deser.read_encapsulation(); payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; // Deserialize the object. - p_type->deserialize(deser); + deser \>> *p_type; } catch (eprosima::fastcdr::exception::Exception& /*exception*/) { @@ -147,12 +160,18 @@ bool $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::dese } std::function $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::getSerializedSizeProvider( - void* data) + void* data, + DataRepresentationId_t data_representation) { - return [data]() -> uint32_t + return [data, data_representation]() -> uint32_t { - return static_cast(type::getCdrSerializedSize(*static_cast<$if (parent.IsInterface)$$parent.name$_$endif$$struct.name$*>(data))) + - 4u /*encapsulation*/; + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast<$if (parent.IsInterface)$$parent.name$_$endif$$struct.name$*>(data), current_alignment)) + + 4u /*encapsulation*/; }; } @@ -181,15 +200,15 @@ bool $if (parent.IsInterface)$$parent.name$_$endif$$struct.name$PubSubType::getK // Object that manages the raw buffer. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::getKeyMaxCdrSerializedSize()); + $struct.cScopedname$_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); - p_type->serializeKey(ser); - if (force_md5 || $if (parent.IsInterface)$$struct.scopedname$$else$$struct.name$$endif$::getKeyMaxCdrSerializedSize() > 16) + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || $struct.cScopedname$_max_key_cdr_typesize > 16) { m_md5.init(); - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); m_md5.finalize(); for (uint8_t i = 0; i < 16; ++i) { diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg index f8d11655..4ec7002b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.i"], description=["This header file contains the SWIG interface of the serialization functions."])$ @@ -23,38 +25,34 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.i"], description=["This h #include "$ctx.filename$PubSubTypes.h" %} -#define GEN_API_VER 1 +#define GEN_API_VER 2 %include "$ctx.filename$PubSubTypes.h" >> -module(ctx, parent, module, definition_list) ::= << ->> +module(ctx, parent, module, definition_list) ::= <<>> -definition_list(definitions) ::= << ->> +definition_list(definitions) ::= <<>> -struct_type(ctx, parent, struct) ::= << ->> +struct_type(ctx, parent, struct) ::= <<>> -union_type(ctx, parent, union, extensions) ::= << ->> +union_type(ctx, parent, union, extensions) ::= <<>> -bitset_type(ctx, parent, bitset, extensions) ::= << ->> +bitset_type(ctx, parent, bitset, extensions) ::= <<>> -enum_type(ctx, parent, enum) ::= << ->> +enum_type(ctx, parent, enum) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= << ->> +bitmask_type(ctx, parent, bitmask) ::= <<>> -annotation(ctx, annotation) ::= << ->> +const_decl(ctx, parent, const) ::= <<>> -interface(ctx, parent, interface, export_list) ::= << ->> +typedef_decl(ctx, parent, typedefs) ::= <<>> -exception(ctx, parent, exception) ::= << ->> +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/fastdds/idl/templates/DDSPublisherHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherHeader.stg index d48aa0bc..913cb5b7 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherHeader.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "Publisher.h"], description=["This header file contains the declaration of the publisher functions."])$ @@ -97,6 +99,8 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg index 089bf25d..44740bd2 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPublisherSource.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "Publisher.cpp"], description=["This file contains the implementation of the publisher functions."])$ @@ -191,6 +193,8 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg index 3029e23c..c7cb0a14 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberHeader.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "Subscriber.h"], description=["This header file contains the declaration of the subscriber functions."])$ @@ -100,6 +102,8 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg index d4b2762a..3799bfc7 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSSubscriberSource.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "Subscriber.cpp"], description=["This file contains the implementation of the subscriber functions."])$ @@ -175,6 +177,8 @@ param(parameter) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= <<>> struct_type(ctx, parent, struct) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/JNIHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/JNIHeader.stg index 3508f90f..e443af92 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/JNIHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/JNIHeader.stg @@ -14,6 +14,8 @@ group JNIHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "JNII.cxx"], description=[""])$ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/JNISource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/JNISource.stg index cc793e4a..4a2764f2 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/JNISource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/JNISource.stg @@ -14,6 +14,8 @@ group JNISource; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "JNI.cxx"], description=[""])$ @@ -219,7 +221,7 @@ class $struct.name$PubSubJNI : public TopicDataType, public SubscriberListener // Serialize encapsulation ser.serialize_encapsulation(); p_type->serialize(ser); - payload->length = (uint16_t)ser.getSerializedDataLength(); + payload->length = (uint16_t)ser.get_serialized_data_length(); return true; } @@ -257,7 +259,7 @@ class $struct.name$PubSubJNI : public TopicDataType, public SubscriberListener if(force_md5 || $struct.scopedname$::getKeyMaxCdrSerializedSize()>16) { m_md5.init(); - m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength()); + m_md5.update(m_keyBuffer,(unsigned int)ser.get_serialized_data_length()); m_md5.finalize(); for(uint8_t i = 0;i<16;++i) { handle->value[i] = m_md5.digest[i]; diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/JavaSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/JavaSource.stg index d5886a76..2a1eed46 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/JavaSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/JavaSource.stg @@ -14,6 +14,8 @@ group JavaSource; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSub.java"], description=[""])$ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg index 23512578..774110f7 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "Serialization.h"], description=["This file contains serialization definitions."])$ @@ -24,6 +26,8 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "Serialization.h"], description=["This $definitions; separator="\n"$ +extern bool g_$ctx.filename$_test_null_opt; + #endif //_FAST_DDS_GENERATED_$ctx.headerGuardName$_SERIALIZATION_H_ >> @@ -93,4 +97,6 @@ definition_list(definitions) ::= << $definitions; separator="\n"$ >> -fwd_decl(ctx, parent, type) ::= <<>> \ No newline at end of file +fwd_decl(ctx, parent, type) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index 602e62ae..77bae39b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -1,804 +1,917 @@ -// 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 ProtocolHeader; - -main(ctx, definitions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, "SerializationSource.cpp"], description=["This file contains serialization code."])$ - -#include "$ctx.filename$Serialization.h" - -#include -#include -#include -#include -#include -#include - -$ctx.directIncludeDependencies:{#include "$it$Serialization.h"}; separator="\n"$ - -$definitions; separator="\n"$ - ->> - -struct_type(ctx, parent, struct) ::= << -$if((ctx.generateTypesC))$ -void $if(struct.hasScope)$$struct.scope$::$endif$free_string$struct.name$( - $struct.name$* topic) -{ - $struct.allMembers:{$free_member_string(ctx=ctx, typecode=it.typecode, name=it.name)$}; separator=""$ -} - -$endif$ -void $if(struct.hasScope)$$struct.scope$::$endif$print$struct.name$( - $struct.name$* topic) -{ - printf("$struct.name$: { \n"); - $struct.allMembers:{$member_print(ctx=ctx, typecode=it.typecode, name=it.name)$}; separator="\n"$ - printf("}\n"); -} - -void $if(struct.hasScope)$$struct.scope$::$endif$initialize$struct.name$( - $struct.name$* topic, - int idx) -{ - if (idx == 0) - { - $struct.allMembers:{$member_assignment(ctx=ctx, typecode=it.typecode, name=it.name, originName=it.name)$}; separator="\n"$ - } - else - { - $struct.allMembers:{$simply_member_assignment(ctx=ctx, typecode=it.typecode, name=it.name)$}; separator="\n"$ - } -} - -int $if(struct.hasScope)$$struct.scope$::$endif$compare$struct.name$( - $struct.name$* topic_a, - $struct.name$* topic_b) -{ - $struct.allMembers:{$member_comparision(ctx=ctx, typecode=it.typecode, name=it.name, name=it.name)$}; separator="\n"$ - return 1; -} - -$if(struct.hasScope)$$struct.scope$::$endif$$struct.name$ $if(struct.hasScope)$$struct.scope$::$endif$createKey$struct.name$( - int idx) -{ - $struct.name$ result; - initialize$struct.name$(&result, idx+1); // 0 means don't use the idx internally. - return result; -} - ->> - -union_type(ctx, parent, union) ::= << -void $if(union.hasScope)$$union.scope$::$endif$print$union.name$( - $union.name$* topic) -{ - topic->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); - printf("$union.name$: { \n"); - $if(union.members)$ - $member_print(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, originName=first(union.members).name)$ - $endif$ - printf("}\n"); -} - -void $if(union.hasScope)$$union.scope$::$endif$initialize$union.name$( - $union.name$* topic) -{ - $if(union.members)$ - $member_assignment(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, originName=first(union.members).name)$ - $endif$ -} - -int $if(union.hasScope)$$union.scope$::$endif$compare$union.name$( - $union.name$* topic_a, - $union.name$* topic_b) -{ - topic_a->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); - topic_b->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); - $if(union.members)$ - $member_comparision(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, originName=first(union.members).name)$ - $endif$ - return 1; -} - ->> - -enum_type(ctx, parent, enum) ::= <<>> - -bitmask_type(ctx, parent, bitmask) ::= <<>> - -typedef_decl(ctx, parent, typedefs) ::= <<>> - -annotation(ctx, annotation) ::= <<>> - -module(ctx, parent, module, definition_list) ::= << -$definition_list$ ->> - -definition_list(definitions) ::= << -$definitions; separator="\n"$ - ->> - -fwd_decl(ctx, parent, type) ::= <<>> - -bitset_type(ctx, parent, bitset) ::= << -void $if(bitset.hasScope)$$bitset.scope$::$endif$print$bitset.name$( - $bitset.name$* topic) -{ - printf("$bitset.name$: { \n"); - $bitset.allBitfields:{$if(it.name)$printf("$it.name$: 0x%" PRIx64 "\n", (uint64_t)topic->$it.name$());$endif$}; separator="\n"$ -} - -void $if(bitset.hasScope)$$bitset.scope$::$endif$initialize$bitset.name$( - $bitset.name$* topic) -{ - $bitset.allBitfields:{$if(it.name)$$if(it.spec.typecode.isType_7)$topic->$it.name$(static_cast<$it.spec.typecode.cppTypename$>(rand()%2==1));$elseif(it.spec.typecode.primitive)$topic->$it.name$(static_cast<$it.spec.typecode.cppTypename$>(rand()));$endif$$endif$}; separator="\n"$ -} - -int $if(bitset.hasScope)$$bitset.scope$::$endif$compare$bitset.name$( - $bitset.name$* topic_a, - $bitset.name$* topic_b) -{ - $bitset.allBitfields:{$if(it.name)$if(topic_a->$it.name$() != topic_b->$it.name$()) return 0;$endif$}; separator="\n"$ - return 1; -} - ->> - -// ======================================================================================== -// ASSIGNMENT -// ======================================================================================== -simply_member_assignment(ctx, typecode, name) ::= << -// $typecode.cppTypename$ - $typecode.kind$ -$if(typecode.isType_7)$ -topic->$name$(static_cast<$typecode.cppTypename$>(idx%2==1)); -$elseif(typecode.primitive)$ -topic->$name$(static_cast<$typecode.cppTypename$>(idx)); -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -topic->$name$(std::to_wstring(idx)); -$elseif(ctx.generateTypesC)$ -topic->$name$(std::to_string(idx).c_str()); -$else$ -topic->$name$(std::to_string(idx)); -$endif$ -$elseif(typecode.isType_10)$ -$simply_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name)$ -$elseif(typecode.isSequenceType)$ -printf("For testing map's key structs sequences aren't allowed.\n"); -assert(false); -$elseif(typecode.isType_f)$ -printf("For testing map's key structs arrays aren't allowed.\n"); -assert(false); -$elseif(typecode.isMapType)$ -printf("For testing map's key structs maps aren't allowed.\n"); -assert(false); -$else$ -printf("For testing map's key structs $typecode.cppTypename$ aren't allowed.\n"); -assert(false); -$endif$ ->> - -member_assignment(ctx, typecode, name, originName) ::= << -// $typecode.cppTypename$ - $typecode.kind$ -$if(typecode.isType_7)$ -topic->$name$(static_cast<$typecode.cppTypename$>(rand()%2==1)); -$elseif(typecode.primitive)$ -topic->$name$(static_cast<$typecode.cppTypename$>(rand())); -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -topic->$name$(std::wstring($typecode.maxsize$,'W')); -$else$ -topic->$name$(u8"AAAu8u8รฑรฑรฑรถAA\u2602"); -$endif$ -$elseif(typecode.isType_10)$ -$member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$ -$elseif(typecode.isSequenceType)$ -$sequence_assigment(ctx=ctx, typecode=typecode, name=name, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isType_f)$ -$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isMapType)$ -$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, p="()", loopvar=ctx.newLoopVarName)$ -$else$ -$typecode.scope$::initialize$typecode.name$(&topic->$name$()); -$endif$ ->> - -array_member_assignment(ctx, typecode, name, originName, loopvar) ::= << -$if(typecode.isType_7)$ -topic->$name$ = static_cast<$typecode.cppTypename$>(rand()%2==1); -$elseif(typecode.primitive)$ -topic->$name$ = static_cast<$typecode.cppTypename$>(rand()); -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -topic->$name$ = std::wstring($typecode.maxsize$,'W'); -$elseif(ctx.generateTypesC)$ -free(topic->$name$); -topic->$name$ = (char*)malloc(6); // AAAAA\0 -strncpy(topic->$name$, "AAAAA", 6); -$else$ -topic->$name$ = std::string($typecode.maxsize$,'A'); -$endif$ -$elseif(typecode.isType_10)$ -$array_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ -$elseif(typecode.isSequenceType)$ -$sequence_assigment(ctx=ctx, typecode=typecode, name=name, p="", loopvar=loopvar)$ -$elseif(typecode.isType_f)$ -$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$else$ -$typecode.scope$::initialize$typecode.name$(&topic->$name$); -$endif$ ->> - -sequence_member_assignment(ctx, typecode, name, originName, p, loopvar, currentvar) ::= << -$if(typecode.isType_7)$ -$if(ctx.generateTypesC)$ -topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(rand()%2==1); -$else$ -topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(rand()%2==1)); -$endif$ -$elseif(typecode.primitive)$ -$if(ctx.generateTypesC)$ -topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(rand()); -$else$ -topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(rand())); -$endif$ -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -$if(ctx.generateTypesC)$ -topic->$name$$p$.value()[$currentvar$] = std::wstring($typecode.maxsize$,'W'); -$else$ -topic->$name$$p$.push_back(std::wstring($typecode.maxsize$,'W')); -$endif$ -$else$ -$if(ctx.generateTypesC)$ -topic->$name$$p$.value()[$currentvar$] = u8"AA\u2602A\u2602AA"; -$else$ -topic->$name$$p$.push_back(u8"AA\u2602A\u2602AA"); -$endif$ -$endif$ -$elseif(typecode.isSequenceType)$ -$sequence_assigment(ctx=ctx, typecode=typecode, name=name, loopvar=loopvar, p="")$ -$elseif(typecode.isType_f)$ -$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, loopvar=loopvar, p="")$ -$elseif(typecode.isType_10)$ -$sequence_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, p=p, loopvar=loopvar, currentvar=currentvar)$ -$else$ -$typecode.cppTypename$ aux$typecode.cTypename$_$name$; -initialize$typecode.name$(&aux$typecode.cTypename$_$name$); -$if(ctx.generateTypesC)$ -topic->$name$$p$.value()[$currentvar$] = aux$typecode.cTypename$_$name$; -$else$ -topic->$name$$p$.push_back(aux$typecode.cTypename$_$name$); -$endif$ -$endif$ - ->> - -map_member_assignment(ctx, keytypecode, valueTypeCode, name, originName, p, loopvar) ::= << -// Key generation -$if(keytypecode.isType_10)$ -$map_member_assignment(ctx=ctx, keytypecode=keytypecode.typedefContentTypeCode, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$elseif(keytypecode.isType_7)$ -$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand()%2==1); -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$elseif(keytypecode.primitive)$ -$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand()); -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$elseif(keytypecode.isType_d)$ -$if(keytypecode.isWStringType)$ -$if(keytypecode.isBounded)$ -std::wstring var_map_Key$loopvar$ = std::wstring($keytypecode.maxsize$, 'W'); -$else$ -$keytypecode.cppTypename$ var_map_Key$loopvar$ = std::wstring($keytypecode.maxsize$, 'W'); -$endif$ -var_map_Key$loopvar$ = std::to_wstring(rand()) + var_map_Key$loopvar$ ; -var_map_Key$loopvar$ = var_map_Key$loopvar$.substr(0, $keytypecode.maxsize$); -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$else$ -$if(keytypecode.isBounded)$ -std::string var_map_Key$loopvar$ = std::string($keytypecode.maxsize$,'A'); -$else$ -$keytypecode.cppTypename$ var_map_Key$loopvar$ = std::string($keytypecode.maxsize$,'A'); -$endif$ -var_map_Key$loopvar$ = std::to_string(rand()) + var_map_Key$loopvar$ ; -var_map_Key$loopvar$ = var_map_Key$loopvar$.substr(0, $keytypecode.maxsize$); -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$endif$ -$elseif(keytypecode.isSequenceType)$ -printf("Sequences not supported for testing map's key.\n"); -assert(false); -$elseif(keytypecode.isType_f)$ -printf("Arrays not supported for testing map's key.\n"); -assert(false); -$elseif(keytypecode.isMapType)$ -printf("Maps not supported for testing map's key.\n"); -assert(false); -$elseif(keytypecode.isUnionType)$ -printf("Unions not supported for testing map's key.\n"); -assert(false); -$elseif(keytypecode.isStructType)$ -$keytypecode.cppTypename$ var_map_Key$loopvar$ = createKey$keytypecode.cppTypename$($loopvar$); -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$else$ -printf("Unsupported testing map's key type ($keytypecode.cppTypename$).\n"); -assert(false); -$endif$ ->> - -map_member_value_assignment(ctx, valueTypeCode, name, originName, p, loopvar) ::= << -// Value assignment -$if(valueTypeCode.isType_7)$ -topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand()%2==1); -$elseif(valueTypeCode.primitive)$ -topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand()); -$elseif(valueTypeCode.isType_d)$ -$if(valueTypeCode.isWStringType)$ -topic->$name$$p$[var_map_Key$loopvar$] = std::wstring($valueTypeCode.maxsize$,'W'); -$elseif(ctx.generateTypesC)$ -free(topic->$name$$p$[var_map_Key$loopvar$]); -topic->$name$$p$[var_map_Key$loopvar$] = (char*)malloc(6); // AAAAA\0 -strncpy(topic->$name$$p$[var_map_Key$loopvar$], "AAAAA", 6); -$else$ -topic->$name$$p$[var_map_Key$loopvar$] = std::string($valueTypeCode.maxsize$,'A'); -$endif$ -$elseif(valueTypeCode.isType_10)$ -$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode.typedefContentTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ -$elseif(valueTypeCode.isSequenceType)$ -$sequence_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p=p, key1="var_map_", key2=loopvar), loopvar=loopvar, p="")$ -$elseif(valueTypeCode.isType_f)$ -$array_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p="()", key1="var_map_", key2=loopvar), originName=originName, dimensions=valueTypeCode.dimensions, p="", loopvar=loopvar)$ -$elseif(valueTypeCode.isMapType)$ -$map_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p=p, key1="var_map_", key2=loopvar), originName=originName,loopvar=loopvar, p="")$ -$else$ -$valueTypeCode.cppTypename$ aux$valueTypeCode.cppTypename$_$name$; -initialize$valueTypeCode.cppTypename$(&aux$valueTypeCode.cppTypename$_$name$); -topic->$name$$p$[var_map_Key$loopvar$] = aux$valueTypeCode.cppTypename$_$name$; -$endif$ ->> - -sequence_assigment(ctx, typecode, name, p, loopvar) ::= << -$if(typecode.contentTypeCode.forwarded)$ -static bool $name$_detect_recursive_ = false; -$endif$ -$if(typecode.contentTypeCode.isArrayType)$ -topic->$name$$p$.resize(50); -$endif$ -$if(typecode.contentTypeCode.isMapType)$ -topic->$name$$p$.resize(50); -$endif$ -for(size_t $loopvar$ = 0; $if(typecode.contentTypeCode.forwarded)$!$name$_detect_recursive_ && $endif$$loopvar$ < $if(typecode.unbound)$50$else$$typecode.maxsize$$endif$; ++$loopvar$) -{ - $if(typecode.contentTypeCode.forwarded)$ - $name$_detect_recursive_ = true; - $endif$ - $if(typecode.contentTypeCode.isSequenceType)$ - topic->$name$$p$.emplace_back(); - $if(ctx.generateTypesC)$ - $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ - $else$ - $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ - $endif$ - $elseif(typecode.contentTypeCode.isArrayType)$ - $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ - $elseif(typecode.contentTypeCode.isMapType)$ - $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ - $else$ - $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=name, p=p, loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ - $endif$ - $if(typecode.contentTypeCode.forwarded)$ - $name$_detect_recursive_ = false; - $endif$ -} ->> - -map_assigment(ctx, typecode, name, originName, p, loopvar) ::= << -for(int $loopvar$ = 0; $loopvar$ < $typecode.maxsize$; ++$loopvar$) -{ - $if(typecode.valueTypeCode.isSequenceType)$ - $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ - $elseif(typecode.valueTypeCode.isMapType)$ - $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ - $elseif(typecode.valueTypeCode.isArrayType)$ - $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p="", loopvar=ctx.nextLoopVarName)$ - $else$ - $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ - $endif$ -} ->> - -array_assigment(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << -$if(rest(dimensions))$ -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_assigment(ctx=ctx, typecode=typecode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ -} -$elseif(typecode.isType_f)$ -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ -} -$elseif(typecode.contentTypeCode.primitive)$ -memset(&topic->$name$$p$, static_cast<$typecode.contentTypeCode.cppTypename$>(rand()), sizeof(topic->$name$$p$)); -$elseif(typecode.contentTypeCode.isType_d)$ -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ -} -$else$ -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ -} -$endif$ ->> - - - -// ======================================================================================== -// PRINT -// ======================================================================================== -member_print(ctx, typecode, name, originName) ::= << -$if(typecode.primitive)$ -printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$()); -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -printf("$name$: %S\n", topic->$name$().c_str()); -$elseif(ctx.generateTypesC)$ -printf("$name$: %s\n", topic->$name$()); -$else$ -printf("$name$: %s\n", topic->$name$().c_str()); -$endif$ -$elseif(typecode.isType_10)$ -$member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$ -$elseif(typecode.isSequenceType)$ -$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isType_f)$ -$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="()", loopvar=ctx.newLoopVarName)$ -$else$ -$typecode.scope$::print$typecode.name$(&topic->$name$()); -$endif$ ->> - -array_member_print(ctx, typecode, name, originName, loopvar) ::= << -$if(typecode.primitive)$ -printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$); -$elseif(typecode.isType_d)$ -$if(typecode.isWStringType)$ -printf("$name$: %S\n", topic->$name$.c_str()); -$elseif(ctx.generateTypesC)$ -printf("$name$: %s\n", topic->$name$); -$else$ -printf("$name$: %s\n", topic->$name$.c_str()); -$endif$ -$elseif(typecode.isType_10)$ -$array_member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ -$elseif(typecode.isSequenceType)$ -$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isType_f)$ -$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$else$ -$typecode.scope$::print$typecode.name$(&topic->$name$); -$endif$ ->> - -map_member_print(ctx, typecode, name, originName, loopvar) ::= << -printf("[%" PRIx64 "]: ", (uint64_t)(it_$loopvar$.first)); -$if(typecode.valueTypeCode.primitive)$ -printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$); -$elseif(typecode.valueTypeCode.isType_d)$ -$if(typecode.valueTypeCode.isWStringType)$ -printf("$name$: %S\n", topic->$name$.c_str()); -$elseif(ctx.generateTypesC)$ -printf("$name$: %s\n", topic->$name$()); -$else$ -printf("$name$: %s\n", topic->$name$.c_str()); -$endif$ -$elseif(typecode.isType_10)$ -$map_member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$ -$elseif(typecode.valueTypeCode.isSequenceType)$ -$sequence_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.valueTypeCode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.valueTypeCode.isType_f)$ -$array_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, dimensions=typecode.valueTypeCode.dimensions, p="", loopvar=loopvar)$ -$else$ -$typecode.valueTypeCode.scope$::print$typecode.valueTypeCode.name$(&topic->$name$[it_$loopvar$.first]); -$endif$ ->> - -sequence_print(ctx, typecode, name, originName, p, loopvar) ::= << -printf("$name$_size: 0x%" PRIx64 "\n", (uint64_t)topic->$name$$p$.size()); -$if(typecode.contentTypeCode.primitive)$ -printf("$name$: "); -$print_sequence(name=name, p=p, loopvar=loopvar)$ -$elseif(typecode.contentTypeCode.isType_10)$ -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode.typedefContentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ -} - -$elseif(typecode.contentTypeCode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ - -$else$ -printf("$name$: \n"); -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $if(ctx.generateTypesC)$ - $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ - $else$ - $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ - $endif$ -} -$endif$ ->> - -map_print(ctx, typecode, name, originName, p, loopvar) ::= << -printf("$name$_size: 0x%" PRIx64 "\n", (uint64_t)topic->$name$$p$.size()); -for (auto it_$loopvar$ : topic->$name$$p$) -{ - printf("-"); - $map_key_print(ctx=ctx, typecode=typecode.keyTypeCode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ - printf(" : "); - $map_value_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ - printf("\n"); -} ->> - - - -map_key_print(ctx, typecode, name, originName, p, loopvar) ::= << -$if(typecode.isType_d)$ - $if(typecode.isWStringType)$ - printf("[%S]", (it_$loopvar$.first).c_str()); - $elseif(ctx.generateTypesC)$ - printf("[%s]", (it_$loopvar$.first)); - $else$ - printf("[%s]", (it_$loopvar$.first).c_str()); - $endif$ -$elseif(typecode.isSequenceType)$ -$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isType_f)$ -$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$elseif(typecode.isType_10)$ - $map_key_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.primitive)$ - printf("[$typecode$]"); -$else$ - printf("[$typecode$]"); -$endif$ ->> - -map_value_print(ctx, typecode, name, originName, p, loopvar) ::= << -$if(typecode.isType_d)$ - $if(typecode.isWStringType)$ - printf("[%S]", (topic->$name$$p$).c_str()); - $elseif(ctx.generateTypesC)$ - printf("[%s]", (topic->$name$$p$)); - $else$ - printf("[%s]", (topic->$name$$p$).c_str()); - $endif$ - -$elseif(typecode.isSequenceType)$ -$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isType_f)$ -$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$elseif(typecode.isType_10)$ - $map_value_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.primitive)$ - printf("[$typecode$]"); -$else$ - printf("[$typecode$]"); -$endif$ ->> - -array_print(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << -$if(rest(dimensions))$ -printf("$name$: \n"); -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_print(ctx=ctx, typecode=typecode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ -} -$elseif(typecode.contentTypeCode.primitive)$ -printf("$name$: "); -$print_array(name=name, p=p, loopvar=loopvar)$ -$elseif(typecode.contentTypeCode.isType_d)$ -printf("$name$: \n"); -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ -} - -$elseif(typecode.isMapType)$ -$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ - -$else$ -printf("$name$: \n"); -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ -} -$endif$ ->> - -print_sequence(name, p, loopvar) ::= << -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - printf("%" PRIx64 " ", (uint64_t)topic->$name$$p$$if(ctx.generateTypesC)$.value()$endif$[$loopvar$]); -} -printf("\n"); ->> - -print_array(name, p, loopvar) ::= << -for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) -{ - printf("%" PRIx64 " ", (uint64_t)topic->$name$$p$[$loopvar$]); -} -printf("\n"); ->> - -// ======================================================================================== -// COMPARISION -// ======================================================================================== -member_comparision(ctx, typecode, name, originName) ::= << -$if(typecode.primitive)$ -if (topic_a->$name$() != topic_b->$name$()) return 0; -$elseif(typecode.isType_d)$ -$if(typecode.isStringType)$ -$if(ctx.generateTypesC)$ -if (strncmp(topic_a->$name$(), topic_b->$name$(), strlen(topic_b->$name$())) != 0) return 0; -$else$ -if (topic_a->$name$() != topic_b->$name$()) return 0; -$endif$ -$else$ -if (topic_a->$name$() != topic_b->$name$()) return 0; -$endif$ -$elseif(typecode.isType_10)$ -$member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$ -$elseif(typecode.isSequenceType)$ -$sequence_comparision(ctx=ctx, typecode=typecode, name=name, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isMapType)$ -$map_comparision(ctx=ctx, typecode=typecode, name=name, p="()", loopvar=ctx.newLoopVarName)$ -$elseif(typecode.isType_f)$ -$array_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="()", loopvar=ctx.newLoopVarName)$ -$else$ -if (!$typecode.scope$::compare$typecode.name$(&topic_a->$name$(), &topic_b->$name$())) return 0; -$endif$ ->> - -array_member_comparision(ctx, typecode, name, originName, loopvar) ::= << -$if(typecode.primitive)$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$elseif(typecode.isType_d)$ -$if(typecode.isStringType)$ -$if(ctx.generateTypesC)$ -if (strncmp(topic_a->$name$, topic_b->$name$, strlen(topic_b->$name$)) != 0) return 0; -$else$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$endif$ -$else$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$endif$ -$elseif(typecode.isType_10)$ -$array_member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ -$elseif(typecode.isSequenceType)$ -$sequence_comparision(ctx=ctx, typecode=typecode, name=name, p="", loopvar=loopvar)$ -$elseif(typecode.isMapType)$ -$map_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ -$elseif(typecode.isType_f)$ -$array_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ -$else$ -if (!$typecode.scope$::compare$typecode.name$(&topic_a->$name$, &topic_b->$name$)) return 0; -$endif$ ->> - -map_member_comparision(ctx, typecode, name, originName, loopvar) ::= << -$if(typecode.valueTypeCode.primitive)$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$elseif(typecode.valueTypeCode.isType_d)$ -$if(typecode.valueTypeCode.isStringType)$ -$if(ctx.generateTypesC)$ -if (strncmp(topic_a->$name$, topic_b->$name$, strlen(topic_b->$name$)) != 0) return 0; -$else$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$endif$ -$else$ -if (topic_a->$name$ != topic_b->$name$) return 0; -$endif$ -$elseif(typecode.isType_10)$ -$map_member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ -$elseif(typecode.valueTypeCode.isSequenceType)$ -$sequence_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, p="", loopvar=loopvar)$ -$elseif(typecode.valueTypeCode.isMapType)$ -$map_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, originName=originName, p="", loopvar=ctx.nextLoopVarName)$ -$elseif(typecode.valueTypeCode.isType_f)$ -$array_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, originName=originName, dimensions=typecode.valueTypeCode.dimensions, p="", loopvar=loopvar)$ -$else$ -if (!$typecode.valueTypeCode.scope$::compare$typecode.valueTypeCode.name$(&topic_a->$name$, &topic_b->$name$)) return 0; -$endif$ ->> - -sequence_comparision(ctx, typecode, name, p, loopvar) ::= << -for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) -{ - $if(ctx.generateTypesC)$ - $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ - $else$ - $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ - $endif$ -} ->> - -map_comparision(ctx, typecode, name, originName, p, loopvar) ::= << -for(auto it_$loopvar$ : topic_a->$name$$p$) -{ - $map_member_comparision(ctx=ctx, typecode=typecode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=loopvar)$ -} ->> - -array_comparision(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << -$if(rest(dimensions))$ -for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) -{ - $array_comparision(ctx=ctx, typecode=typecode, name=indexName(name=name, loopvar=loopvar, p=p), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ -} -$elseif(typecode.contentTypeCode.primitive)$ -if (memcmp(&topic_a->$name$$p$, &topic_b->$name$$p$, sizeof(topic_a->$name$$p$)) != 0) return 0; -$elseif(typecode.contentTypeCode.isType_d)$ -for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) -{ - $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ -} -$else$ -for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) -{ - $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ -} -$endif$ ->> - -// ======================================================================================== -// AUXILIAR -// ======================================================================================== -indexName(name, p, loopvar) ::= <<$name$$p$[$loopvar$]>> -mapName(name, p, key1, key2) ::= <<$name$$p$[$key1$Key$key2$]>> -itMapName(name, p, loopvar) ::= <<$name$$p$[it_$loopvar$.first]>> - -// ======================================================================================== -// C STRING -// ======================================================================================== -// TODO: Add more cases if tests evolve... -free_member_string(ctx, typecode, name) ::= << -$if(ctx.generateTypesC)$ -$if(typecode.isType_a)$ -free_string$typecode.name$(&topic->$name$()); -$elseif(typecode.isSequenceType)$$if(typecode.contentTypeCode.isType_d)$ -char** $name$_buffer = topic->$name$().value(true); -delete[] $name$_buffer; -$endif$$endif$$endif$>> \ No newline at end of file +// 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 ProtocolHeader; + +import "eprosima.stg" + +main(ctx, definitions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "SerializationSource.cpp"], description=["This file contains serialization code."])$ + +#include "$ctx.filename$Serialization.h" + +#include +#include +#include +#include +#include +#include + +bool g_$ctx.filename$_test_null_opt = false; + +$ctx.directIncludeDependencies:{ header | #include "$header$Serialization.h"}; separator="\n"$ + +$definitions; separator="\n"$ + +>> + +struct_type(ctx, parent, struct) ::= << +$if((ctx.generateTypesC))$ +void $if(struct.hasScope)$$struct.scope$::$endif$free_string$struct.name$( + $struct.name$* topic) +{ + $struct.allMembers:{ member | + $free_member_string(ctx=ctx, typecode=member.typecode, name=member.name)$ + }; separator=""$ +} + +$endif$ +void $if(struct.hasScope)$$struct.scope$::$endif$print$struct.name$( + $struct.name$* topic) +{ + printf("$struct.name$: { \n"); + $struct.allMembers:{ member | + $member_print(ctx=ctx, typecode=member.typecode, name=member.name, originName=member.name, optional=member.annotationOptional)$ + }; separator="\n"$ + printf("}\n"); +} + +void $if(struct.hasScope)$$struct.scope$::$endif$initialize$struct.name$( + $struct.name$* topic, + int idx) +{ + if (idx == 0) + { + $struct.allMembers:{ member | + $if(member.annotationOptional)$ + if(!g_$ctx.filename$_test_null_opt) + { + $endif$ + $member_assignment(ctx=ctx, typecode=member.typecode, name=member.name, originName=member.name, optional=member.annotationOptional)$ + $if(member.annotationOptional)$ + \} + $endif$ + }; separator="\n"$ + } + else + { + $struct.allMembers:{ member | + $if(member.annotationOptional)$ + if(!g_$ctx.filename$_test_null_opt) + { + $endif$ + $simply_member_assignment(ctx=ctx, typecode=member.typecode, name=member.name, optional=member.annotationOptional)$ + $if(member.annotationOptional)$ + \} + $endif$ + }; separator="\n"$ + } +} + +int $if(struct.hasScope)$$struct.scope$::$endif$compare$struct.name$( + $struct.name$* topic_a, + $struct.name$* topic_b) +{ + $struct.allMembers:{ member | + $member_comparision(ctx=ctx, typecode=member.typecode, name=member.name, originName=member.name, optional=member.annotationOptional)$ + }; separator="\n"$ + return 1; +} + +$if(struct.hasScope)$$struct.scope$::$endif$$struct.name$ $if(struct.hasScope)$$struct.scope$::$endif$createKey$struct.name$( + int idx) +{ + $struct.name$ result; + initialize$struct.name$(&result, idx+1); // 0 means don't use the idx internally. + return result; +} + +>> + +union_type(ctx, parent, union) ::= << +void $if(union.hasScope)$$union.scope$::$endif$print$union.name$( + $union.name$* topic) +{ + topic->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); + printf("$union.name$: { \n"); + $if(union.members)$ + $member_print(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, + originName=first(union.members).name, optional=first(union.members).annotationOptional)$ + $endif$ + printf("}\n"); +} + +void $if(union.hasScope)$$union.scope$::$endif$initialize$union.name$( + $union.name$* topic) +{ + $if(union.members)$ + $member_assignment(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, + originName=first(union.members).name, optional=first(union.members).annotationOptional)$ + $endif$ +} + +int $if(union.hasScope)$$union.scope$::$endif$compare$union.name$( + $union.name$* topic_a, + $union.name$* topic_b) +{ + topic_a->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); + topic_b->_d(static_cast<$union.discriminator.cppTypename$>($first(first(union.members).labels)$)); + $if(union.members)$ + $member_comparision(ctx=ctx, typecode=first(union.members).typecode, name=first(union.members).name, + originName=first(union.members).name, optional=first(union.members).annotationOptional)$ + $endif$ + return 1; +} + +>> + +enum_type(ctx, parent, enum) ::= <<>> + +bitmask_type(ctx, parent, bitmask) ::= <<>> + +typedef_decl(ctx, parent, typedefs) ::= <<>> + +annotation(ctx, annotation) ::= <<>> + +module(ctx, parent, module, definition_list) ::= << +$definition_list$ +>> + +definition_list(definitions) ::= << +$definitions; separator="\n"$ + +>> + +fwd_decl(ctx, parent, type) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> + +bitset_type(ctx, parent, bitset) ::= << +void $if(bitset.hasScope)$$bitset.scope$::$endif$print$bitset.name$( + $bitset.name$* topic) +{ + printf("$bitset.name$: { \n"); + $bitset.allBitfields:{ bitfield | + $if(bitfield.name)$printf("$bitfield.name$: 0x%" PRIx64 "\n", (uint64_t)topic->$bitfield.name$());$endif$ + }; separator="\n"$ +} + +void $if(bitset.hasScope)$$bitset.scope$::$endif$initialize$bitset.name$( + $bitset.name$* topic) +{ + $bitset.allBitfields:{ bitfield | + $if(bitfield.name)$$if(bitfield.spec.typecode.isType_7)$topic->$bitfield.name$(static_cast<$bitfield.spec.typecode.cppTypename$>(rand()%2==1));$elseif(bitfield.spec.typecode.primitive)$topic->$bitfield.name$(static_cast<$bitfield.spec.typecode.cppTypename$>(rand()));$endif$$endif$ + }; separator="\n"$ +} + +int $if(bitset.hasScope)$$bitset.scope$::$endif$compare$bitset.name$( + $bitset.name$* topic_a, + $bitset.name$* topic_b) +{ + $bitset.allBitfields:{ bitfield | + $if(bitfield.name)$if(topic_a->$bitfield.name$() != topic_b->$bitfield.name$()) return 0;$endif$ + }; separator="\n"$ + return 1; +} + +>> + +// ======================================================================================== +// ASSIGNMENT +// ======================================================================================== +simply_member_assignment(ctx, typecode, name, optional) ::= << +$if(typecode.isType_10)$ +$simply_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, optional=optional)$ +$elseif(typecode.isType_7)$ +topic->$name$(static_cast<$typecode.cppTypename$>(idx%2==1)); +$elseif(typecode.primitive)$ +topic->$name$(static_cast<$typecode.cppTypename$>(idx)); +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +topic->$name$(std::to_wstring(idx)); +$elseif(ctx.generateTypesC)$ +topic->$name$() = std::to_string(idx).c_str(); +$else$ +topic->$name$() = std::to_string(idx); +$endif$ +$elseif(typecode.isSequenceType)$ +printf("For testing map's key structs sequences aren't allowed.\n"); +assert(false); +$elseif(typecode.isType_f)$ +printf("For testing map's key structs arrays aren't allowed.\n"); +assert(false); +$elseif(typecode.isMapType)$ +printf("For testing map's key structs maps aren't allowed.\n"); +assert(false); +$else$ +printf("For testing map's key structs $typecode.cppTypename$ aren't allowed.\n"); +assert(false); +$endif$ +>> + +member_assignment(ctx, typecode, name, originName, optional) ::= << +$if(typecode.isType_10)$ +$member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, optional=optional)$ +$elseif(typecode.isType_7)$ +topic->$name$(static_cast<$typecode.cppTypename$>(rand()%2==1)); +$elseif(typecode.isWCharType)$ +topic->$name$(L'W'); +$elseif(typecode.primitive)$ +topic->$name$(static_cast<$typecode.cppTypename$>(rand())); +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +topic->$name$(std::wstring($typecode.maxsize$,'W')); +$else$ +topic->$name$() = u8"AAAu8u8รฑรฑรฑรถAA\u2602"; +$endif$ +$elseif(typecode.isSequenceType)$ +$if(optional)$topic->$name$().reset(true);$endif$ +$sequence_assigment(ctx=ctx, typecode=typecode, name=name, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$elseif(typecode.isType_f)$ +$if(optional)$topic->$name$().reset(true);$endif$ +$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$elseif(typecode.isMapType)$ +$if(optional)$topic->$name$().reset(true);$endif$ +$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$else$ +$if(optional)$topic->$name$().reset(true);$endif$ +$typecode.scope$::initialize$typecode.name$(&topic->$name$()$if(optional)$.value()$endif$); +$endif$ +>> + +array_member_assignment(ctx, typecode, name, originName, loopvar) ::= << +$if(typecode.isType_7)$ +topic->$name$ = static_cast<$typecode.cppTypename$>(rand()%2==1); +$elseif(typecode.isWCharType)$ +topic->$name$ = static_cast<$typecode.cppTypename$>(L'W'); +$elseif(typecode.primitive)$ +topic->$name$ = static_cast<$typecode.cppTypename$>(rand()); +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +topic->$name$ = std::wstring($typecode.maxsize$,'W'); +$elseif(ctx.generateTypesC)$ +free(topic->$name$); +topic->$name$ = (char*)malloc(6); // AAAAA\0 +strncpy(topic->$name$, "AAAAA", 6); +$else$ +topic->$name$ = std::string($typecode.maxsize$,'A'); +$endif$ +$elseif(typecode.isType_10)$ +$array_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ +$elseif(typecode.isSequenceType)$ +$sequence_assigment(ctx=ctx, typecode=typecode, name=name, p="", loopvar=loopvar)$ +$elseif(typecode.isType_f)$ +$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$else$ +$typecode.scope$::initialize$typecode.name$(&topic->$name$); +$endif$ +>> + +sequence_member_assignment(ctx, typecode, name, originName, p, loopvar, currentvar) ::= << +$if(typecode.isType_7)$ +$if(ctx.generateTypesC)$ +topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(rand()%2==1); +$else$ +topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(rand()%2==1)); +$endif$ +$elseif(typecode.isWCharType)$ +topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(L'W')); +$elseif(typecode.primitive)$ +$if(ctx.generateTypesC)$ +topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(rand()); +$else$ +topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(rand())); +$endif$ +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +$if(ctx.generateTypesC)$ +topic->$name$$p$.value()[$currentvar$] = std::wstring($typecode.maxsize$,'W'); +$else$ +topic->$name$$p$.push_back(std::wstring($typecode.maxsize$,'W')); +$endif$ +$else$ +$if(ctx.generateTypesC)$ +topic->$name$$p$.value()[$currentvar$] = u8"AA\u2602A\u2602AA"; +$else$ +topic->$name$$p$.push_back(u8"AA\u2602A\u2602AA"); +$endif$ +$endif$ +$elseif(typecode.isSequenceType)$ +$sequence_assigment(ctx=ctx, typecode=typecode, name=name, loopvar=loopvar, p="")$ +$elseif(typecode.isType_f)$ +$array_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_assigment(ctx=ctx, typecode=typecode, name=name, originName=originName, loopvar=loopvar, p="")$ +$elseif(typecode.isType_10)$ +$sequence_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, p=p, loopvar=loopvar, currentvar=currentvar)$ +$else$ +$typecode.cppTypename$ aux$typecode.cTypename$_$name$; +initialize$typecode.name$(&aux$typecode.cTypename$_$name$); +$if(ctx.generateTypesC)$ +topic->$name$$p$.value()[$currentvar$] = aux$typecode.cTypename$_$name$; +$else$ +topic->$name$$p$.push_back(aux$typecode.cTypename$_$name$); +$endif$ +$endif$ + +>> + +map_member_assignment(ctx, keytypecode, valueTypeCode, name, originName, p, loopvar) ::= << +// Key generation +$if(keytypecode.isType_10)$ +$map_member_assignment(ctx=ctx, keytypecode=keytypecode.typedefContentTypeCode, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$elseif(keytypecode.isType_7)$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand()%2==1); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$elseif(keytypecode.isWCharType)$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(L'W'); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$elseif(keytypecode.primitive)$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand()); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$elseif(keytypecode.isType_d)$ +$if(keytypecode.isWStringType)$ +$if(keytypecode.isBounded)$ +std::wstring var_map_Key$loopvar$ = std::wstring($keytypecode.maxsize$, 'W'); +$else$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = std::wstring($keytypecode.maxsize$, 'W'); +$endif$ +var_map_Key$loopvar$ = std::to_wstring(rand()) + var_map_Key$loopvar$ ; +var_map_Key$loopvar$ = var_map_Key$loopvar$.substr(0, $keytypecode.maxsize$); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$else$ +$if(keytypecode.isBounded)$ +std::string var_map_Key$loopvar$ = std::string($keytypecode.maxsize$,'A'); +$else$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = std::string($keytypecode.maxsize$,'A'); +$endif$ +var_map_Key$loopvar$ = std::to_string(rand()) + var_map_Key$loopvar$ ; +var_map_Key$loopvar$ = var_map_Key$loopvar$.substr(0, $keytypecode.maxsize$); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$endif$ +$elseif(keytypecode.isSequenceType)$ +printf("Sequences not supported for testing map's key.\n"); +assert(false); +$elseif(keytypecode.isType_f)$ +printf("Arrays not supported for testing map's key.\n"); +assert(false); +$elseif(keytypecode.isMapType)$ +printf("Maps not supported for testing map's key.\n"); +assert(false); +$elseif(keytypecode.isUnionType)$ +printf("Unions not supported for testing map's key.\n"); +assert(false); +$elseif(keytypecode.isStructType)$ +$keytypecode.cppTypename$ var_map_Key$loopvar$ = createKey$keytypecode.cppTypename$($loopvar$); +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$else$ +printf("Unsupported testing map's key type ($keytypecode.cppTypename$).\n"); +assert(false); +$endif$ +>> + +map_member_value_assignment(ctx, valueTypeCode, name, originName, p, loopvar) ::= << +// Value assignment +$if(valueTypeCode.isType_7)$ +topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand()%2==1); +$elseif(valueTypeCode.isWCharType)$ +topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(L'W'); +$elseif(valueTypeCode.primitive)$ +topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand()); +$elseif(valueTypeCode.isType_d)$ +$if(valueTypeCode.isWStringType)$ +topic->$name$$p$[var_map_Key$loopvar$] = std::wstring($valueTypeCode.maxsize$,'W'); +$elseif(ctx.generateTypesC)$ +free(topic->$name$$p$[var_map_Key$loopvar$]); +topic->$name$$p$[var_map_Key$loopvar$] = (char*)malloc(6); // AAAAA\0 +strncpy(topic->$name$$p$[var_map_Key$loopvar$], "AAAAA", 6); +$else$ +topic->$name$$p$[var_map_Key$loopvar$] = std::string($valueTypeCode.maxsize$,'A'); +$endif$ +$elseif(valueTypeCode.isType_10)$ +$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode.typedefContentTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$ +$elseif(valueTypeCode.isSequenceType)$ +$sequence_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p=p, key1="var_map_", key2=loopvar), loopvar=loopvar, p="")$ +$elseif(valueTypeCode.isType_f)$ +$array_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p="()", key1="var_map_", key2=loopvar), originName=originName, dimensions=valueTypeCode.dimensions, p="", loopvar=loopvar)$ +$elseif(valueTypeCode.isMapType)$ +$map_assigment(ctx=ctx, typecode=valueTypeCode, name=mapName(name=name, p=p, key1="var_map_", key2=loopvar), originName=originName,loopvar=loopvar, p="")$ +$else$ +$valueTypeCode.cppTypename$ aux$valueTypeCode.cppTypename$_$name$; +initialize$valueTypeCode.cppTypename$(&aux$valueTypeCode.cppTypename$_$name$); +topic->$name$$p$[var_map_Key$loopvar$] = aux$valueTypeCode.cppTypename$_$name$; +$endif$ +>> + +sequence_assigment(ctx, typecode, name, p, loopvar) ::= << +$if(typecode.contentTypeCode.forwarded)$ +static bool $name$_detect_recursive_ = false; +$endif$ +$if(typecode.contentTypeCode.isArrayType)$ +topic->$name$$p$.resize(50); +$endif$ +$if(typecode.contentTypeCode.isMapType)$ +topic->$name$$p$.resize(50); +$endif$ +for(size_t $loopvar$ = 0; $if(typecode.contentTypeCode.forwarded)$!$name$_detect_recursive_ && $endif$$loopvar$ < $if(typecode.unbound)$50$else$$typecode.maxsize$$endif$; ++$loopvar$) +{ + $if(typecode.contentTypeCode.forwarded)$ + $name$_detect_recursive_ = true; + $endif$ + $if(typecode.contentTypeCode.isSequenceType)$ + topic->$name$$p$.emplace_back(); + $if(ctx.generateTypesC)$ + $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ + $else$ + $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ + $endif$ + $elseif(typecode.contentTypeCode.isArrayType)$ + $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ + $elseif(typecode.contentTypeCode.isMapType)$ + $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, p="", loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ + $else$ + $sequence_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=name, p=p, loopvar=ctx.nextLoopVarName, currentvar=loopvar)$ + $endif$ + $if(typecode.contentTypeCode.forwarded)$ + $name$_detect_recursive_ = false; + $endif$ +} +>> + +map_assigment(ctx, typecode, name, originName, p, loopvar) ::= << +for(int $loopvar$ = 0; $loopvar$ < $typecode.maxsize$; ++$loopvar$) +{ + $if(typecode.valueTypeCode.isSequenceType)$ + $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ + $elseif(typecode.valueTypeCode.isMapType)$ + $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ + $elseif(typecode.valueTypeCode.isArrayType)$ + $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p="", loopvar=ctx.nextLoopVarName)$ + $else$ + $map_member_assignment(ctx=ctx, keytypecode=typecode.keyTypeCode, valueTypeCode=typecode.valueTypeCode, name=name, originName=originName, p=p, loopvar=ctx.nextLoopVarName)$ + $endif$ +} +>> + +array_assigment(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << +$if(rest(dimensions))$ +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_assigment(ctx=ctx, typecode=typecode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ +} +$elseif(typecode.isType_f)$ +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ +} +$elseif(typecode.contentTypeCode.primitive)$ +memset(&topic->$name$$p$, static_cast<$typecode.contentTypeCode.cppTypename$>(rand()), sizeof(topic->$name$$p$)); +$elseif(typecode.contentTypeCode.isType_d)$ +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ +} +$else$ +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_assignment(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ +} +$endif$ +>> + + + +// ======================================================================================== +// PRINT +// ======================================================================================== +member_print(ctx, typecode, name, originName, optional) ::= << +$if(optional)$ +if (topic->$name$().has_value()) { +$endif$ + +$if(typecode.primitive)$ +printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$()$if(optional)$.value()$endif$); +$elseif(typecode.isBitsetType)$ +printf("$name$: %s\n", topic->$name$()$if(optional)$.value()$endif$.bitset().to_string().c_str()); +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +printf("$name$: %S\n", topic->$name$()$if(optional)$.value()$endif$.c_str()); +$elseif(ctx.generateTypesC)$ +printf("$name$: %s\n", topic->$name$()$if(optional)$.value()$endif$); +$else$ +printf("$name$: %s\n", topic->$name$()$if(optional)$.value()$endif$.c_str()); +$endif$ +$elseif(typecode.isType_10)$ +$member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, optional=optional)$ +$elseif(typecode.isSequenceType)$ +$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$elseif(typecode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$elseif(typecode.isType_f)$ +$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$else$ +$typecode.scope$::print$typecode.name$(&topic->$name$()$if(optional)$.value()$endif$); +$endif$ + +$if(optional)$ +} +$endif$ +>> + +array_member_print(ctx, typecode, name, originName, loopvar) ::= << +$if(typecode.primitive)$ +printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$); +$elseif(typecode.isBitsetType)$ +printf("$name$: %s\n", topic->$name$.bitset().to_string().c_str()); +$elseif(typecode.isType_d)$ +$if(typecode.isWStringType)$ +printf("$name$: %S\n", topic->$name$.c_str()); +$elseif(ctx.generateTypesC)$ +printf("$name$: %s\n", topic->$name$); +$else$ +printf("$name$: %s\n", topic->$name$.c_str()); +$endif$ +$elseif(typecode.isType_10)$ +$array_member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ +$elseif(typecode.isSequenceType)$ +$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isType_f)$ +$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$else$ +$typecode.scope$::print$typecode.name$(&topic->$name$); +$endif$ +>> + +map_member_print(ctx, typecode, name, originName, loopvar) ::= << +printf("[%" PRIx64 "]: ", (uint64_t)(it_$loopvar$.first)); +$if(typecode.valueTypeCode.primitive)$ +printf("$name$: 0x%" PRIx64 "\n", (uint64_t)topic->$name$); +$elseif(typecode.isBitsetType)$ +printf("$name$: %s\n", topic->$name$.bitset().to_string().c_str()); +$elseif(typecode.valueTypeCode.isType_d)$ +$if(typecode.valueTypeCode.isWStringType)$ +printf("$name$: %S\n", topic->$name$.c_str()); +$elseif(ctx.generateTypesC)$ +printf("$name$: %s\n", topic->$name$()); +$else$ +printf("$name$: %s\n", topic->$name$.c_str()); +$endif$ +$elseif(typecode.isType_10)$ +$map_member_print(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$ +$elseif(typecode.valueTypeCode.isSequenceType)$ +$sequence_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.valueTypeCode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.valueTypeCode.isType_f)$ +$array_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, loopvar=loopvar), originName=originName, dimensions=typecode.valueTypeCode.dimensions, p="", loopvar=loopvar)$ +$else$ +$typecode.valueTypeCode.scope$::print$typecode.valueTypeCode.name$(&topic->$name$[it_$loopvar$.first]); +$endif$ +>> + +sequence_print(ctx, typecode, name, originName, p, loopvar) ::= << +printf("$name$_size: 0x%" PRIx64 "\n", (uint64_t)topic->$name$$p$.size()); +$if(typecode.contentTypeCode.primitive)$ +printf("$name$: "); +$print_sequence(name=name, p=p, loopvar=loopvar)$ +$elseif(typecode.contentTypeCode.isType_10)$ +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode.typedefContentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ +} + +$elseif(typecode.contentTypeCode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ + +$else$ +printf("$name$: \n"); +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $if(ctx.generateTypesC)$ + $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ + $else$ + $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ + $endif$ +} +$endif$ +>> + +map_print(ctx, typecode, name, originName, p, loopvar) ::= << +printf("$name$_size: 0x%" PRIx64 "\n", (uint64_t)topic->$name$$p$.size()); +for (auto it_$loopvar$ : topic->$name$$p$) +{ + printf("-"); + $map_key_print(ctx=ctx, typecode=typecode.keyTypeCode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ + printf(" : "); + $map_value_print(ctx=ctx, typecode=typecode.valueTypeCode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, p="", loopvar=loopvar)$ + printf("\n"); +} +>> + + + +map_key_print(ctx, typecode, name, originName, p, loopvar) ::= << +$if(typecode.isType_d)$ + $if(typecode.isWStringType)$ + printf("[%S]", (it_$loopvar$.first).c_str()); + $elseif(ctx.generateTypesC)$ + printf("[%s]", (it_$loopvar$.first)); + $else$ + printf("[%s]", (it_$loopvar$.first).c_str()); + $endif$ +$elseif(typecode.isSequenceType)$ +$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isType_f)$ +$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$elseif(typecode.isType_10)$ + $map_key_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.primitive)$ + printf("[$typecode$]"); +$else$ + printf("[$typecode$]"); +$endif$ +>> + +map_value_print(ctx, typecode, name, originName, p, loopvar) ::= << +$if(typecode.isType_d)$ + $if(typecode.isWStringType)$ + printf("[%S]", (topic->$name$$p$).c_str()); + $elseif(ctx.generateTypesC)$ + printf("[%s]", (topic->$name$$p$)); + $else$ + printf("[%s]", (topic->$name$$p$).c_str()); + $endif$ + +$elseif(typecode.isSequenceType)$ +$sequence_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isType_f)$ +$array_print(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$elseif(typecode.isType_10)$ + $map_value_print(ctx=ctx, typecode=typecode.contentTypeCode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.primitive)$ + printf("[$typecode$]"); +$else$ + printf("[$typecode$]"); +$endif$ +>> + +array_print(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << +$if(rest(dimensions))$ +printf("$name$: \n"); +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_print(ctx=ctx, typecode=typecode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ +} +$elseif(typecode.contentTypeCode.primitive)$ +printf("$name$: "); +$print_array(name=name, p=p, loopvar=loopvar)$ +$elseif(typecode.contentTypeCode.isType_d)$ +printf("$name$: \n"); +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ +} + +$elseif(typecode.isMapType)$ +$map_print(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ + +$else$ +printf("$name$: \n"); +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + $array_member_print(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ +} +$endif$ +>> + +print_sequence(name, p, loopvar) ::= << +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + printf("%" PRIx64 " ", (uint64_t)topic->$name$$p$$if(ctx.generateTypesC)$.value()$endif$[$loopvar$]); +} +printf("\n"); +>> + +print_array(name, p, loopvar) ::= << +for(int $loopvar$ = 0; $loopvar$ < topic->$name$$p$.size(); ++$loopvar$) +{ + printf("%" PRIx64 " ", (uint64_t)topic->$name$$p$[$loopvar$]); +} +printf("\n"); +>> + +// ======================================================================================== +// COMPARISION +// ======================================================================================== +member_comparision(ctx, typecode, name, originName, optional) ::= << +$if(typecode.primitive)$ +if (topic_a->$name$() != topic_b->$name$()) return 0; +$elseif(typecode.isType_d)$ +$if(typecode.isStringType)$ +$if(ctx.generateTypesC)$ +if (strncmp(topic_a->$name$(), topic_b->$name$(), strlen(topic_b->$name$())) != 0) return 0; +$else$ +if (topic_a->$name$() != topic_b->$name$()) return 0; +$endif$ +$else$ +if (topic_a->$name$() != topic_b->$name$()) return 0; +$endif$ +$elseif(typecode.isType_10)$ +$member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, optional=optional)$ +$elseif(typecode.isSequenceType)$ +$if(optional)$ +if(topic_a->$name$().has_value()) +{ +$endif$ +$sequence_comparision(ctx=ctx, typecode=typecode, name=name, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$if(optional)$ +} +else +{ + if (topic_a->$name$().has_value() != topic_b->$name$().has_value()) return 0; +} +$endif$ +$elseif(typecode.isMapType)$ +$if(optional)$ +if(topic_a->$name$().has_value()) +{ +$endif$ +$map_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$if(optional)$ +} +else +{ + if (topic_a->$name$().has_value() != topic_b->$name$().has_value()) return 0; +} +$endif$ +$elseif(typecode.isType_f)$ +$if(optional)$ +if(topic_a->$name$().has_value()) +{ +$endif$ +$array_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$ +$if(optional)$ +} +else +{ + if (topic_a->$name$().has_value() != topic_b->$name$().has_value()) return 0; +} +$endif$ +$else$ +$if(optional)$ +if(topic_a->$name$().has_value()) +{ +$endif$ +if (!$typecode.scope$::compare$typecode.name$(&topic_a->$name$()$if(optional)$.value()$endif$, &topic_b->$name$()$if(optional)$.value()$endif$)) return 0; +$if(optional)$ +} +else +{ + if (topic_a->$name$().has_value() != topic_b->$name$().has_value()) return 0; +} +$endif$ +$endif$ +>> + +array_member_comparision(ctx, typecode, name, originName, loopvar) ::= << +$if(typecode.primitive)$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$elseif(typecode.isType_d)$ +$if(typecode.isStringType)$ +$if(ctx.generateTypesC)$ +if (strncmp(topic_a->$name$, topic_b->$name$, strlen(topic_b->$name$)) != 0) return 0; +$else$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$endif$ +$else$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$endif$ +$elseif(typecode.isType_10)$ +$array_member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ +$elseif(typecode.isSequenceType)$ +$sequence_comparision(ctx=ctx, typecode=typecode, name=name, p="", loopvar=loopvar)$ +$elseif(typecode.isMapType)$ +$map_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, p="", loopvar=loopvar)$ +$elseif(typecode.isType_f)$ +$array_comparision(ctx=ctx, typecode=typecode, name=name, originName=originName, dimensions=typecode.dimensions, p="", loopvar=loopvar)$ +$else$ +if (!$typecode.scope$::compare$typecode.name$(&topic_a->$name$, &topic_b->$name$)) return 0; +$endif$ +>> + +map_member_comparision(ctx, typecode, name, originName, loopvar) ::= << +$if(typecode.valueTypeCode.primitive)$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$elseif(typecode.valueTypeCode.isType_d)$ +$if(typecode.valueTypeCode.isStringType)$ +$if(ctx.generateTypesC)$ +if (strncmp(topic_a->$name$, topic_b->$name$, strlen(topic_b->$name$)) != 0) return 0; +$else$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$endif$ +$else$ +if (topic_a->$name$ != topic_b->$name$) return 0; +$endif$ +$elseif(typecode.isType_10)$ +$map_member_comparision(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName, loopvar=loopvar)$ +$elseif(typecode.valueTypeCode.isSequenceType)$ +$sequence_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, p="", loopvar=loopvar)$ +$elseif(typecode.valueTypeCode.isMapType)$ +$map_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, originName=originName, p="", loopvar=ctx.nextLoopVarName)$ +$elseif(typecode.valueTypeCode.isType_f)$ +$array_comparision(ctx=ctx, typecode=typecode.valueTypeCode, name=name, originName=originName, dimensions=typecode.valueTypeCode.dimensions, p="", loopvar=loopvar)$ +$else$ +if (!$typecode.valueTypeCode.scope$::compare$typecode.valueTypeCode.name$(&topic_a->$name$, &topic_b->$name$)) return 0; +$endif$ +>> + +sequence_comparision(ctx, typecode, name, p, loopvar) ::= << +for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) +{ + $if(ctx.generateTypesC)$ + $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=[p, ".value()"], loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ + $else$ + $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=ctx.nextLoopVarName)$ + $endif$ +} +>> + +map_comparision(ctx, typecode, name, originName, p, loopvar) ::= << +for(auto it_$loopvar$ : topic_a->$name$$p$) +{ + $map_member_comparision(ctx=ctx, typecode=typecode, name=itMapName(name=name, p=p, loopvar=loopvar), originName=originName, loopvar=loopvar)$ +} +>> + +array_comparision(ctx, typecode, name, originName, dimensions, p, loopvar) ::= << +$if(rest(dimensions))$ +for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) +{ + $array_comparision(ctx=ctx, typecode=typecode, name=indexName(name=name, loopvar=loopvar, p=p), originName=originName, dimensions=rest(dimensions), p="", loopvar=ctx.nextLoopVarName)$ +} +$elseif(typecode.contentTypeCode.primitive)$ +if (memcmp(&topic_a->$name$$p$, &topic_b->$name$$p$, sizeof(topic_a->$name$$p$)) != 0) return 0; +$elseif(typecode.contentTypeCode.isType_d)$ +for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) +{ + $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ +} +$else$ +for(int $loopvar$ = 0; $loopvar$ < topic_a->$name$$p$.size(); ++$loopvar$) +{ + $array_member_comparision(ctx=ctx, typecode=typecode.contentTypeCode, name=indexName(name=name, p=p, loopvar=loopvar), originName=name, loopvar=ctx.nextLoopVarName)$ +} +$endif$ +>> + +// ======================================================================================== +// AUXILIAR +// ======================================================================================== +indexName(name, p, loopvar) ::= <<$name$$p$[$loopvar$]>> +mapName(name, p, key1, key2) ::= <<$name$$p$[$key1$Key$key2$]>> +itMapName(name, p, loopvar) ::= <<$name$$p$[it_$loopvar$.first]>> + +// ======================================================================================== +// C STRING +// ======================================================================================== +// TODO: Add more cases if tests evolve... +free_member_string(ctx, typecode, name) ::= << +$if(ctx.generateTypesC)$ +$if(typecode.isType_a)$ +free_string$typecode.name$(&topic->$name$()); +$elseif(typecode.isSequenceType)$$if(typecode.contentTypeCode.isType_d)$ +char** $name$_buffer = topic->$name$().value(true); +delete[] $name$_buffer; +$endif$$endif$$endif$ +>> + +optional_suffix(p, optional) ::= <<$if(optional)$$p$.value()$else$$p$$endif$>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationTestSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationTestSource.stg index 95d9768e..02009abc 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationTestSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationTestSource.stg @@ -14,6 +14,8 @@ group ProtocolHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "SerializationTest.cpp"], description=["This file contains serialization test code."])$ @@ -48,23 +50,31 @@ int main(void) >> -struct_type(ctx, parent, struct) ::= << +function_to_run(ctx, parent, struct, cdr_version, test_null_optional) ::= << functions_to_run.emplace_back([]() -> bool { - printf("\n========================================Testing $struct.name$ ========================================\n"); + std::cout << std::endl <<"======================================== Testing $struct.name$" << + (true == $test_null_optional$ ? " with a null optional" : "") << " using encoding " << + (eprosima::fastdds::dds::DataRepresentationId_t::XCDR_DATA_REPRESENTATION == $cdr_version$ ? "XCDRv1" : "XCDRv2") << + " ========================================" << std::endl; using eprosima::fastrtps::rtps::SerializedPayload_t; $if(struct.hasScope)$ using namespace $struct.scope$;$endif$ + $struct.name$PubSubType $struct.name$_type_support; $struct.name$ $struct.name$_serialization_topic; $struct.name$ $struct.name$_deserialization_topic; + g_$ctx.filename$_test_null_opt = $test_null_optional$; + initialize$struct.name$(&$struct.name$_serialization_topic); $struct.name$PubSubType pst; - uint32_t payloadSize = static_cast(pst.getSerializedSizeProvider(&$struct.name$_serialization_topic)()); + uint32_t payloadSize = static_cast(pst.getSerializedSizeProvider(&$struct.name$_serialization_topic, + $cdr_version$)()); SerializedPayload_t payload(payloadSize); - if (pst.serialize(&$struct.name$_serialization_topic, &payload) == 0) + if (pst.serialize(&$struct.name$_serialization_topic, &payload, + $cdr_version$) == 0) { return false; } @@ -74,11 +84,12 @@ functions_to_run.emplace_back([]() -> bool return false; } - uint32_t payloadOutSize = static_cast(pst.getSerializedSizeProvider(&$struct.name$_deserialization_topic)()); + uint32_t payloadOutSize = static_cast(pst.getSerializedSizeProvider(&$struct.name$_deserialization_topic, + $cdr_version$)()); int topic_equal = compare$struct.name$(&$struct.name$_serialization_topic, &$struct.name$_deserialization_topic); bool size_equal = payloadOutSize == payloadSize; - bool ge_than_max = ($struct.name$_serialization_topic.getMaxCdrSerializedSize() + 4)>= payloadSize; + bool ge_than_max = ($struct.name$_type_support.m_typeSize + 4)>= payloadSize; printf("\n"); printf("===== Before serialize: =====\n"); @@ -89,7 +100,7 @@ functions_to_run.emplace_back([]() -> bool printf("\n"); printf("SerializedPayload_t: \n"); printf("length: %d - %d\n", payloadSize, payload.length); - printf("max: %lu\n", $struct.name$_serialization_topic.getMaxCdrSerializedSize() + 4); + printf("max: %" PRIu32 "\n", $struct.name$_type_support.m_typeSize + 4); if (500 > payloadSize) { printf("data: "); @@ -101,8 +112,8 @@ functions_to_run.emplace_back([]() -> bool } uint32_t type_size = sizeof($struct.name$); - printf("Topic $struct.name$ size: %s => payloadIn: %d, payloadOut: %d, type: %d, max_size: %lu\n", size_equal ? "OK" : "ERROR", payloadSize, payloadOutSize, type_size, - $struct.name$_serialization_topic.getMaxCdrSerializedSize() + 4); + printf("Topic $struct.name$ size: %s => payloadIn: %d, payloadOut: %d, type: %d, max_size: %" PRIu32 "\n", size_equal ? "OK" : "ERROR", payloadSize, payloadOutSize, type_size, + $struct.name$_type_support.m_typeSize + 4); printf("Topic $struct.name$ comparation: %s\n", topic_equal ? "OK" : "ERROR"); $if((ctx.generateTypesC))$ @@ -119,6 +130,27 @@ functions_to_run.emplace_back([]() -> bool >> fwd_decl(ctx, parent, type) ::= <<>> + +struct_type(ctx, parent, struct) ::= << +$function_to_run(ctx=ctx, parent=parent, struct=struct, + cdr_version="eprosima::fastdds::dds::DataRepresentationId_t::XCDR_DATA_REPRESENTATION", + test_null_optional="false")$ + +$function_to_run(ctx=ctx, parent=parent, struct=struct, + cdr_version="eprosima::fastdds::dds::DataRepresentationId_t::XCDR2_DATA_REPRESENTATION", + test_null_optional="false")$ + +$if (struct.containsOptional)$ +$function_to_run(ctx=ctx, parent=parent, struct=struct, + cdr_version="eprosima::fastdds::dds::DataRepresentationId_t::XCDR_DATA_REPRESENTATION", + test_null_optional="true")$ + +$function_to_run(ctx=ctx, parent=parent, struct=struct, + cdr_version="eprosima::fastdds::dds::DataRepresentationId_t::XCDR2_DATA_REPRESENTATION", + test_null_optional="true")$ +$endif$ +>> + union_type(ctx, parent, union) ::= <<>> enum_type(ctx, parent, enum) ::= <<>> @@ -134,3 +166,5 @@ annotation(ctx, annotation) ::= <<>> module(ctx, parent, module, definition_list) ::= <<>> definition_list(definitions) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg index e115d685..60591010 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg @@ -28,29 +28,29 @@ if(POLICY CMP0086) cmake_policy(SET CMP0086 NEW) endif() -$solution.projects : {$subproject_compiler(project=it)$}; separator="\n"$ +$solution.projects : { project | $subproject_compiler(project)$}; separator="\n"$ >> subproject_compiler(project) ::= << ############################################################################### -# Library for types defined in $it.name$ IDL +# Library for types defined in $project.name$ IDL ############################################################################### -message(STATUS "Configuring python wrapper for types in $it.name$...") +message(STATUS "Configuring python wrapper for types in $project.name$...") ############################################################################### # Type library on C++ -project($it.name$) +project($project.name$) find_package(fastcdr REQUIRED) find_package(fastrtps REQUIRED) set(\${PROJECT_NAME}_FILES - $it.name$.cxx - $it.name$PubSubTypes.cxx + $project.name$.cxx + $project.name$PubSubTypes.cxx ) include_directories() @@ -79,7 +79,7 @@ set(PYTHON_LIBRARIES \${Python3_LIBRARIES}) include_directories(\${PYTHON_INCLUDE_PATH}) set(\${PROJECT_NAME}_MODULE - $it.name$Wrapper + $project.name$Wrapper ) set(\${PROJECT_NAME}_MODULE_FILES @@ -96,7 +96,7 @@ include_directories( \${PROJECT_SOURCE_DIR} ) -set_property(SOURCE \${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$") +set_property(SOURCE \${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : { ns | $ns$}; separator="/"$") SWIG_ADD_LIBRARY(\${\${PROJECT_NAME}_MODULE} TYPE SHARED @@ -111,11 +111,11 @@ target_link_libraries(\${\${PROJECT_NAME}_MODULE} Python3::Module fastrtps \${PROJECT_NAME} - $project.dependencies : {$it$}; separator=" "$ + $project.dependencies : { dep | $dep$}; separator=" "$ ) set_target_properties(\${\${PROJECT_NAME}_MODULE} - PROPERTIES LIBRARY_OUTPUT_DIRECTORY "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$" + PROPERTIES LIBRARY_OUTPUT_DIRECTORY "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : { ns | $ns$}; separator="/"$" ) @@ -137,8 +137,8 @@ install(TARGETS \${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$) +install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : { ns | $ns$}; separator="/"$) get_property(support_files TARGET \${\${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$) +install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : { ns | $ns$}; separator="/"$) >> diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg similarity index 92% rename from src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectHeader.stg rename to src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg index 2c6dd9e1..cd6baba3 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg @@ -14,8 +14,10 @@ group TypeObjectHeader; +import "eprosima.stg" + main(ctx, definitions) ::= << -$fileHeader(file=[ctx.filename, "TypeObject.h"], description=["This header file contains the declaration of the described types in the IDL file."])$ +$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObject.h"], description=["This header file contains the declaration of the described types in the IDL file."])$ #ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_H_ #define _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_H_ @@ -114,9 +116,9 @@ eProsima_user_DllExport const TypeObject* GetComplete$annotation.name$Object(); namespace $annotation.name$ { -$annotation.enums : {$enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ +$annotation.enums : { it | $enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ -$annotation.typeDefs : {$typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ +$annotation.typeDefs : { it | $typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ } >> @@ -133,4 +135,6 @@ $definitions; separator="\n"$ const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + /***** Utils *****/ diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg similarity index 86% rename from src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectSource.stg rename to src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg index 7bc8cd01..f31975f5 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypeObjectSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg @@ -14,8 +14,10 @@ group TypeObjectSource; +import "eprosima.stg" + main(ctx, definitions) ::= << -$fileHeader(file=[ctx.filename, "TypeObject.cpp"], description=["This source file contains the definition of the described types in the IDL file."])$ +$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObject.cpp"], description=["This source file contains the definition of the described types in the IDL file."])$ #ifdef _WIN32 // Remove linker warning LNK4221 on Visual Studio @@ -35,6 +37,7 @@ namespace { char dummy; } #include $if(ctx.cdr)$ #include +#include $endif$ $if(ctx.fastcdr)$ @@ -89,26 +92,26 @@ $endif$ register_annotation_types(annotation) ::= << -$annotation.enums : {$register_annotation_enum(it)$}; separator="\n"$ +$annotation.enums : { it | $register_annotation_enum(it)$}; separator="\n"$ -$annotation.typeDefs : {$register_annotation_typedef(it)$}; separator="\n"$ +$annotation.typeDefs : { it | $register_annotation_typedef(it)$}; separator="\n"$ >> register_annotation_enum(enum) ::= << -factory->add_type_object("$enum.name$", $if(object.hasScope)$$object.scope$::$endif$Get$enum.name$Identifier(true), - $if(object.hasScope)$$object.scope$::$endif$Get$enum.name$Object(true)); -factory->add_type_object("$enum.name$", $if(object.hasScope)$$object.scope$::$endif$Get$enum.name$Identifier(false), - $if(object.hasScope)$$object.scope$::$endif$Get$enum.name$Object(false)); +factory->add_type_object("$enum.name$", $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Identifier(true), + $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Object(true)); +factory->add_type_object("$enum.name$", $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Identifier(false), + $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Object(false)); >> register_annotation_typedef(typedef) ::= << factory->add_type_object("$typedef.name$", - $if(object.hasScope)$$object.scope$::$endif$Get$typedef.name$Identifier(true), - $if(object.hasScope)$$object.scope$::$endif$Get$typedef.name$Object(true)); + $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Identifier(true), + $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Object(true)); factory->add_type_object("$typedef.name$", - $if(object.hasScope)$$object.scope$::$endif$Get$typedef.name$Identifier(false), - $if(object.hasScope)$$object.scope$::$endif$Get$typedef.name$Object(false)); + $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Identifier(false), + $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Object(false)); >> module(ctx, parent, module, definition_list) ::= << @@ -167,17 +170,19 @@ const TypeObject* GetMinimal$annotation.name$Object() TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalAnnotationType::getCdrSerializedSize(type_object->minimal().annotation_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().annotation_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -218,17 +223,19 @@ const TypeObject* GetComplete$annotation.name$Object() TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteAnnotationType::getCdrSerializedSize(type_object->complete().annotation_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().annotation_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -244,9 +251,9 @@ const TypeObject* GetComplete$annotation.name$Object() namespace $annotation.name$ { -$annotation.enums : {$enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ +$annotation.enums : { it |$enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ -$annotation.typeDefs : {$typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ +$annotation.typeDefs : { it |$typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ } // $annotation.name$ namespace >> @@ -297,6 +304,8 @@ export_list(exports) ::= <<>> const_decl(ctx, parent, const) ::= <<>> +fwd_decl(ctx, parent, type) ::= <<>> + typedef_decl(ctx, parent, typedefs) ::= << const TypeIdentifier* Get$typedefs.name$Identifier(bool complete) { @@ -375,17 +384,19 @@ const TypeObject* GetMinimal$typedefs.name$Object() TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalAliasType::getCdrSerializedSize(type_object->minimal().alias_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().alias_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -457,17 +468,19 @@ const TypeObject* GetComplete$typedefs.name$Object() TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteAliasType::getCdrSerializedSize(type_object->complete().alias_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().alias_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -541,17 +554,19 @@ const TypeObject* GetMinimal$enum.name$Object() TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalEnumeratedType::getCdrSerializedSize(type_object->minimal().enumerated_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().enumerated_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -601,17 +616,17 @@ const TypeObject* GetComplete$enum.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().enumerated_type().header().detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -621,17 +636,19 @@ const TypeObject* GetComplete$enum.name$Object() TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteEnumeratedType::getCdrSerializedSize(type_object->complete().enumerated_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().enumerated_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -692,17 +709,17 @@ $object.annotationList:{ ann | for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); - } + \} };separator="\n"$ $endif$ cel_$object.name$.detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -763,22 +780,24 @@ const TypeObject* GetMinimal$struct.name$Object() // TODO Inheritance //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL); //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13]; - $struct.inheritances:{$minimal_struct_inheritance(it)$}; separator="\n"$ + $struct.inheritances:{ it | $minimal_struct_inheritance(it)$}; separator="\n"$ TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalStructType::getCdrSerializedSize(type_object->minimal().struct_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().struct_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -816,7 +835,7 @@ const TypeObject* GetComplete$struct.name$Object() // Header type_object->complete().struct_type().header().detail().type_name("$struct.name$"); // TODO inheritance - $struct.inheritances:{$complete_struct_inheritance(it)$}; separator="\n"$ + $struct.inheritances:{ it | $complete_struct_inheritance(it)$}; separator="\n"$ $if(struct.annotationList)$ $struct.annotationList:{ ann | @@ -832,34 +851,36 @@ const TypeObject* GetComplete$struct.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().struct_type().header().detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteStructType::getCdrSerializedSize(type_object->complete().struct_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().struct_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -946,17 +967,17 @@ $object.annotationList:{ ann | for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); - } + \} };separator="\n"$ $endif$ cst_$object.name$.detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -1033,17 +1054,19 @@ const TypeObject* GetMinimal$union.name$Object() TypeIdentifier* identifier = new TypeIdentifier(); identifier->_d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalUnionType::getCdrSerializedSize(type_object->minimal().union_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().union_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1100,17 +1123,17 @@ const TypeObject* GetComplete$union.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().union_type().discriminator().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -1134,34 +1157,36 @@ const TypeObject* GetComplete$union.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().union_type().header().detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ TypeIdentifier* identifier = new TypeIdentifier(); identifier->_d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteUnionType::getCdrSerializedSize(type_object->complete().union_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().union_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1249,17 +1274,17 @@ $object.annotationList:{ ann | for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); - } + \} };separator="\n"$ $endif$ cst_$object.name$.detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -1314,17 +1339,19 @@ const TypeObject* GetMinimal$bitmask.name$Object() TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalBitmaskType::getCdrSerializedSize(type_object->minimal().bitmask_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().bitmask_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1373,17 +1400,17 @@ const TypeObject* GetComplete$bitmask.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().bitmask_type().header().detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -1394,17 +1421,19 @@ const TypeObject* GetComplete$bitmask.name$Object() TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteBitmaskType::getCdrSerializedSize(type_object->complete().bitmask_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().bitmask_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1486,18 +1515,18 @@ $object.annotationList:{ ann | for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); - } + \} };separator="\n"$ $endif$ cbf_$object.name$.detail().ann_custom().push_back(ann); - } -} + \} +\} }; separator="\n"$ $endif$ @@ -1547,22 +1576,24 @@ const TypeObject* GetMinimal$bitset.name$Object() $bitset.bitfields:{ member | $minimal_bitfield(ctx=ctx, object=member)$}; separator="\n"$ - $bitset.parents:{$minimal_bitset_inheritance(it)$}; separator="\n"$ + $bitset.parents:{ it | $minimal_bitset_inheritance(it)$}; separator="\n"$ TypeIdentifier identifier; identifier._d(EK_MINIMAL); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - MinimalBitsetType::getCdrSerializedSize(type_object->minimal().bitset_type()) + 4)); + calculator.calculate_serialized_size(type_object->minimal().bitset_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1609,17 +1640,17 @@ const TypeObject* GetComplete$bitset.name$Object() for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); -} +\} };separator="\n"$ $endif$ type_object->complete().bitset_type().header().detail().ann_custom().push_back(ann); -} +\} }; separator="\n"$ $endif$ @@ -1627,22 +1658,24 @@ const TypeObject* GetComplete$bitset.name$Object() $bitset.bitfields:{ member | $complete_bitfield(ctx=ctx, object=member)$}; separator="\n"$ - $bitset.parents:{$complete_bitset_inheritance(it)$}; separator="\n"$ + $bitset.parents:{ it | $complete_bitset_inheritance(it)$}; separator="\n"$ TypeIdentifier identifier; identifier._d(EK_COMPLETE); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; SerializedPayload_t payload(static_cast( - CompleteBitsetType::getCdrSerializedSize(type_object->complete().bitset_type()) + 4)); + calculator.calculate_serialized_size(type_object->complete().bitset_type(), current_alignment) + 4)); eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. - payload.encapsulation = CDR_LE; + fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - type_object->serialize(ser); - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + ser << *type_object; + payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length MD5 objectHash; objectHash.update((char*)payload.data, payload.length); objectHash.finalize(); @@ -1752,18 +1785,18 @@ $object.annotationList:{ ann | for(int i = 0; i < 4; ++i) { annParam.paramname_hash()[i] = message_hash.digest[i]; - } + \} AnnotationParameterValue paramValue; paramValue._d($annval.typecode.typeIdentifier$); paramValue.from_string("$annval.value$"); annParam.value(paramValue); ann.param_seq().push_back(annParam); - } + \} };separator="\n"$ $endif$ cbf_$object.name$.detail().ann_custom().push_back(ann); - } -} + \} +\} }; separator="\n"$ $endif$ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg new file mode 100644 index 00000000..e7b46369 --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg @@ -0,0 +1,98 @@ +// Copyright 2023 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 TypesCdrAuxHeader; + +import "eprosima.stg" + +main(ctx, definitions, extensions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "CdrAux.hpp"], description=["This source file contains some definitions of CDR related functions."])$ + +#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_HPP_ +#define _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_HPP_ + +#include "$ctx.filename$.h" + +$if(ctx.anyCdr)$ +$ctx.types:{ type | $if(type.inScope)$$if(type.typeCode.isStructType)$ +constexpr uint32_t $type.typeCode.cScopedname$_max_cdr_typesize {$type.typeCode.maxSerializedSize$UL\}; +constexpr uint32_t $type.typeCode.cScopedname$_max_key_cdr_typesize {$type.typeCode.maxKeySerializedSize$UL\}; +$endif$$endif$ +}; separator="\n"$ +$endif$ + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +$definitions; separator="\n"$ + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_HPP_ +>> + +module(ctx, parent, module, definition_list) ::= << +$definition_list$ +>> + +definition_list(definitions) ::= << +$definitions; separator="\n"$ + +>> + +annotation(ctx, annotation) ::= <<>> + +interface(ctx, parent, interface, export_list) ::= << +$export_list$ +>> + +export_list(exports) ::= << +$exports; separator="\n"$ + +>> + +fwd_decl(ctx, parent, type) ::= <<>> + +exception(ctx, parent, exception) ::= <<>> + +operation(ctx, parent, operation, param_list) ::= <<>> + +param_list(parameters) ::= <<>> + +param(parameter) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> + +typedef_decl(ctx, parent, typedefs) ::= <<>> + +struct_type(ctx, parent, struct, extensions) ::= << +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const $struct.scopedname$& data); + +>> + +bitset_type(ctx, parent, bitset) ::= <<>> + +public_bitfield_definition(member) ::= <<>> + +union_type(ctx, parent, union) ::= <<>> + +enum_type(ctx, parent, enum) ::= <<>> + +bitmask_type(ctx, parent, bitmask) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg new file mode 100644 index 00000000..6695b44d --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg @@ -0,0 +1,324 @@ +// Copyright 2023 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 TypesCdrAuxHeader; + +import "eprosima.stg" + +main(ctx, definitions, extensions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "CdrAux.ipp"], description=["This source file contains some declarations of CDR related functions."])$ + +#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_IPP_ +#define _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_IPP_ + +#include "$ctx.filename$CdrAux.hpp" + +$if(ctx.cdr)$ +#include +#include + +$endif$ + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +$definitions; separator="\n"$ + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$CDRAUX_IPP_ +>> + +module(ctx, parent, module, definition_list) ::= << +$definition_list$ +>> + +definition_list(definitions) ::= << +$definitions; separator="\n"$ + +>> + +annotation(ctx, annotation) ::= <<>> + +interface(ctx, parent, interface, export_list) ::= << +$export_list$ +>> + +export_list(exports) ::= << +$exports; separator="\n"$ + +>> + +fwd_decl(ctx, parent, type) ::= <<>> + +exception(ctx, parent, exception) ::= <<>> + +operation(ctx, parent, operation, param_list) ::= <<>> + +param_list(parameters) ::= <<>> + +param(parameter) ::= <<>> + +const_decl(ctx, parent, const) ::= <<>> + +typedef_decl(ctx, parent, typedefs) ::= <<>> + +struct_type(ctx, parent, struct, extensions) ::= << +$if(ctx.anyCdr)$ +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const $struct.scopedname$& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + $if(struct.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ : + $if(struct.annotationFinal || struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$, + current_alignment)}; + + + $struct.allIdentifiedMembers : { member | $if(!member.value.annotationNonSerialized)$ + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($member.key$), + data.$member.value.name$(), current_alignment); + $endif$}; separator="\n"$ + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} +$endif$ + +$if(ctx.cdr)$ +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const $struct.scopedname$& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + $if(struct.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ : + $if(struct.annotationFinal || struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$); + + scdr$struct.allIdentifiedMembers : { member | $if(!member.value.annotationNonSerialized)$ + << eprosima::fastcdr::MemberId($member.key$) << data.$member.value.name$() + $endif$ + }; separator=""$; + + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + $struct.scopedname$& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + $if(struct.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ : + $if(struct.annotationFinal || struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + $struct.allIdentifiedMembers : { member | + case $member.key$: + $if(!member.value.annotationNonSerialized)$ + dcdr \>> data.$member.value.name$(); + $endif$ + break; + }; separator="\n"$ + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const $struct.scopedname$& data) +{ + static_cast(scdr); + static_cast(data); + $if(struct.hasKey)$ + $struct.members : { member | + $if(member.annotationKey)$ + $if(member.typecode.isStructType)$ + $if(member.typecode.hasKey)$ + serialize_key(scdr, data.$member.name$()); + $else$ + scdr << data.$member.name$(); + $endif$ + $else$ + scdr << data.$member.name$(); + $endif$ + $endif$ + }; separator="\n"$ + $endif$ +} + +$endif$ + +>> + +bitset_type(ctx, parent, bitset) ::= << +$if(ctx.anyCdr)$ +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const $bitset.scopedname$& data, + size_t& current_alignment) +{ + return calculator.calculate_serialized_size(data.bitset(), current_alignment); +} +$endif$ + +$if(ctx.cdr)$ +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const $bitset.scopedname$& data) +{ + scdr << data.bitset(); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& dcdr, + $bitset.scopedname$& data) +{ + std::bitset<$bitset.fullBitSize$> bitset; + dcdr \>> bitset; + data.bitset(bitset); +} +$endif$ +>> + +public_bitfield_definition(member) ::= <<>> + +union_type(ctx, parent, union) ::= << +$if(ctx.anyCdr)$ +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const $union.scopedname$& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + $if(union.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2 $endif$ : + $if(union.annotationFinal || union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR $endif$, + current_alignment)}; + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), data._d(), + current_alignment); + + switch (data._d()) + { + $union.identifiedMembers:{ member | $if(member.value.printable)$$member.value.labels:{ label |case $label$:}; separator="\n"$ + $if(member.value.default)$default:$endif$ + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($member.key$), + data.$member.value.name$(), current_alignment); + break; + $endif$ + }; separator="\n"$ + } + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +$endif$ + +$if(ctx.cdr)$ +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const $union.scopedname$& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + $if(union.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ : + $if(union.annotationFinal || union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$); + + scdr << eprosima::fastcdr::MemberId(0) << data._d(); + + switch (data._d()) + { + $union.identifiedMembers:{ member | $if(member.value.printable)$ + $member.value.labels:{ label |case $label$:}; separator="\n"$ + $if(member.value.default)$default:$endif$ + scdr << eprosima::fastcdr::MemberId($member.key$) << data.$member.value.name$(); + break; + $endif$ + }; separator="\n"$ + } + + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + $union.scopedname$& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + $if(union.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ : + $if(union.annotationFinal || union.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(union.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr \>> data._d(); + break; + default: + switch (data._d()) + { + $union.identifiedMembers:{ member | $if(member.value.printable)$ + $member.value.labels:{ label |case $label$:}; separator="\n"$ + $if(member.value.default)$default:$endif$ + dcdr \>> data.$member.value.name$(); + break; + $endif$ + }; separator="\n"$ + } + $if(!union.annotationMutable)$ret_value = false;$endif$ + break; + } + return ret_value; + }); +} +$endif$ +>> + +enum_type(ctx, parent, enum) ::= <<>> + +bitmask_type(ctx, parent, bitmask) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/VS.stg b/src/main/java/com/eprosima/fastdds/idl/templates/VS.stg index 2badae05..0d0603d9 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/VS.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/VS.stg @@ -17,13 +17,13 @@ group VS; solution(solution, example, configurations, generateJava, vsVersion) ::= << Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio $vsVersion$ -$solution.projects : {$projectReferences(solution=solution, project=it, example=example)$$if(it.containsInterfaces)$$projectReferencesExtra(solution=solution, project=it, example=example)$$endif$$if(generateJava)$$projectReferencesJava(solution=solution, project=it, example=example)$$endif$};separator="\n"$ +$solution.projects : { project | $projectReferences(solution=solution, project=project, example=example)$$if(project.containsInterfaces)$$projectReferencesExtra(solution=solution, project=project, example=example)$$endif$$if(generateJava)$$projectReferencesJava(solution=solution, project=project, example=example)$$endif$};separator="\n"$ Global $\t$GlobalSection(SolutionConfigurationPlatforms) = preSolution $configurations:{conf |$\t$$\t$$conf.name$|$conf.platform$ = $conf.name$|$conf.platform$};separator="\n"$ $\t$EndGlobalSection $\t$GlobalSection(ProjectConfigurationPlatforms) = postSolution -$solution.projects : {$projectConfigurationPlatforms(solution=solution, project=it, configurations=configurations)$}; separator="\n"$ +$solution.projects : { project | $projectConfigurationPlatforms(solution=solution, project=project, configurations=configurations, generateJava=generateJava)$}; separator="\n"$ $\t$EndGlobalSection $\t$GlobalSection(SolutionProperties) = preSolution $\t$$\t$HideSolutionNode = FALSE @@ -36,9 +36,9 @@ project(solution, project, example, configurations, vsVersion, toolset) ::= << - $configurations:{ - $it.name$ - $it.platform$ + $configurations:{ conf | + $conf.name$ + $conf.platform$ };separator="\n"$ @@ -47,9 +47,9 @@ project(solution, project, example, configurations, vsVersion, toolset) ::= << $project.name$Types - $configurations:{ - $if(it.dll)$DynamicLibrary$else$StaticLibrary$endif$ - $if(it.debug)$true$else$false$endif$ + $configurations : { conf | + $if(conf.dll)$DynamicLibrary$else$StaticLibrary$endif$ + $if(conf.debug)$true$else$false$endif$ false MultiByte v$toolset$ @@ -57,21 +57,21 @@ project(solution, project, example, configurations, vsVersion, toolset) ::= << - $configurations:{ + $configurations : { conf | };separator="\n"$ - $configurations:{ + $configurations : { conf | \$(Platform)\\\$(Configuration)\\\$(ProjectName)\ - .\\$if(!it.dll)$lib$else$bin$endif$\\$example$\ - $if(!it.dll)$lib$endif$\$(ProjectName)$if(it.debug)$d$endif$ + .\\$if(!conf.dll)$lib$else$bin$endif$\\$example$\ + $if(!conf.dll)$lib$endif$\$(ProjectName)$if(conf.debug)$d$endif$ };separator="\n"$ - $configurations:{ + $configurations : { conf | Level3 - $if(it.debug)$Disabled$else$MaxSpeed$endif$ - $solution.includes : {include |$include$;}$%(AdditionalIncludeDirectories) - $preprocessorDefs(conf=it)$;$if(it.dll)$;EPROSIMA_USER_DLL_EXPORT$endif$;$solution.defines : {define |$define$;}$%(PreprocessorDefinitions) + $if(conf.debug)$Disabled$else$MaxSpeed$endif$ + $solution.includes : { include | $include$;}$%(AdditionalIncludeDirectories) + $preprocessorDefs(conf=conf)$;$if(conf.dll)$EPROSIMA_ALL_DYN_LINK;EPROSIMA_USER_DLL_EXPORT$endif$;$solution.defines : {define |$define$;}$%(PreprocessorDefinitions) NotUsing @@ -80,14 +80,14 @@ project(solution, project, example, configurations, vsVersion, toolset) ::= << true - $project.dependencies : {dep |$if(!it.dll)$lib$endif$$dep$Types$if(it.debug)$d$endif$.lib}; separator=";"$;%(AdditionalDependencies) - $if(it.dll)$ + $project.dependencies : { dep |$if(!conf.dll)$lib$endif$$dep$Types$if(conf.debug)$d$endif$.lib}; separator=";"$;%(AdditionalDependencies) + $if(conf.dll)$ \$(TargetDir)\$(TargetName)\$(TargetExt) $solution.libraryPaths : {path |$path$;}$.\lib\\$example$;%(AdditionalLibraryDirectories) .\lib\\$example$\\\$(TargetName).lib $endif$ - $if(!it.dll)$ + $if(!conf.dll)$ \$(TargetDir)\$(TargetName)\$(TargetExt) @@ -109,9 +109,9 @@ projectPubSub(solution, project, example, configurations, vsVersion, toolset) :: - $configurations:{ - $it.name$ - $it.platform$ + $configurations : { conf | + $conf.name$ + $conf.platform$ };separator="\n"$ @@ -120,9 +120,9 @@ projectPubSub(solution, project, example, configurations, vsVersion, toolset) :: $project.name$PublisherSubscriber - $configurations:{ + $configurations : { conf | Application - $if(it.debug)$true$else$false$endif$ + $if(conf.debug)$true$else$false$endif$ false MultiByte v$toolset$ @@ -130,29 +130,29 @@ projectPubSub(solution, project, example, configurations, vsVersion, toolset) :: - $configurations:{ + $configurations : { conf | };separator="\n"$ - $configurations:{ + $configurations : { conf | \$(Platform)\\\$(Configuration)\\\$(ProjectName)\ .\bin\\$example$\ - \$(ProjectName)$if(it.debug)$d$endif$ + \$(ProjectName)$if(conf.debug)$d$endif$ };separator="\n"$ - $configurations:{ + $configurations : { conf | Level3 - $if(it.debug)$Disabled$else$MaxSpeed$endif$ + $if(conf.debug)$Disabled$else$MaxSpeed$endif$ $solution.includes : {include |$include$;}$%(AdditionalIncludeDirectories) - _WIN32_WINDOWS;WIN32;EPROSIMA_WIN32;$if(it.dll)$EPROSIMA_ALL_DYN_LINK;$endif$BOOST_ALL_DYN_LINK;$if(it.debug)$_DEBUG;$else$NDEBUG;$endif$ + _WIN32_WINDOWS;WIN32;EPROSIMA_WIN32;$if(conf.dll)$EPROSIMA_ALL_DYN_LINK;$endif$BOOST_ALL_DYN_LINK;$if(conf.debug)$_DEBUG;$else$NDEBUG;$endif$ NotUsing \$(TargetDir)\$(TargetName).pdb - $if(it.debug)$true$else$false$endif$ - $if(!it.dll)$lib$endif$$project.name$Types$if(it.debug)$d$endif$.lib;$if(!it.dll)$$it.staticLibraries : {sl|$sl$}; separator=";"$;Shlwapi.lib;Iphlpapi.lib;$endif$$project.dependencies : {dep |$if(!it.dll)$lib$endif$$dep$Types$if(it.debug)$d$endif$.lib}; separator=";"$;%(AdditionalDependencies) + $if(conf.debug)$true$else$false$endif$ + $if(!conf.dll)$lib$endif$$project.name$Types$if(conf.debug)$d$endif$.lib;$if(!conf.dll)$$conf.staticLibraries : {sl|$sl$}; separator=";"$;Shlwapi.lib;Iphlpapi.lib;$endif$$project.dependencies : {dep |$if(!conf.dll)$lib$endif$$dep$Types$if(conf.debug)$d$endif$.lib}; separator=";"$;%(AdditionalDependencies) \$(TargetDir)\$(TargetName)\$(TargetExt) $solution.libraryPaths : {path |$path$;}$.\lib\\$example$;%(AdditionalLibraryDirectories) @@ -173,9 +173,9 @@ projectJNI(solution, project, example, configurations, vsVersion, toolset) ::= < - $configurations:{ - $it.name$ - $it.platform$ + $configurations : { conf | + $conf.name$ + $conf.platform$ };separator="\n"$ @@ -184,9 +184,9 @@ projectJNI(solution, project, example, configurations, vsVersion, toolset) ::= < $project.name$PubSubJNI - $configurations:{ - $if(it.dll)$DynamicLibrary$else$StaticLibrary$endif$ - $if(it.debug)$true$else$false$endif$ + $configurations : { conf | + $if(conf.dll)$DynamicLibrary$else$StaticLibrary$endif$ + $if(conf.debug)$true$else$false$endif$ false MultiByte v$toolset$ @@ -194,22 +194,22 @@ projectJNI(solution, project, example, configurations, vsVersion, toolset) ::= < - $configurations:{ + $configurations : { conf | };separator="\n"$ - $configurations:{ + $configurations : { conf | \$(Platform)\\\$(Configuration)\\\$(ProjectName)\ - .\\$if(!it.dll)$lib$else$bin$endif$\\$example$\ - $if(!it.dll)$lib$endif$\$(ProjectName)$if(it.debug)$d$endif$ + .\\$if(!conf.dll)$lib$else$bin$endif$\\$example$\ + $if(!conf.dll)$lib$endif$\$(ProjectName)$if(conf.debug)$d$endif$ };separator="\n"$ - $configurations:{ + $configurations : { conf | Level3 - $if(it.debug)$Disabled$else$MaxSpeed$endif$ + $if(conf.debug)$Disabled$else$MaxSpeed$endif$ \$(JAVA_HOME)\include;\$(JAVA_HOME)\include\win32; $solution.includes : {include |$include$;}$%(AdditionalIncludeDirectories) - $preprocessorDefs(conf=it)$$if(it.dll)$;EPROSIMA_ALL_DYN_LINK;EPROSIMA_USER_DLL_EXPORT$endif$;BOOST_ALL_DYN_LINK;$solution.defines : {define |$define$;}$%(PreprocessorDefinitions) + $preprocessorDefs(conf=conf)$$if(conf.dll)$;EPROSIMA_ALL_DYN_LINK;EPROSIMA_USER_DLL_EXPORT$endif$;BOOST_ALL_DYN_LINK;$solution.defines : {define |$define$;}$%(PreprocessorDefinitions) NotUsing @@ -217,24 +217,24 @@ projectJNI(solution, project, example, configurations, vsVersion, toolset) ::= < true - $if(it.dll)$ - $if(it.debug)$$solution.librariesDebug : {library |$library$.lib;}$ + $if(conf.dll)$ + $if(conf.debug)$$solution.librariesDebug : {library |$library$.lib;}$ $else$$solution.libraries : {library |$library$.lib;}$ $endif$ $else$ - $if(it.debug)$$solution.librariesStaticDebug : {library |$library$.lib;}$ + $if(conf.debug)$$solution.librariesStaticDebug : {library |$library$.lib;}$ $else$$solution.librariesStatic : {library |$library$.lib;}$ $endif$ $endif$ - $project.dependencies : {dep |$if(!it.dll)$lib$endif$$dep$$if(it.debug)$d$endif$.lib;$if(!it.dll)$lib$endif$$dep$JNI$if(it.debug)$d$endif$.lib}; separator=";"$; - $if(!it.dll)$lib$endif$$project.name$$if(it.debug)$d$endif$.lib;$if(project.containsInterfaces)$$if(!it.dll)$lib$endif$$project.name$Client$if(it.debug)$d$endif$.lib;$endif$%(AdditionalDependencies) - $if(it.dll)$ + $project.dependencies : {dep |$if(!conf.dll)$lib$endif$$dep$$if(conf.debug)$d$endif$.lib;$if(!conf.dll)$lib$endif$$dep$JNI$if(conf.debug)$d$endif$.lib}; separator=";"$; + $if(!conf.dll)$lib$endif$$project.name$$if(conf.debug)$d$endif$.lib;$if(project.containsInterfaces)$$if(!conf.dll)$lib$endif$$project.name$Client$if(conf.debug)$d$endif$.lib;$endif$%(AdditionalDependencies) + $if(conf.dll)$ \$(TargetDir)\$(TargetName)\$(TargetExt) $solution.libraryPaths : {path |$path$;}$.\lib\\$example$;%(AdditionalLibraryDirectories) .\lib\\$example$\\\$(TargetName).lib $endif$ - $if(!it.dll)$ + $if(!conf.dll)$ \$(TargetDir)\$(TargetName)\$(TargetExt) @@ -353,9 +353,6 @@ preprocessorDefs(conf) ::= << WIN32;_CRT_SECURE_NO_WARNINGS;$if(conf.dll)$WIN32_LEAN_AND_MEAN;$endif$$if(conf.debug)$_DEBUG$else$NDEBUG$endif$ >> -preprocessorTypesLibDefs(conf) ::= << ->> - bigObjOption() ::= << /bigobj %(AdditionalOptions) >> @@ -372,22 +369,20 @@ bigObjOption() ::= << projectReferences(solution, project, example) ::= << Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$project.name$Types", "$project.name$Types-$example$.vcxproj", "{$project.guid$}" $\t$ProjectSection(ProjectDependencies) = postProject -$project.dependenciesGuids : {$\t$$\t${$it$} = {$it$}}; separator="\n"$ +$project.dependenciesGuids : { dep | $\t$$\t${$dep$\} = {$dep$\}}; separator="\n"$ $\t$EndProjectSection$\n$ EndProject $if(project.hasStruct)$ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$project.name$PublisherSubscriber", "$project.name$PublisherSubscriber-$example$.vcxproj", "{$project.exampleGuid$}" $\t$ProjectSection(ProjectDependencies) = postProject $\t$$\t${$project.guid$} = {$project.guid$} -$project.dependenciesGuids : {$\t$$\t${$it$} = {$it$}}; separator="\n"$ +$project.dependenciesGuids : { dep | $\t$$\t${$dep$\} = {$dep$\}}; separator="\n"$ $\t$EndProjectSection$\n$ EndProject $endif$ >> -projectReferencesExtra(solution, project, example) ::= << - ->> +projectReferencesExtra(solution, project, example) ::= <<>> projectReferencesJava(solution, project, example) ::= << @@ -401,7 +396,7 @@ $\t$$\t${$project.guid$} = {$project.guid$} $endif$ $if(project.dependenciesJNIGuids)$ -$project.dependenciesJNIGuids : {$\t$$\t${$it$} = {$it$}}; separator="\n"$ +$project.dependenciesJNIGuids : { dep | $\t$$\t${$dep$\} = {$dep$\}}; separator="\n"$ $endif$ $\t$EndProjectSection @@ -492,5 +487,5 @@ $if(conf.debug)$true$else$false$endif$ * Uses: */ runtimeLibrary(conf) ::= << -$if(it.dll)$$if(it.debug)$MultiThreadedDebugDLL$else$MultiThreadedDLL$endif$$else$$if(it.debug)$MultiThreadedDebug$else$MultiThreaded$endif$$endif$ +$if(conf.dll)$$if(conf.debug)$MultiThreadedDebugDLL$else$MultiThreadedDLL$endif$$else$$if(conf.debug)$MultiThreadedDebug$else$MultiThreaded$endif$$endif$ >> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg b/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg index 94009787..45c5e248 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg @@ -14,22 +14,27 @@ group eprosima; -paramTypeByValue(typecode) ::= << -$if(typecode.primitive)$ -$typecode.cppTypename$ -$else$ -const $typecode.cppTypename$& -$endif$ ->> +fileHeader(ctx, file, description) ::= << +// 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. -varDecl(variable, create) ::= << -$if(variable)$ -$if(variable.typecode.primitive)$ -$variable.typecode.cppTypename$ $variable.name$ = $variable.typecode.initialValue$; -$else$ -$variable.typecode.cppTypename$ $variable.name$; -$endif$ -$endif$ +/*! + * @file $file$ + * $description$ + * + * This file was generated by the tool $ctx.product$gen. + */ >> varDel(variable) ::= <<>> @@ -46,202 +51,4 @@ bitset_inherit_copy_init(parent) ::= <<$parent.scopedname$(x)>> bitset_inherit_move_init(parent) ::= <<$parent.scopedname$(std::move(x))>> -member_default_init(ctx, member, loopvar) ::= << -// $member.typecode.idlTypename$ m_$member.name$ -$if(member.typecode.forwarded)$ - m_$member.name$ = new $member.typecode.cppTypename$($if(member.annotationDefault)$$member.annotationDefaultValue$$endif$); -$else$ -$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.isStringType)$ -m_$member.name$ = $if(ctx.generateTypesC)$$if(member.annotationDefault)$$member.annotationDefaultValue$$else$nullptr$endif$$else$$if(member.annotationDefault)$$member.annotationDefaultValue$$else$$member.typecode.initialValue$$endif$$endif$; -$elseif(member.typecode.isWStringType)$ -m_$member.name$ = $if(ctx.generateTypesC)$$if(member.annotationDefault)$$member.annotationDefaultValue$$else$nullptr$endif$$else$$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$ -$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) ::= <> - -member_destructor(ctx, member) ::= <<$if(member.typecode.forwarded)$delete m_$member.name$;$elseif(ctx.generateTypesC)$$if(member.typecode.isStringType)$free(m_$member.name$); -m_$member.name$ = nullptr;$elseif(member.typecode.isType_f)$$if(member.typecode.contentTypeCode.isStringType)$$member_array_cstring_destructor(ctx=ctx, name=memberName(member.name), loopvar=ctx.newLoopVarName, dims=member.typecode.dimensions)$$endif$$endif$$endif$>> - -member_array_cstring_destructor(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$) -{ - $member_array_cstring_destructor(ctx=ctx, name=indexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims))$ -}$else$for (char* str : $name$) -{ - free(str); -}$endif$>> - -getTypenameOperation(operation, suffix, varname) ::= << -$varname$ = $operation.parent.scopedname$Plugin::$operation.name$$suffix$Plugin::get_typename(); ->> - -getTypenameInterface(interface, suffix, varname) ::= << -$varname$ = $interface.scopedname$$suffix$Plugin::get_typename(); ->> - -registerTypenameOperationAndCheck(operation, suffix, varname) ::= << -!$operation.parent.scopedname$Plugin::$operation.name$$suffix$Plugin::register_type(m_ddsTransport->getRTPSParticipant(), $varname$) ->> - -registerTypenameInterfaceAndCheck(interface, suffix, varname) ::= << -!$interface.scopedname$$suffix$Plugin::register_type(m_ddsTransport->getRTPSParticipant(), $varname$) ->> - -createDataCallback(operation, suffix) ::= << -(::transport::dds::Transport::Create_data)$operation.parent.scopedname$Plugin::$operation.name$$suffix$Plugin::create_data ->> - -createDataCallbackInterface(interface, suffix) ::= << -(::transport::dds::Transport::Create_data)$interface.scopedname$$suffix$Plugin::create_data ->> - -copyDataCallback(operation, suffix) ::= << -(::transport::dds::Transport::Copy_data)$operation.parent.scopedname$Plugin::$operation.name$$suffix$Plugin::copy_data ->> - -copyDataCallbackInterface(interface, suffix) ::= << -(::transport::dds::Transport::Copy_data)$interface.scopedname$$suffix$Plugin::copy_data ->> - -destroyDataCallback(operation, suffix) ::= << -(::transport::dds::Transport::Destroy_data)$operation.parent.scopedname$Plugin::$operation.name$$suffix$Plugin::destroy_data ->> - -destroyDataCallbackInterface(interface, suffix) ::= << -(::transport::dds::Transport::Destroy_data)$interface.scopedname$$suffix$Plugin::destroy_data ->> - -addParamToTopic(param, varname, isRequest) ::= << -$if(param)$ -$if(isRequest)$ -$varname$.$param.name$($param.name$); -$else$ -$if(param.typecode.primitive)$ -$varname$.$param.name$($param.name$); -$else$ -$varname$.$param.name$(std::move($param.name$)); -$endif$ -$endif$ -$endif$ ->> - -addExceptionMemberToTopic(exception, member, varname) ::= << -$if(member.typecode.primitive)$ -$varname$.unio().$exception.formatedScopedname$_ex().$member.name$(ex.$member.name$()); -$else$ -$varname$.unio().$exception.formatedScopedname$_ex().$member.name$(std::move(ex.$member.name$())); -$endif$ ->> - -extractParamFromTopic(param, varname, isReply) ::= << -$if(param.typecode.primitive)$ -$param.name$ = $varname$.$param.name$(); -$else$ -$param.name$ = std::move($varname$.$param.name$()); //TODO Probar que esto funciona. -$endif$ ->> - -extractExceptionMemberFromTopic(exception, member, varname) ::= << -$if(member.typecode.primitive)$ -ex.$member.name$($varname$.unio().$exception.formatedScopedname$_ex().$member.name$()); -$else$ -ex.$member.name$(std::move($varname$.unio().$exception.formatedScopedname$_ex().$member.name$())); -$endif$ ->> - -extractExceptionMemberFromTopicByInterface(exception, member, varname) ::= << -$if(member.typecode.primitive)$ -ex.$member.name$($varname$.$exception.formatedScopedname$_ex().$member.name$()); -$else$ -ex.$member.name$(std::move($varname$.$exception.formatedScopedname$_ex().$member.name$())); -$endif$ ->> - -copyHeaderInfo(reqvarname, repvarname) ::= << -$repvarname$._header().clientId().value_1() = $reqvarname$._header().clientId().value_1(); -$repvarname$._header().clientId().value_2() = $reqvarname$._header().clientId().value_2(); -$repvarname$._header().clientId().value_3() = $reqvarname$._header().clientId().value_3(); -$repvarname$._header().clientId().value_4() = $reqvarname$._header().clientId().value_4(); -$repvarname$._header().requestSequenceNumber() = $reqvarname$._header().requestSequenceNumber(); ->> - -setHeaderSuccess(varname) ::= << -$varname$._header().retCode(OPERATION_SUCCESSFUL); ->> - -setHeaderServerInternalException(varname) ::= << -$varname$._header().retCode(SERVER_INTERNAL_ERROR); -$varname$._header().retMsg(std::move(ex.what())); ->> - -getHeaderRetCode(varname) ::= << -$varname$._header().retCode() ->> - -getHeaderRetMsg(varname) ::= << -$varname$._header().retMsg() ->> - -interfaceUnionDiscriminator(varname) ::= << -$varname$.unio()._d() ->> - -interfaceUnionOperation(operation, varname) ::= << -$varname$.unio().$operation.name$() ->> - -replyUnionDiscriminator(varname) ::= << -$varname$.unio()._d() ->> - -replyUnionDiscriminatorByInterface(operation, varname) ::= << -$varname$.unio().$operation.name$()._d() ->> - -replyUnionData(varname, dataname) ::= << -$varname$.unio().$dataname$() ->> - -replyUnionDataByInterface(operation, varname, dataname) ::= << -$varname$.unio().$operation.name$().$dataname$() ->> - -eprosimaTypesBool() ::= <> - -/** NEEDED BY RTI TYPES **/ -charCasting() ::= <<>> - -unsetReply() ::= <<>> - -reqrepDestruction(type, reqrep, name, void) ::= <<>> - -varComplexInitializeT(typeName, name) ::= <<>> - -varComplexInitialize(variable) ::= <<>> - -varComplexDelT(typeName, name) ::= <<>> - -reqrepRefFinalize(type, reqrep, name) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/util/Utils.java b/src/main/java/com/eprosima/fastdds/util/Utils.java index 08f04d19..1821dd34 100644 --- a/src/main/java/com/eprosima/fastdds/util/Utils.java +++ b/src/main/java/com/eprosima/fastdds/util/Utils.java @@ -14,7 +14,7 @@ package com.eprosima.fastdds.util; -import org.antlr.stringtemplate.StringTemplate; +import org.stringtemplate.v4.ST; import java.io.*; @@ -74,7 +74,7 @@ public static String addFileSeparator(String directory) return returnedValue; } - public static boolean writeFile(String file, StringTemplate template, boolean replace) + public static boolean writeFile(String file, ST template, boolean replace) { boolean returnedValue = false; @@ -85,7 +85,7 @@ public static boolean writeFile(String file, StringTemplate template, boolean re if(!handle.exists() || replace) { FileWriter fw = new FileWriter(file); - String data = template.toString(); + String data = template.render(); fw.write(data, 0, data.length()); fw.close(); } diff --git a/src/test/java/com/eprosima/fastdds/FastDDSGenTest.java b/src/test/java/com/eprosima/fastdds/FastDDSGenTest.java index 6e5d4701..5bc21a09 100644 --- a/src/test/java/com/eprosima/fastdds/FastDDSGenTest.java +++ b/src/test/java/com/eprosima/fastdds/FastDDSGenTest.java @@ -28,6 +28,13 @@ private static boolean isUnix() @Test public void Context_getRelativeDir_Test() { + String absolute_idl_dir = isUnix() ? + "/home/testing/Prueba.idl" : "C:/Users/testing/Prueba.idl"; + String absolute_dir = isUnix() ? + "/home/testing/" : "C:/Users/testing/"; + String absolute_root_dir = isUnix() ? + "/home/" : "C:/Users/"; + { com.eprosima.idl.context.Context ctx = new com.eprosima.idl.context.Context( "Prueba.idl", new ArrayList()); @@ -72,23 +79,23 @@ public void Context_getRelativeDir_Test() { com.eprosima.idl.context.Context ctx = new com.eprosima.idl.context.Context( - "/home/testing/Prueba.idl", new ArrayList()); + absolute_idl_dir, new ArrayList()); assertEquals("", ctx.getRelativeDir(null)); } { com.eprosima.idl.context.Context ctx = new com.eprosima.idl.context.Context( - "/home/testing/Prueba.idl", new ArrayList()); + absolute_idl_dir, new ArrayList()); - assertEquals("", ctx.getRelativeDir("/home/testing/")); + assertEquals("", ctx.getRelativeDir(absolute_dir)); } { com.eprosima.idl.context.Context ctx = new com.eprosima.idl.context.Context( - "/home/testing/Prueba.idl", new ArrayList()); + absolute_idl_dir, new ArrayList()); - assertEquals("testing/", ctx.getRelativeDir("/home/")); + assertEquals("testing/", ctx.getRelativeDir(absolute_root_dir)); } } @@ -101,14 +108,20 @@ public void runTests() return; } + String list_tests_str = System.getProperty("list_tests"); + java.util.List list_tests = null; + + if (null != list_tests_str) + { + list_tests = java.util.Arrays.asList(list_tests_str.split(",", -1)); + } + //Configure idl tests TestManager tests = new TestManager(TestLevel.RUN, "share/fastddsgen/java/fastddsgen", INPUT_PATH, - OUTPUT_PATH, "CMake"); + OUTPUT_PATH, "CMake", list_tests); tests.addCMakeArguments("-DCMAKE_BUILD_TYPE=Debug"); tests.removeTests("basic_inner_types"); - - boolean testResult = tests.runTests(); System.exit(testResult ? 0 : -1); } diff --git a/thirdparty/dds-types-test b/thirdparty/dds-types-test index fda5e5b7..ebcd23cf 160000 --- a/thirdparty/dds-types-test +++ b/thirdparty/dds-types-test @@ -1 +1 @@ -Subproject commit fda5e5b7c7204b283e4e0eece8306684abb4abf1 +Subproject commit ebcd23cf57053f85380b58abc4b085e927bbae0d diff --git a/thirdparty/idl-parser b/thirdparty/idl-parser index be218309..e88ae80b 160000 --- a/thirdparty/idl-parser +++ b/thirdparty/idl-parser @@ -1 +1 @@ -Subproject commit be21830935b6d702cfcf32334d1f3327f6e43921 +Subproject commit e88ae80bf1ad5f962731110455d211823e8eb89c