VR-Forces 4.2 Class Documentation
16.6 - Handling Unspecified Parameters

There may be times when a DtReaderWriter object expects to read a value from a file and the file does not contain the expected value.

A DtReaderWriter object can keep track of whether or not it has received a value from a file. In Example RW-1, the class created could read the following input without error (note that the integer-number entry is missing):

(two-numbers
(real-number 7.66)
)

The DtReaderWriter does not require that every registered item get a value from the data stream. When data is found for a registered entry, DtReaderWriter sets a flag to true to indicate this. If you want to detect unread entries, set this flag to false for the object before getSelf() is called (the constructor is a good place to do this). Since some objects may want this functionality and others may not, it is a good practice to let the including object set these flags, rather then setting them in the constructor of the base object itself. In our RealAndInt class, in the constructor, we could add the following:

myRealNumber.setValueSpecified(false);
myIntegerNumber.setValueSpecified(false);

You could also call the following:

myRealNumber.setValueSpecified(true);

in the mutator that sets myRealNumber’s value, if that is also a valid way to get a value in your class. Finally you can test whether or not a value has been set as follows:

if (myRealNumber.valueSpecified())
{
// do this only if a value was read from the file or set in the mutator
// function
...

[<< The Reader Writer Registry] [Home] [Top of Page]


Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)