The type command
Structure types are defined by using the type command. This command is followed by the specified type name and fields description in braces.There can be one or more fields of the same type defined in each string of the block. First, a type name is specified, which is followed by field names separated by commas or spaces. The field can have a numeric type as well as the previously defined structure type. Fields of the structure type are organized in memory as they have been described in the source code; if the field has a structure type, the structure of this type is completely embedded in the final structure. When fields are defined, dimensions separated by commas and enclosed in square brackets and the item type followed the keyword of can be determined. To get or assign a field value for a variable, its name should be specified after a full stop.
type customer
{
str name, last_name
uint age
arrstr phones[ 5 ]
}
...
customer cust1 //
cust1.name = "Tom"
cust1.age = 30
cust1.phones[ 0 ] = "3332244"
Attributes
index
Types can contain other elements, like a string array. You can specify what type of elements can be included in the object of this type by default. To do this, assign a corresponding type to this attribute. If elements have the same type by default (for example, tree), write index = this.
type arrstr <index=str inherit = arr>
{
...
}
inherit
You can inherit types. You have to use the attribute inherit = имятипа. See more details in Type inheritance.
protected
Gentee makes it possible to restrict access to fields of the type from other modules. The specified protected attribute is used for this purpose. In this case, all fields of the type will be accessible before the current file has compiled. Otherwise, fields of this type will be unaccessible.
type mytype <protected>
{
...
}
Additional features
For any structure type you can define methods that will allow you to
- Perform additional actions during initialization and deletion of a variable
- Specify of when describing variables of this type
- Use square brackets when addressing individual elements
- Use foreach to scan elements of this type.
These methods are described in System type methods.