![]() |
![]() |
![]() |
![]() |
![]() |
TTCN Access Primitives
Each node in TTCN Access is translated to a C++ class definition. Each instance of a specific C++ class definition contains one or more elements as defined in the specific C++ class definition. For each type definition there are a collection of TTCN Access functions.
In this chapter names written in italic are referred to as meta names. Words written in courier are taken from the definition of TTCN Access.
For further details see the TTCN Access include file access.hh.
General TTCN Access Functions Description
- For every node definition with assignment of type SEQUENCE or SEQUENCE OF there exists a general method
SlotType TypeReference.SlotName()Attach MyRepeat.attach()
- where MyRepeat is of type Repeat and the return value is of type Attach.
- For every TypeAssignment of type CHOICE there is a general method
Choices::choice TypeReference.choice()
- that returns the allowed SlotName type for current object. It is then possible to use the general method
SlotType TypeReference.SlotName()switch ( MyEvent.choice() ) {case Choice::c_send:do_something( Me.send() );break;case Choice::c_receive:do_something( Me.receive() );break;case Choice::c_otherwise:do_something( Me.otherwise() );break;case Choice::c_timeout:do_something( Me.timeout() );break;case Choice::c_done:do_something( Me.done() );break;default:do_something_default();break;}
- Assume that MyEvent.choice() in the previous example returned the value Choice::c_done. Then, TTCN Access method MyEvent.done().tcompIdList will then be a valid method and return an object of type TCompIdList.
- According to the above example the method MyTCompIdList.nr_of_items() returns an integer value of the number if items in the vector object MyTCompIdList and MyTCompIdList[ 2 ] will return the third element in the vector.
- For slots with ending OPTIONAL or FIELD there is a general method
Boolean TypeReference.is_present_SlotName()- For slots with ending FIELD and slots residing in a sub tree to a field there is a general method
Astring Node.content()
- The following C++ code will print out the content of a behavior line:
BehaviourLine BLine = MyLine;cout << BLine.line( ).content() << endl;
Terminal Nodes in TTCN Access
Every TTCN Access node that represents a leaf in the parse tree is considered to be a terminal TTCN Access node. A terminal TTCN Access node is a node that does not have any TTCN Access child nodes and can therefore not be accessed any further.
Terminal TTCN Access children are nodes containing identifiers, strings, keywords as well as numbers (i.e. TTCN Access nodes of type Identifier, IA5String, INTEGER, NUMBER, etc.). However, the content of such terminal nodes can be accessed through the methods supplied by the inherited class Astring.
TTCN Access Class Astring
Every terminal TTCN Access node carries information in string format. In order to access that information, every terminal TTCN Access node inherits a class named Astring. This class contains various methods for treating string information.
For terminal TTCN Access nodes, the following operations are available:
- The following C++ code will create and initiate a variable of type Astring:
Astring tmp1; // tmp1 is emptyAstring tmp2( "test1" ); // tmp2 contains "test1"Astring tmp3 = "test2"; // tmp3 contains "test2"Astring tmp4 = tmp2; // tmp4 contains "test1"
- The following relational operations are available between Astring elements:
==, !=
- The following code is valid C++ code:
Astring myString( "test" );cout << myString;printf( "%s", ( const char* ) myString );
- The following is valid C++ code:
char c = myString[ 2 ]; // save the third character of the string
For further details see class Astring in TTCN Access include file ITEXAccessClasses.hh.
Direct Access
AccessSuite
The AccessSuite object is the TTCN Access representation of a TTCN test suite. The test suite is in turn contained in a TTCN Suite data base. The AccessSuite services include opening and closing the TTCN Suite data bases as well as services to start an TTCN Access application and accessing the symbol table manager.
Opening and closing the test suite Test.itex for use in TTCN Access:
AccessSuite suite;Boolean ok_open = suite.open( "Test.itex" );if( ok_open ){// do somethingBoolean ok_close = suite.close();}After opening a test suite for TTCN Access use, it is possible to use the following methods to get a handle to the contents of the data base file:
- Getting a handle to the root object of a document:
AccessSuite suite;Boolean ok_open = suite.open( "Test.itex" );if( ok_open ) {const AccessNode node = suite.root();// do something with NSAPaddrBoolean ok_close = suite.close();}
For further details see class AccessSuite in TTCN Access include file access.hh.
- Ask the AccessSuite object for a specific TTCN Access object in the test suite. The object asked for must be a global object in the test suite. This is performed by using TTCN Access class AccessNode.
- Find the TTCN Access object NSAP in test suite Test.itex:
AccessSuite suite;Boolean ok_open = suite.open( "Test.itex" );if( ok_open ) {const AccessNode node = suite.find("NSAPaddr");// do something with NSAPaddrBoolean ok_close = suite.close();}
The AccessNode object now holds the TTCN Access item corresponding to the name NSAPaddr, if any.
To gain access to the data in an AccessNode, you must now find out the runtime type of the object. Based on that type, you will be able to use the conversion routine for an object of the corresponding type:
Find the type of the TTCN Access node corresponding to a name:
extern void HandleSimpleType( const SimpleType * );AccessSuite suite;Boolean ok_open = suite.open( "Test.itex" );if( ok_open ) {AccessNode node = suite.find( "SomeName" );switch( node.choice() ) {case Choice::_SimpleType:HandleSimpleType(node.SimpleType());break;default:break;}}
For further details see class AccessNode in TTCN Access include file access.hh
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |