Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use include header which will be used [20074] #272

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/fastddsgen.meta
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"names":
{
"fastrtps": {
"cmake-args": [
"-DEPROSIMA_BUILD_TESTS=ON"

]
},
"fastdds_python": {
"cmake-args": [
"-DBUILD_TESTING=ON"
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,36 @@ $fileHeader(ctx=ctx, file=[ctx.filename, ".hpp"], description=["This header file
#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_HPP_
#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_HPP_

$if(ctx.thereIsArray)$
#include <array>
$endif$
$if(ctx.thereIsBitset)$
#include <bitset>
$endif$
#include <cstdint>
$if(ctx.thereIsMap)$
#include <map>
$endif$
$if(ctx.thereIsString)$
#include <string>
$endif$
#include <utility>
$if(ctx.thereIsSequence)$
#include <vector>
$endif$

$if(ctx.thereIsString)$
#include <fastcdr/cdr/fixed_size_string.hpp>
$endif$
$if(ctx.thereIsExternalAnnotation)$
#include <fastcdr/xcdr/external.hpp>
$endif$
$if(ctx.thereIsOptionalAnnotation)$
#include <fastcdr/xcdr/optional.hpp>
$endif$
$if(ctx.thereIsUnion)$
#include <fastcdr/exceptions/BadParamException.h>
$endif$

$ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$

Expand Down
134 changes: 115 additions & 19 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public AliasTypeCode createAliasTypeCode(
@Override
public ArrayTypeCode createArrayTypeCode()
{
if (isInScopedFile())
{
there_is_at_least_one_array = true;
}
return new ArrayTypeCode();
}

Expand All @@ -170,6 +174,10 @@ public BitsetTypeCode createBitsetTypeCode(
String scope,
String name)
{
if (isInScopedFile())
{
there_is_at_least_one_bitset = true;
}
return new BitsetTypeCode(scope, name);
}

Expand All @@ -193,6 +201,10 @@ public EnumTypeCode createEnumTypeCode(
public MapTypeCode createMapTypeCode(
String maxsize)
{
if (isInScopedFile())
{
there_is_at_least_one_map = true;
}
return new MapTypeCode(maxsize, evaluate_literal(maxsize));
}

Expand All @@ -207,6 +219,10 @@ public PrimitiveTypeCode createPrimitiveTypeCode(
public SequenceTypeCode createSequenceTypeCode(
String maxsize)
{
if (isInScopedFile())
{
there_is_at_least_one_sequence = true;
}
return new SequenceTypeCode(maxsize, evaluate_literal(maxsize));
}

Expand All @@ -222,13 +238,21 @@ public StringTypeCode createStringTypeCode(
int kind,
String maxsize)
{
if (isInScopedFile())
{
there_is_at_least_one_string = true;
}
return new StringTypeCode(kind, maxsize, evaluate_literal(maxsize));
}

@Override
public StructTypeCode createStructTypeCode(
String name)
{
if (isInScopedFile())
{
there_is_at_least_one_struct = true;
}
return new StructTypeCode(getScope(), name);
}

Expand All @@ -237,6 +261,10 @@ public UnionTypeCode createUnionTypeCode(
String scope,
String name)
{
if (isInScopedFile())
{
there_is_at_least_one_union = true;
}
return new UnionTypeCode(scope, name);
}

Expand All @@ -246,6 +274,10 @@ public UnionTypeCode createUnionTypeCode(
String name,
TypeCode discriminatorTypeCode)
{
if (isInScopedFile())
{
there_is_at_least_one_union = true;
}
return new UnionTypeCode(scope, name, discriminatorTypeCode);
}

Expand Down Expand Up @@ -374,18 +406,54 @@ else if (content.getKind() == Kind.KIND_MAP)
typecodes.add(new SimpleEntry<String, TypeCode>(sequence.getCppTypename(), sequence));
}

public boolean isThereIsStructOrUnion()
public boolean isThereIsArray()
{
for (TypeDeclaration type : m_types.values())
{
if (type.getTypeCode() instanceof StructTypeCode ||
type.getTypeCode() instanceof UnionTypeCode)
{
return true;
}
}
return there_is_at_least_one_array;
}

return false;
public boolean isThereIsBitset()
{
return there_is_at_least_one_bitset;
}

public boolean isThereIsExternalAnnotation()
{
return there_is_at_least_one_external_annotation;
}

public boolean isThereIsMap()
{
return there_is_at_least_one_map;
}

public boolean isThereIsOptionalAnnotation()
{
return there_is_at_least_one_optional_annotation;
}

public boolean isThereIsSequence()
{
return there_is_at_least_one_sequence;
}

public boolean isThereIsString()
{
return there_is_at_least_one_string;
}

public boolean isThereIsStructure()
{
return there_is_at_least_one_struct;
}

public boolean isThereIsUnion()
{
return there_is_at_least_one_union;
}

public boolean isThereIsStructOrUnion()
{
return there_is_at_least_one_struct || there_is_at_least_one_union;
}

/*** Functions inherited from FastCDR Context ***/
Expand Down Expand Up @@ -554,15 +622,6 @@ public String getM_lastStructureScopedName()
return null;
}

public boolean isThereIsStructure()
{
if (m_lastStructure != null)
{
return true;
}
return false;
}

public TypeDeclaration getLastStructure()
{
return m_lastStructure;
Expand Down Expand Up @@ -617,6 +676,25 @@ public TypeCode getTypeCode(
}
}

@Override
public AnnotationDeclaration getAnnotationDeclaration(
String name)
{
if (isInScopedFile())
{
if (name.equals("optional"))
{
there_is_at_least_one_optional_annotation = true;
}
else if (name.equals("external"))
{
there_is_at_least_one_external_annotation = true;
}
}

return super.getAnnotationDeclaration(name);
}

//// Java block ////
// Java package name.
private String m_package = "";
Expand All @@ -634,4 +712,22 @@ public TypeCode getTypeCode(
new AbstractMap.SimpleEntry<>("DDS", Arrays.asList("eprosima", "fastdds", "dds")),
new AbstractMap.SimpleEntry<>("XTypes", Arrays.asList("xtypes")))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

private boolean there_is_at_least_one_array = false;

private boolean there_is_at_least_one_bitset = false;

private boolean there_is_at_least_one_external_annotation = false;

private boolean there_is_at_least_one_map = false;

private boolean there_is_at_least_one_optional_annotation = false;

private boolean there_is_at_least_one_sequence = false;

private boolean there_is_at_least_one_string = false;

private boolean there_is_at_least_one_struct = false;

private boolean there_is_at_least_one_union = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ $endif$


$if(object.labels)$
$object.labels:{ label | mst_$object.name$.common().label_seq().emplace_back($label$);}; separator="\n"$
$object.labels:{ label | mst_$object.name$.common().label_seq().emplace_back(static_cast<int32_t>($label$));}; separator="\n"$
$endif$

MD5 $object.name$_hash("$object.name$");
Expand Down Expand Up @@ -1288,7 +1288,7 @@ cst_$object.name$.common().type_id(*TypeObjectFactory::get_instance()->get_type_
$endif$

$if(object.labels)$
$object.labels:{ label | cst_$object.name$.common().label_seq().emplace_back($label$);}; separator="\n"$
$object.labels:{ label | cst_$object.name$.common().label_seq().emplace_back(static_cast<int32_t>($label$));}; separator="\n"$
$endif$


Expand Down
Loading