Implementation of a Document Class
A document class is derived from the
IlvDvDocument class.
The document is the user data. The document class loads and saves data and also provides accessors that are used by document views to modify data.
Note: The user data is similar to the Model View Controller (MVC) approach. |
Application Framework provides document classes that manage specific data, such as Rogue Wave Views managers, text buffers, or projects, as shown in the following inheritance tree:
New Document
A derived document class must override the
IlvDvDocument::initializeDocument method.
It is called when the File > New command is executed to create a document.
The method must first call
initializeDocument. Then, it must initialize specific data.
Serialization
void IlvDvDocument::serialize(IlvDvStream& stream);
is called when a file is opened to create the document, if a call to stream.isSaving() returns false. Otherwise, the document must be saved.
Typically, the body of the method has the following form:
IlvDvDocument::serialize(stream);
if (stream.isSaving()) {
// Here, write your persistent data
}
else {
// Here, read data from stream
}
There are two ways of loading and saving data when using the parameter called stream.
One way is to use istream or ostream objects. These objects are given by a call to the istream* getInStream() const and ostream* getOutStream() const methods directly.
The other way, which is usually easier, is to use specific serialization methods, provided by the
IlvDvStream class. Here are these methods:
Operators
// Storing operators
IlvDvStream& operator<<(IlInt i);
IlvDvStream& operator<<(IlUShort w);
IlvDvStream& operator<<(IlShort ch);
IlvDvStream& operator<<(IlUInt u);
IlvDvStream& operator<<(IlBoolean b);
IlvDvStream& operator<<(IlFloat f);
IlvDvStream& operator<<(IlDouble d);
IlvDvStream& operator<<(const IlString& s); //’s’ must not contain blanks
// Reading operators
IlvDvStream& operator>>(IlInt& i);
IlvDvStream& operator>>(IlUShort& w);
IlvDvStream& operator>>(IlShort& ch);
IlvDvStream& operator>>(IlUInt& u);
IlvDvStream& operator>>(IlBoolean& b);
IlvDvStream& operator>>(IlFloat& f);
IlvDvStream& operator>>(IlDouble& d);
IlvDvStream& operator>>(IlString& s);
void serialize(IlvString&, IlBoolean betweenQuotes = IlTrue); This method is a safe way of loading and saving strings. If the betweenQuotes parameter is set to true, the string is saved between quotation marks. This way it can contain blank spaces.
void serializeBitmap(IlvBitmap*&, IlBoolean lock = IlTrue); Serializes a bitmap path.
Serialization of objects
When implementing user classes, it is recommended to derive from the
IlvDvSerializable class. This class is an abstract interface that provides both a mechanism for safe downcasting and a serialization method:
virtual void serialize(IlvDvStream& stream);
void serializeObjects(IlvArray&); Load and save an array of IlvDvSerializable objects:
void writeObject(const IlvDvSerializable*); IlvDvSerializable* readObject(); virtual void clean(); This method is called to clean up the document data. It is only used for documents whose corresponding document type does not allow opening more than one document (SDI document types, typically project documents). When a user tries to create a new document while a document of the same type is already open, Application Framework does not delete the currently opened document to create another one. Instead, it cleans the open document (by calling this method) and reinitializes the document.
Version 5.6
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.