CERN -> IPT Group -> FrameMaker at CERN
Information Service User's Guide

4.2 Getting information object type

There are two ways of getting the type of a particular information object, static and polymorphic. The static one can be used if the declaration of the C++ (or Java) class for the information object is available in user's code. In C++ language one can call the static method of the generated information class, which is called type, to get the type object of this information class (Listing 4.1).

Listing 4.1   Getting static type of information object

1: // include header files generated for the Person and Employee classes
2: #include <Person.h>
3: #include <Employee.h>
4: #include <ipc/core.h>
5:
6: void print_type( const ISType & type )
7: {
8: std::cout << "type is " << type << std::endl;
9: }
10:
11: int main( int ac, char ** av )
12: {
13: print_type( Person::type() );
14: print_type( Employee::type() );
15: return 0;
16: }
17:

In Java the type of the information object is declared as a public static final attribute of the generated class, called type and can used as <Information Class Name>.type.

The polymorphic type function, which is declared in the ISInfo class (is.Info in Java) can be used to get the type of the information object when the object's class declaration is not available or there is uncertainty about the actual type of this object (Listing 4.2).

Listing 4.2   Getting polymorphic type of information object

1: // include header files generated for the Person and Employee classes
2: #include <Person.h>
3: #include <Employee.h>
4: #include <ipc/core.h>
5:
6: void print_type( const ISInfo & info )
7: {
8: std::cout << "type is " << info.type() << std::endl;
9: }
10:
11: int main( int ac, char ** av )
12: {
13: print_type( Person() );
14: print_type( Employee() );
15: return 0;
16: }

Of course the types which are obtained using static and polymorphic ways are identical for the same information class.


2 July 1998 - WebMaster
Copyright © CERN 1998