IBM
Contents Index Previous Next



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.

Note:

For further details see the TTCN Access include file access.hh.

General TTCN Access Functions Description

Example 169

Attach MyRepeat.attach()
where MyRepeat is of type Repeat and the return value is of type Attach.

Example 170

	 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;
	 }

Example 171

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.

Example 172

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.

Example 173

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:

Example 174

The following C++ code will create and initiate a variable of type Astring:
Astring tmp1;             // tmp1 is empty
Astring tmp2( "test1" );  // tmp2 contains "test1"
Astring tmp3 = "test2";   // tmp3 contains "test2"
Astring tmp4 = tmp2;      // tmp4 contains "test1"

Example 175

The following relational operations are available between Astring elements:
==, !=

Example 176

The following code is valid C++ code:
Astring myString( "test" );

cout << myString;
printf( "%s", ( const char* ) myString );

Example 177

The following is valid C++ code:
char c = myString[ 2 ]; // save the third character 
of the string

Note:

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.

Example 178

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 something
   Boolean 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:

Example 179

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 NSAPaddr
    Boolean ok_close = suite.close();
}


Note:

For further details see class AccessSuite in TTCN Access include file access.hh.

Example 180

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 NSAPaddr
    Boolean 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:

Example 181

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;
   }}

Note:

For further details see class AccessNode in TTCN Access include file access.hh


http://www.ibm.com/rational
Contents Index Previous Next