Hello everyone
I have a question on the TCI operations of UnionValue, and the union type,
and subtyping within structured types. Here's what the TCI standard
says:
"
TCI: 7.2.2.2.15 The abstract data type UnionValue
Value getVariant(in TString variantName)
Returns the value of the TTCN-3 union variantName, variantName equals
the result of getPresentVariantName, the distinct otherwise.
variantName denotes the name variant as defined in TTCN-3
void setVariant(in TString variantName, in Value value)
Sets variantName of the union to value. If is not defined for this
union this operation is variant was selected the new variant is
selected
TString getPresentVariantName()
Returns a String representing the currently selected name in the given
TTCN-3 union. The distinct returned if no variant is selected
TStringSeq getVariantNames()
Returns a sequence of string of variant names, null, if the union has
no fields. If the UnionValue represents the TTCN-3 anytype, i.e. the
type obtained by getType() is ANYTYPE, all user-defined TTCN-3 types is
returned
"
What are the "variant names"? Are they the field names, or the field
types? From the definition of getVariantNames() I get the idea, that it
returns type identifiers, not field names. For the RecordValue type, the
TStringSeq getFieldNames() operation returns field names, not types.
If getVariantNames() returns type identifiers, then consider the following
union definition, which is legal according to BNF and not prohibited by
the core standard. At least I could not find any mention.
type union myUnion
{
integer smallNumber (1),
integer greatNumber (100)
} with
{
encode (smallNumber) "smallRule";
encode (greatNumber) "greatRule";
}
Now, how does one set value for the field smallNumbers with setVariant(),
if it takes as a parameter the field type? Both choices have the same
type identifier but they are different subtypes.
You could say that the TE/tool has given them different internal type
identifiers, and those are returned with getVariantNames().
But I don't see any reason why this would be illegal either:
type union myUnion
{
integer smallNumber,
integer greatNumber
} with
{
encode (smallNumber) "smallRule";
encode (greatNumber) "greatRule";
}
or
type union myUnion
{
integer smallNumber,
integer greatNumber
}
For the last one there is an example in the standard.
I guess the TE/tool could again give them different internal type
identifiers, but it has to also store the information, that these types
are just aliases for the integer type, and they are compatible with it.
If the TE/tool generates new type identifiers for the field types,
then type identifier specific codecs cannot be used, or they can
be used, but they become tool spesific, since they have to know
the tool spesific rule how the type identifiers are generated.
Summa summarum:
1. Should it be illegal to define new subtypes within structured types?
2. Should it be illegal to have fields of the same (sub)type within a
structured type?
3. Should there be the operation TStringSeq getFieldNames() for the
unionValue also?
4. Something else should be changed?
I don't expect yes to all of them :)
BR
Antti