Ad/2010-08-01 Concrete Syntax for a uml action Language for Foundational uml (Alf) Second Revised Submission



Download 1.74 Mb.
Page33/62
Date28.01.2017
Size1.74 Mb.
#9041
1   ...   29   30   31   32   33   34   35   36   ...   62

11.4Basic Input and Output


As shown in Figure 11 -73, the Alf::Library::BasicInputOutput package imports the fUML standard FoundationalModelLibrary::BasicInputOutput package (see fUML Specification, Subclause 9.4). This makes the fUML input-output classes available via the Alf::Library::BasicInputOutput namespace. In addition, the FoundationalModelLibrary::BasicInputOutput package imports the FoundationalModelLibrary::Common package, so the common classes from that package are also available via the Alf::Library::BasicInputOutput namespace.

11.5Collection Functions


The Alf::Library::CollectionFunctions package contains template versions of the sequence functions defined in the Alf::Library::PrimitiveBehaviors:: SequenceFunctions package. Each collection function has a single template parameter, the type of values in the sequence be operated on. The type inference rule for the invocation of template behaviors (see Subclause 8.3.9) then allows these behaviors to be invoked without having to explicitly notate the binding of their template parameter.

For example, if integerList is a sequence of type Integer, then the statement

let extendedList: Integer[] = including(integerList, 1);

is equivalent to

let extendedList: Integer[] = including(integerList, 1);

Since the result type of including is Integer, the right-hand side of this statement is assignable to the left-hand side without the need for an explicit cast.

Each of the functions defined in the SequenceFunctions package has a template version defined as an activity in the CollectionFunctions package. The body of this activity simply calls the corresponding primitive function and returns the result of that call, cast to the appropriate result type. For example, the including function may be defined as follows as an Alf unit (see Subclause 10.4.8 on activity definitions):

namespace Alf::Library::CollectionFunctions;

activity including(in seq: T[*] sequence, in element: T):

T[*] sequence

{

return (T)PrimitiveBehaviors::SequenceFunctions::Including(seq, element);



}

Other functions are defined similarly.



NOTE. According to the copy semantics for templates (see Subclause 6.2), a call to a bound template activity, such as including, has the semantics of a call to an effective bound element constructed from a copy of the template activity with each occurrence of the template parameter T replaced by the actual argument type. However, once static analysis is complete, a call to such a bound activity will have a semantically equivalent effect (in the sense defined in Subclause 2.2) to a direct call to the corresponding sequence function, without even a need for any cast (since the definitions of the sequence functions guarantee that their results have the expected dynamic type, even if the statically declared type is any). Therefore, a compliant compilative implementation may, if desired, produce a target fUML model that replaces calls to bound collection functions with direct calls to the corresponding sequence functions.

All the primitive sequence functions take a sequence as an in parameter and return some result based on that sequence (see Subclause 11.3.6) and, therefore, so do the corresponding collection functions. The collection functions may also take collection objects (see Subclause 11.6) as inputs because of the collection conversion rule for assignability (see Subclause 8.8). This is particularly useful when using a collection as the source in the sequence operation notation (see Subclause 8.3.17). The returned result, however, is always a sequence, though this may be used to construct a new collection object.

The CollectionFunctions package also includes a number of additional activities that take a sequence as an inout parameter and make changes to that sequence “in place”. Table 11 -15 lists these behaviors. The bodies of these in-place behaviors are defined to be an Alf assignment expression, generally involving one of the base set of collection functions. For example, the full definition of the add function, as an Alf unit, is

namespace Alf::Library::CollectionFunctions;

activity add(inout seq: T[*] sequence, in element: T):

T[*] sequence

{

return seq = including(seq,element);



}

The in-place functions cannot be used with collection objects, since the inout parameter cannot be assigned back to the collection object. However, all collection classes have regular operations that correspond to the functionality of the “in place” functions (see Subclause 11.6). The in-place collection functions are intended to provide similar functionality for sequences to that provided by the similarly named operations on collection objects.



Table 11 15 Collection “In-Place” Behaviors

Activity Signature

Description

add

(inout seq: T[*] ordered,

in element: T):

T[*] sequence



Append element to the end of seq.
seq = including(seq,element)

addAll

(inout seq1: T[*] sequence,

in seq2: T[*] sequence):

T[*] sequence



Append all elements of seq2 to seq1.

seq1 = union(seq1,seq2)



addAt

(inout seq: T[*] sequence,

in index: Integer,

in element: T):

T[*] ordered nonuique


Insert element at position index of seq.

seq = includeAt(seq,index,element)



addAllAt

(inout seq1: T[*] sequence,

in index: Integer,

in seq2: T[*] sequence):

T[*] ordered nonuique


Insert all elements of seq2 into seq1 at position index.

seq = includeAllAt(seq,index,element)



remove

(inout seq: T[*] sequence,

in element: T)


Remove all occurences of element from seq.

seq = excluding(seq,element)



removeAll

(inout seq: T[*] sequence,

in element: T)


Remove all elements of seq2 to seq1.

seq1 = difference(seq1,seq2)



removeOne

(inout seq: T[*] sequence,

in element: T)


Remove the first occurrence of element (if any) from seq.

seq = excludingOne(seq,element)



removeAt

(inout seq: T[*] sequence,

in index: Integer):

T[*] sequence



Remove the element at position index from seq.

seq = excludeAt(seq,index)



replace

(inout seq: T[*] sequence,

in element: T,

in newElement: T):

T[*] sequence


Replace all occurrences of element in seq with newElement.

seq = replacing(seq,element,newElement)



replaceOne

(in seq: T[*] sequence,

in element: T,

in newElement: T):

T[*] sequence


Replace the first occurrence of element in seq (if any) with newElement.

seq = replacingOne(seq,element,newElement)



replaceAt

(inout seq: T[*] sequence,

in index: Integer,

in element: T):

T[*] sequence


Replace the element at position index in seq with the given element.

seq = replacingAt(seq,index,element)



clear

(inout seq: T[*])



Clear all elements of seq.

seq = null




Download 1.74 Mb.

Share with your friends:
1   ...   29   30   31   32   33   34   35   36   ...   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page