Module: XML Streams Module Package: XML Streams
RWXMLObjectStreamCommon RWXmlObjectInputStreamImpRWObjectInputStreamImp RWFilteredDataInputStreamImp
#include <rw/xmlstreams/RWXmlObjectInputStreamImp.h>
The class RWXmlObjectInputStreamImp reads and restores objects encoded in XML from the supplied RWDataInputStream. Typically, the XML stream was originally created by the class RWXmlObjectOutputStreamImp, thereby ensuring symmetry of the output and subsequent input.
The XML Streams Module integrates with the general Rogue Wave streams architecture defined by the streams and serialization packages of the Advanced Tools Module of SourcePro Core. This architecture allows an XML stream to be written out and read in using a wide variety of streaming configurations. For more information specific to the XML Streams Module, see the XML Streams Module User's Guide. For information on the general architecture, see the Advanced Tools Module User's Guide.
RWXmlObjectInputStreamImp is the body class of a handle-body pattern. The corresponding handle class is RWObjectInputStream.
The syntax of the XML formatting parsed by this class is defined by the XML schema xmlstreams.xsd. This schema is located in buildspace\rw\xmlstreams.
// Open an fstream to serve as our source. ifstream s("foo.xml"); // Create an XML data stream using the fstream. RWObjectInputStream in = RWXmlObjectInputStreamImp::make(s); // Read an integer from the XML data stream. int i; s >> i;
virtual void getChar(char& value); virtual void getCharacter(char& value); virtual void getDouble(double& value); virtual void getFloat(float& value); virtual void getInt(int& value); virtual void getLong(long& value); virtual void getLongLong(rwlonglong& value); virtual void getLongDouble(long double& value); virtual void getShort(short& value); virtual void getSizeT(size_t& value); virtual void getString(RWCString& str); virtual void getUCharacter(RWUChar& value); virtual void getUnsignedChar(unsigned char& value); virtual void getUnsignedLongLong(rwulonglong& value); virtual void getUnsignedShort(unsigned short& value); virtual void getUnsignedInt(unsigned int& value); virtual void getUnsignedLong(unsigned long& value); virtual void getUString(RWBasicUString& str); virtual void getWchar_t(wchar_t& value); virtual void getWCharacter(wchar_t& value); virtual void getWString(RWWString& str);
Reads a value from the stream, where the type of the value is defined by the first parameter. These functions are redefined from the parent class RWObjectInputStream.
static RWObjectInputStream make(RW_SL_IO_STD(istream)& source, bool escape = true);
Constructs an RWXmlObjectInputStreamImp instance that uses the data stream source as its source of bytes, and returns a handle to it. Use this method when the data input stream is a standard library std::istream.
The parameter escape sets whether the input stream contains escapes for XML reserved characters that need to be unescaped. Usually this would be because the objects serialized out with RWXmlObjectOutputStream contained embedded XML. By default, this parameter is set to true.
The reserved characters are:
< > & " '
You get slightly better performance if the escape parameter is set to false, but before doing so be certain that your data does not contain reserved characters.
static RWObjectInputStream make(RWDataInputStream& source, bool escape = true);
This function is like the one above, but is used when the required input stream is a derived class of RWDataInputStream.
static RWObjectInputStream make(RW_SL_IO_STD(istream)& source, RW_SL_IO_STD(ios)*& formatter, bool escape = true);
This function is the same as the first one described above, except that it also takes a pointer reference to an std::ios formatting object. An empty formatting object pointer is created before the XML stream is created and is passed through this make() function to the constructor:
std::ios* formatter; // uninitialized pointer RWObjectInputStream xistr = RWXmlObjectInputStreamImp::make(infile,formatter);
The constructor, in creating the underlying character stream for the XML stream, creates a formatting object for the stream and places the address of that object in the pointer reference. The calling application can then use this formatting object to manipulate data formats in the XML stream.
formatter->precision(15); // manipulate data format
RWXmlObjectInputStreamImp(RW_SL_IO_STD(istream)& sourceStream, bool escape);
Used by the make() function and potentially by derived classes to initialize the source data stream if the required input stream is a standard library std::istream.
The parameter sourceStream is a handle to the initialized stream.
The parameter escape sets whether the input stream contains escapes for XML reserved characters that need to be unescaped. Usually this would be because the objects serialized out with RWXmlObjectOutputStream contained embedded XML.
The reserved characters are:
< > & " '
You get slightly better performance if the escape parameter is set to false, but before doing so be certain that your data does not contain reserved characters.
RWXmlObjectInputStreamImp(RWDataInputStream& sourceStream, bool escape);
This constructor is like the one above, but is used when the required input stream is a derived class of RWDataInputStream.
RWXmlObjectInputStreamImp(RW_SL_IO_STD(istream)& sourceStream,
RW_SL_IO_STD(ios)*& formatter,
bool escape);
This constructor is the same as the one above, except that it also takes a pointer reference to an std::ios formatting object.
Before the XML stream is created, pass an empty formatting object pointer to this constructor through the make() function. This constructor, in defining the underlying character stream for the XML stream, creates a formatting object for the stream and places the address of that object in the pointer reference. The calling application can then use this formatting object to manipulate data formats in the XML stream. See the corresponding make() function description above for an example.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.