Saving and Loading the Object Description
Now come the input/output member functions that we have declared in the class synopsis using the DeclareTypeInfo macro.
copy and read Member Functions
Another macro can be used to define the member functions copy and read:
IlvPredefinedIOMembers(ShadowEllipse); |
This macro must be used in the implementation file, outside any function definition block, just like IlvRegisterClass.
It is equivalent to:
IlvGraphic* ShadowEllipse::read(IlvInputFile& input, IlvPalette* palette) { return new ShadowEllipse(input, palette); } IlvGraphic* ShadowEllipse::copy() const { return new ShadowEllipse(*this); } |
The static member function read calls the class reading constructor and returns the new instance. The macro DeclareIOConstructors declares the reading and copying constructors in the header file. The definition of these constructors must be written in this way in the implementation file:
ShadowEllipse::ShadowEllipse(IlvInputFile& f, IlvPalette* pal) : IlvSimpleGraphic(f, pal), _rect(), _thickness(0) { int thickness; f.getStream() >> _rect >> thickness; _thickness = (IlvDim)thickness; _invertedPalette = 0; computeInvertedPalette(); } |
The above constructor calls the superclass reading constructor, which reads the
superclass-specific information from the stream object. Then the subclass can read its own information.
The member function copy creates a copy of the IlvShadowEllipse class, calling the class copy constructor:
ShadowEllipse::ShadowEllipse(const ShadowEllipse& source) : IlvSimpleGraphic(source), _rect(source._rect), _thickness(source._thickness) { _invertedPalette = source._invertedPalette; _invertedPalette->lock(); } |
write Member Function
The member function write writes the dimensions of the rectangle and the thickness of the shadow to the given ostream output stream:
void ShadowEllipse::write(IlvOutputFile& f) const { f.getStream() << _rect << IlvSpc() << (int)_thickness; } |
This
write method is special because the
IlvSimpleGraphic superclass has no information to write. It is better to call the superclass
write method to be consistent with the
read method, if the superclass has information to write. Here is an example of a usual
write method:
void IlvRoundRectangle::write(IlvOutputFile& os) const { IlvRectangle::write(os); os.getStream() << IlvSpc() << _radius; } |
IlvRegisterClass Macro
IlvRegisterClass(ShadowEllipse, IlvSimpleGraphic); |
Outside of the body of any function, we have to register the class
IlvShadowEllipse as a subclass of the class
IlvSimpleGraphic.
Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.