Skip to content

Commit

Permalink
Refs #20973. New STG API function to check if a union needs the defau…
Browse files Browse the repository at this point in the history
…lt case (#138)

Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware authored and EduPonz committed May 14, 2024
1 parent 1004bcb commit 8957372
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,36 @@ public Member getDefaultMember()
return null;
}

/*!
* @ingroup api_for_stg
* @brief This function can be used to check if a generated language binding union (cpp, java) related to this
* union object should have the default case generated.
* @code
$union.members :{ member |
$member.labels:{ label |case $label$:}; separator="\n"$
$if(member.default)$default:$endif$
// Do something
break;
}; separator="\n"$
$if(union.needDefaultCase)$
default:
break;
$endif$
* @endcode
* @return @e false if the union contains a member declared as default member or the union discriminator type is
* @b boolean and the @e true and @e false case labels were defined. In other case, @e true is returned.
*/
public boolean getNeedDefaultCase()
{
if (m_defaultindex == -1 &&
!(Kind.KIND_BOOLEAN == discriminator_.getTypecode().getKind() && 2 == getMembers().size()))
{
return true;
}

return false;
}

@Override
public String getCppTypename()
{
Expand Down

0 comments on commit 8957372

Please sign in to comment.