Skip to content

Commit

Permalink
Refs #2381. Adds simple IDL C types
Browse files Browse the repository at this point in the history
  • Loading branch information
BorjaOuterelo committed Dec 5, 2017
1 parent 6e65c09 commit 9767808
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
15 changes: 13 additions & 2 deletions src/java/com/eprosima/microcdr/idl/templates/MicroCdrCommon.stg
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ $if(params)$$separatorInicial$$endif$$params : {param | /*$param.comment$*/ $par
>>

object_serialization(ctx, object, preffix) ::= <<
scdr << $serializeCasting(typecode=object.typecode)$$preffix$$object.name$;
$if(object.typecode.primitive)$serialize_$object.typecode.cppTypename$(writer, topic->$preffix$$object.name$);
$elseif(object.typecode.isType_d)$
serialize_uint32_t(writer, strlen(topic->$preffix$$object.name$) + 1);
serialize_array_char(writer, topic->$preffix$$object.name$, strlen(topic->$preffix$$object.name$) + 1);
$endif$
>>

object_deserialization(ctx, object, preffix) ::= <<
dcdr \>> $deserializeCasting(typecode=object.typecode)$$preffix$$object.name$;
$if(object.typecode.primitive)$
deserialize_$object.typecode.cppTypename$(reader, &topic->$preffix$$object.name$);
$elseif(object.typecode.isType_d)$
uint32_t size = 0;
deserialize_uint32_t(reader, &size);
topic->$preffix$$object.name$ = malloc(size);
deserialize_array_char(reader, topic->$preffix$$object.name$, size);
$endif$
>>

// TODO Todos los tipos. MEJORAR. size of 1 no deberia generar alignment.
Expand Down
43 changes: 23 additions & 20 deletions src/java/com/eprosima/microcdr/idl/templates/TypesSource.stg
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $if(ctx.anyCdr)$
size_t $exception.scopedname$::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;

$exception.members : { member |$max_serialized_size(ctx=ctx, typecode=member.typecode, var="current_alignment")$}; separator="\n"$

return current_alignment - initial_alignment;
Expand Down Expand Up @@ -121,11 +121,14 @@ $if(ctx.fastcdr)$
void $exception.scopedname$::serialize(eprosima::fastcdr::FastCdr &scdr) const
{
$exception.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$

}

void $exception.scopedname$::deserialize(eprosima::fastcdr::FastCdr &dcdr)
{
$exception.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$


}

$endif$
Expand Down Expand Up @@ -158,14 +161,14 @@ struct_type(ctx, parent, struct, extensions) ::= <<
bool serialize_$ctx.filename;format="toUpper"$_topic(MicroBuffer* writer, const AbstractTopic* topic_structure)
{
$ctx.filename$Topic* topic = ($ctx.filename$Topic*) topic_structure->topic;

$struct.members : { member |$object_serialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$
return true;
}

bool deserialize_$ctx.filename$_topic(MicroBuffer* reader, AbstractTopic* topic_structure)
{
$ctx.filename$Topic* topic = mallo(sizeof($ctx.filename$Topic));

$ctx.filename$Topic* topic = malloc(sizeof($ctx.filename$Topic));
$struct.members : { member |$object_deserialization(ctx=ctx, object=member, preffix="m_")$}; separator="\n"$
return true;
}
>>
Expand All @@ -188,7 +191,7 @@ $union.scopedname$::~$union.name$()
$union.scopedname$::$union.name$(const $union.name$ &x)
{
m__d = x.m__d;

switch(m__d)
{
$union.members:{$unionmember_copy(it)$}; separator="\n"$
Expand All @@ -199,7 +202,7 @@ $union.scopedname$::$union.name$(const $union.name$ &x)
$union.scopedname$::$union.name$($union.name$ &&x)
{
m__d = x.m__d;

switch(m__d)
{
$union.members:{$unionmember_move(it)$}; separator="\n"$
Expand All @@ -210,40 +213,40 @@ $union.scopedname$::$union.name$($union.name$ &&x)
$union.scopedname$& $union.scopedname$::operator=(const $union.name$ &x)
{
m__d = x.m__d;

switch(m__d)
{
$union.members:{$unionmember_copy(it)$}; separator="\n"$
$unionmemberdefault_copy(union.defaultMember)$
}

return *this;
}

$union.scopedname$& $union.scopedname$::operator=($union.name$ &&x)
{
m__d = x.m__d;

switch(m__d)
{
$union.members:{$unionmember_move(it)$}; separator="\n"$
$unionmemberdefault_move(union.defaultMember)$
}

return *this;
}

void $union.scopedname$::_d($union.discriminator.cppTypename$ __d)
{
bool b = false;

switch(m__d)
{
$union.members:{$unionmember_discriminator_case(member=it, totallabels=union.totallabels)$}; separator="\n"$
}

if(!b) throw BadParamException("Discriminator doesn't correspond with the selected union member");

m__d = __d;
}

Expand Down Expand Up @@ -366,14 +369,14 @@ void $class$::$member.name$($member.typecode.cppTypename$ _$member.name$)
$member.typecode.cppTypename$ $class$::$member.name$() const
{
$unionmember_check_case_list(member=member, totallabels=totallabels)$

return m_$member.name$;
}

$member.typecode.cppTypename$& $class$::$member.name$()
{
$unionmember_check_case_list(member=member, totallabels=totallabels)$

return m_$member.name$;
}
$else$
Expand All @@ -392,14 +395,14 @@ void $class$::$member.name$($member.typecode.cppTypename$ &&_$member.name$)
const $member.typecode.cppTypename$& $class$::$member.name$() const
{
$unionmember_check_case_list(member=member, totallabels=totallabels)$

return m_$member.name$;
}

$member.typecode.cppTypename$& $class$::$member.name$()
{
$unionmember_check_case_list(member=member, totallabels=totallabels)$

return m_$member.name$;
}
$endif$
Expand Down Expand Up @@ -499,7 +502,7 @@ $endif$
unionmember_check_case_list(member, totallabels) ::= <<
$if(member.default)$
bool b = true;

switch(m__d)
{
$totallabels:{case $it$:}; separator="\n"$
Expand All @@ -510,7 +513,7 @@ switch(m__d)
}
$else$
bool b = false;

switch(m__d)
{
$member.labels:{case $it$:}; separator="\n"$
Expand All @@ -520,7 +523,7 @@ switch(m__d)
break;
}
$endif$

if(!b) throw BadParamException("This member is not been selected");
>>

Expand Down

0 comments on commit 9767808

Please sign in to comment.