![]() |
VR-Forces 4.10 Class Documentation
|
To allow readable, writable objects to easily contain other readable, writable objects, the DtReaderWriter creates an instance of DtReaderWriterRegistry (rwRegistry.h).
The DtReaderWriter registry is a list of DtReaderWriter pointers. (Actually it is a hash list indexed by the names of the objects.) The constructor for a DtReaderWriter takes a registry pointer as an argument. If this pointer is non-null, the DtReaderWriter object registers itself with the registry pointer provided. In this way, you can compose new readable, writable objects from existing ones. It is fairly common, in fact, to have objects that generate no new readable, writable data, and therefore do not need to override putData() and getData(). Example RW-1 shows the key elements needed to make a new readable, writable class that contains a real number and an integer number, using the existing DtRwReal and DtRwInt classes.
In the header file realAndInt.h, we do the following:
In the implementation file realAndInt.cxx, we do the following:
The myRegistry variable referred to in the constructor is a member variable of the DtReaderWriter class that the RealAndInt class inherits. An example of its use and sample output, assuming an already open file pointer fp, as follows:
would write to the open file pointed to by fp, as follows:
If your object does not contain any local data that it wants to write other than the readable, writable objects it uses, there is no need to override putData() and getData(), and in fact, no need for putSelf() and getSelf() to invoke these member functions. By default, these functions are not called. To indicate that an object has local data and wants getData() or putData() to be called, call the following, typically in the constructor of the object:
[<< Multiple Inheritance and DtReaderWriter] [Home] [Top of Page] [Handling Unspecified Parameters >>]