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

7.3 Parsing content of the ISInfoAny object

The applications which want to use another format for the information presentation or to use ISInfoAny for another purpose have to parse the content of the ISInfoAny object. The ISInfoAny class provides access for the information value in a stream manner: attribute by attribute. It has a number of input operators which can be used to get the value of a single-value attribute, and a number of get methods which can be used to read an array attribute values. Each input operation (if it was successful) advances the "current position" in the stream to the value of the next attribute. There is a method which returns type of the attribute at the current stream position. "Listing 7.3" shows how to print to the standard output the value of an information object using operators and methods of the ISInfoAny class.

Listing 7.3   Parsing content of the ISInfoAny object

1: // include IS header file
2: #include <is/infoany.h>
3:
4: void print ( ISInfoAny & isa )
5: {
6: int attr_number = isa.countAttributes( );
7:
8: std::cout << attr_number << " attribute(s):" << std::endl;
9: for ( i = 0; i < attr_number; i++ ) {
10: switch ( isa.getAttributeType() ){
11: case ISType::Boolean:
12: ISOut<bool>::put( isa, "boolean" );
13: break;
14: case ISType::S8:
15: ISOut<short>::put( isa, "signed byte" );
16: break;
17: case ISType::U8:
18: ISOut<short>::put( isa, "unsigned byte" );
19: break;
20: case ISType::S16:
21: ISOut<short>::put( isa, "short" );
22: break;
23: case ISType::U16:
24: ISOut<unsigned short>::put( isa, "unsigned short");
25: break;
26: case ISType::S32:
27: ISOut<long>::put( out, isa, "long" );
28: break;
29: case ISType::U32:
30: ISOut<unsigned long>::put( isa, "unsigned long" );
31: break;
32: case ISType::Float:
33: ISOut<float>::put( isa, "float" );
34: break;
35: case ISType::Double:
36: ISOut<double>::put( isa, "double" );
37: break;
38: case ISType::String:
39: ISOut<std::string>::put( isa, "string" );
40: break;
41: case ISType::Date:
42: ISOut<OWLDate>::put( isa, "date" );
43: break;
44: case ISType::Time:
45: ISOut<OWLTime>::put( isa, "time" );
46: break;
47: default:
48: std::cout << " { ERROR: Invalid Type } " << std::endl;
49: }
50: }
51: }

First this program gets the number of the information attributes using the countAttributes method of the ISInfoAny class (line 6). Then, for each attribute it finds out the attribute type (line 11) and calls the put method of the ISOut<T> template class. This method reads the value of that attribute from the ISInfoAny object, and prints this value to the standard output stream. The ISOut<T> template class is shown in "Listing 7.4".

Listing 7.4   Implementation of the ISOut<T> class

1: template <class T>
2: class ISOut
3: {
4: public:
5: static inline void put( ISInfoAny & isa, const char * name )
6: {
7: std::cout << name << " : ";
8: if ( isa.isAttributeArray() )
9: {
10: std::vector<T> value;
11: isa >> value;
12:
13: for ( size_t i = 0; i < value.size(); i++)
14: std::cout << value[i] << " ";
15: }
16: else
17: {
18: T value;
19: isa >> value;
20: std::cout << value;
21: }
22: std::cout << std::endl;
23: }
24: };

The template class is used here to simplify the code. Alternatively one can explicitly define a number of functions to handle different attribute types.


2 July 1998 - WebMaster
Copyright © CERN 1998