Datatype Element/en

Aus expecco Wiki (Version 2.x)
Version vom 1. April 2014, 10:13 Uhr von Cg (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „A datatype element is used to define additional datatypes which are not available in the default set of provided datatypes. They can be modified i…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

A datatype element is used to define additional datatypes which are not available in the default set of provided datatypes. They can be modified in the datatype editor.

Standard (Predefined) Types[Bearbeiten]

A number of types are already built into and well-known to expecco. These are:

General Types[Bearbeiten]

  • Any
any object. Useful when the exact type is not known/not relevant. Instances can be of any other type. But please read "Any Type Considered Harmful" before defining an output pin with this type
  • struct (vsn 2.1)
the "struct" singleton type (i.e. there is only one such type) represents arbitrary compound values, whose field names are defined at runtime. These can be used for compound objects, whose structure is not known in advance (for example, which are returned by an XML-RPC call). Technically, instances are represented as Dictionary (HashTable) instances. In a textual type definifion, use the keyword "struct".

Common Predefined Primary Types[Bearbeiten]

  • Address
a pointer to external data (C-pointer)
  • BitString
an array of bits
  • Boolean
boolean truth values: true and false
  • ByteArray
a collection of bytes
  • Collection
a collection of any other object (possibly unordered)
  • Date
represents a date (dd-mm-yy)
  • DateTime
represents both date and time (aka: timestamp) with millisecond resolution
  • Dictionary (HashTable)
a mapped collection, where the key/index may be any arbitrary object
  • Filename
represents a path/file name
  • FixedPoint
a decimal number which presents itself rounded to a given scale (= number of post-decimal digits). These are useful when monetary values are to be processed.
  • Float
an IEEE rational number with double-precision (64bit)
  • Fraction
an exact fraction. These can result from dividing two integers. Operations on fractions are exact (without rounding errors). When possible, results are reduced and if possible converted to integral results (i.e. (1/3) * (1/3) * 9 -> 1, exact).
  • Handle
a handle as returned by some operating-system calls
  • HexString
  • IPAddress
  • Integer
an integral number of arbitrary size (i.e. only limited by memory). Operations on integers automatically care for overflow and reserve more memory if required (i.e. there is no 32- or 64-bit overflow).
  • Number
any numeric value (integer, float or fraction)
  • OctedString
  • OrderedCollection
a growable collection, with integral index
  • SequenceableCollection
any collection, with integral index (possibly non-growing)
  • Set
an unordered collection, where every object occurrs at most once
  • Socket
represents a socket connection stream
  • Stream
any stream
  • String
a collection of characters
  • StringCollection
a collection of lines, as read from a file
  • StringOrFilename
a union either a fileName object, or a string
  • Time
a time of the day (hh:mm:ss)
  • TimeDuration
a time-delta (10m, 1h or 3d)
  • URL
URLs are used in web browsers to address web documents.
  • UUID
a globally unique identifier.
  • UnicodeString
now obsolete, as String has been generalized to include both single-byte and wide characters

Expecco Types[Bearbeiten]

These represent objects as used or generated by expecco itself.

  • ActivityLog
Represents detail information of a test- or block execution. In particular, pin values, log-messages, caller and called actions are recorded in here.
  • Datatype
a metatype; instances are datatypes themself
  • Error & Exception
Additional details of an exception (provided at exception output pins)
  • GUI Aspect
used with GUI block descriptions
  • Library
Instances represent imported libraries
  • Performer
Instances represent block descriptions. Their primary use is as input value of a virtual block, in order to define which concrete block is to be executed. Constant values (freeze values) of this type are kept as GUID (Globally Unique Identifier) of the referred-to block. The id of the block is found via the block's selection menu in the project tree, or in the documentation page of the block's editor.
  • Report Template
  • Resource
Represents a device, a human operator or any other resource.
  • SUnit TestResult
represents test results as generated by an internal unit test execution
  • Symbol
unique symbols of the underlying Smalltalk runtime system. These are used as hash key when naming classes, methods, UI aspects and others.
  • Verdict
Instances represent a test- or block execution's outcome (PASS, FAIL, ERROR oder INCONCLUSIVE)

User Defined Types[Bearbeiten]

New user defined types can be constructed by a number of different mechanisms:

Primary Types[Bearbeiten]

Primary types represent existing classes of the underlying VM (virtual machine). These are the classes as described in the Smalltalk/X Online Documentation in addition to any classes which have been loaded dynamically via the plugin mechanism.

Tuple Types[Bearbeiten]

A tiple type consists of a fixed number of indexed fields, each defined by its type. For example, an object which associates a name with an age and a gender could be represented by a tuple instance as:

tuple type:

    (
        String
        Integer
        enum(M|F)
    )

when instantiated, fixed sizes arrays are created for tuple instances. Given a tuple type T, it can be instanciated with:

    inst = T.new();

and the fields can be set with:

    inst[1] = "Andy";
    inst[2] = 45;
    inst[3] = 'M'.asSymbol();

In most cases, compound types are a better choice to tuples: due to the naming of fields, compounds are less error prone and more self-describing.


Compound Types[Bearbeiten]

A compound type consists of a number of named fields, each defined by its type. For example, a customer record could be represented by a compound type instance as a structure consisting of individual fields:

compound type:

    {
        firstName: String
        lastName: String
        zip: Integer
        age: Integer
    }

when instantiated, an anonymous class is created for instances of compound types. These objects provide virtual accessor functions (getters and setters), which are named as the field names. Thus, given a compound type T, it can be instanciated with:

    inst = T.new();

and the fields can be set with:

    inst.firstName( "Andy" );
    inst.lastName( "Miller" );
    inst.age ( 41 );

Enumeration Types[Bearbeiten]

An instance of an enumerated type can take a value from a defined list of values. For example, a test-outcome could be defined as an enumerated type:

enum type:

    (
        pass | fail | inconclusive 
    }

(notice, that there is already a Verdict type present in the set of standard types, so the above example is somewhat unrealistic).

Internally, enum values are kept as instances of the underyling Smalltalk Symbol class, which itself derives from String. Thus, an enum value can be fed to any input which accepts Strings.

A freeze value editor presents the enum values as a combolist, which presents the values as a list from which the user chooses the desired item. The organization of this list can be specified in the datatype editor to better meet UI requirements (for example, as hierarchical menu, sorted etc.)

Subrange Types[Bearbeiten]

A subrange of the set of values of either the integer- or the character type. A subrange type defines the minimum and maximum values from the base type's set of values.

For example, a type to describe byte-valued integers could be described as:

range( Integer : 0 .. 255 )

Union Types[Bearbeiten]

A union type represents a number of alternative fields. The selection of which field is actually valid within a union must be done elsewhere (or, via reflection, by asking the object dynamically).

For example, a type to describe an object which is either numeric or a string, could be described as:

union type:

    (
        String | Integer
    )

CTypes (vsn 1.7.4)[Bearbeiten]

A cType is similar to a compound type; however, a data representation is used, which is compatible to structures of the C-programming language. Also, the definition is given in C-syntax. For example, the above customer record could be represented as the following C-structure:

cType type:

    /* C: */
    struct {
        char firstName[20];
        char lastName[20];
        int zip;
        short age;
    }

Notice the explicit dimension of the strings. These are required to define the C-structures exact size. When instantiated, an object is created, which has the underlying C-structure layout, and which is not moved in memory by the garbage collector (i.e. its address remains constant). It can therefore be passed to a called c-functions, for example in a dll call. Similar to compound types, instances of cTypes understand accessor functions. Given a ctype type T, it can be instanciated with:

    inst = T.new();

and the fields can be set with:

    inst.firstName( "Andy" );
    inst.lastName( "Miller" );
    inst.age ( 41 );

Notice that cTypes are not supported by expecco releases before 1.7.4. Also notice, that C-structures are allocated using malloc on the C-heap. The overhead in terms of memory use and processing power is therefore much higher when compared to normal compound- or primary instances. Only use cType instances when data has to be exchanged with C-programs.

Special Types[Bearbeiten]

The following two types are useful as a pin datatype. They are usually not declared as elements in the project tree, but attached to a pin type (i.e. they are usually anonymous).

Template Types[Bearbeiten]

Template types allow for type save declaration of polymorphic operations.

Template types are a kind of placeholder-type, which will be bound to a real type as soon as a pin is connected. Template types are initially unbound. When a pin with an unbound template type is connected to a real typed pin, the template becomes bound and is treated like a pin of the other type. If a bound template typed pin is connected, the usual type compatibility checks are performed against the underlying real type. Template types have a special name, consisting of a "#"-character followed by a number (i.e. "#1", "#2" etc.). Within the set of pins of a single step, all template types with the same name are unified; i.e. bound together.

For example, assume that we have a block which takes an input value and, depending on a control input, sends its input value to one of two outputs. Let's call this a "muliplexer" block. This block's operation is independent of the input type: it could handle any datum. This might lead us to declare the value input and output pins as "Any":

        +-----+
Any --->| MUX |
Bool -->|     |---> Any
        +-----+

However, having an "Any"-output prevents it from being connected to any non-Any input. You will need a lot of type-cast blocks, to downcast from the very general "Any" to whatever type is actually passed. What we really want to say is that the output's type should always be the same as the input's type, and vice versa. I.e. if the input is connected to a Number output, the multiplexer's output should also be of Number-type. If connected to a String-pin, the output should have String-type, and so on.

        +-----+
#1  --->| MUX |
Bool -->|     |---> #1
        +-----+

Exactly that is what a template type does: it states, that whatever type is connected to the input pin, will be the type of the output pin.

Template types can be embedded in a user-defined type: for example, a block which takes three inputs of arbitrary type, and generates a tuple of these values on its output, could be defined as:

       +--------+
#1 --->|        |
#2 --->| Tupler |---> (#1 #2 #3)
#3 --->|        |
       +--------+

If the inputs are connected to Bool, Bool, String, it will only be possible to connect to blocks which accept tuples like (Bool, Bool, Number) or more general tuples, such as (Bool, Bool, Any), but not to more specific typed tuples, such as (Bool, Bool, Integer).

Please also read the motivation for template types in "Any Type Considered Harmful".

Constraint Template Types[Bearbeiten]

Constraint Template Types are similar to template types, in that they are initially unbound and bind to a concrete type when connected. However, they restrict the set of possible types which can be bound. For example, if some pin expects the type to be a kind of collection, the datatype can be defined as "#1(Collection)". Similar to a regular template type, this initially unbound type will be bound whenever a pin gets connected. Also, other "#1(Collection)" types at the same step are unified with this type.

However, when connecting, binding is only allowed to types which are compatible with a Collection type.

Formal (BNF) Syntax of Type Declarations =[Bearbeiten]

Please refer to the datatype editor documentation .

   


For other tree elements see: Tree Elements

For editors see: Editors

The full online documentation can be found under: Online Documentation



Copyright © 2014-2024 eXept Software AG