The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Private Member Functions | Private Attributes | List of all members
XmlWriter Class Referencefinal

#include <XmlWriter.hpp>

Public Member Functions

 XmlWriter (const XmlWriter &)=delete
 
 XmlWriter (std::ostream &outputStream, string streamName)
 
 XmlWriter (string filePath)
 
XmlWriteroperator= (const XmlWriter &)=delete
 
void writeAttribute (string name, string value)
 
void writeComment (string text)
 
void writeEndDocument ()
 
void writeEndElement ()
 
void writeStartDocument ()
 
void writeStartElement (string name)
 

Private Member Functions

void writeIndentation ()
 

Private Attributes

vector< string > _elementNames
 
std::ostream & _out
 
std::ofstream _outfile
 
bool _starting
 
string _streamName
 

Detailed Description

The XmlWriter class facilates writing the subset of XML that is sufficient to represent SMILE schemas and datasets. The output stream is garantueed to be a well-formed XML 1.0 document that also conforms to the limitations described for the XmlReader class, so that it can be parsed by that class.

When an error occurs while writing the XML data stream, the constructor and methods of this class throw a FatalError with an appropriate error message.

Constructor & Destructor Documentation

◆ XmlWriter() [1/3]

XmlWriter::XmlWriter ( std::ostream &  outputStream,
string  streamName 
)

This constructor accepts and retains a reference to the output stream to be written, and initializes the XML writer. The second argument provides a human readable string to identify the stream in error messages.

◆ XmlWriter() [2/3]

XmlWriter::XmlWriter ( string  filePath)

This constructor creates and opens the file with the specified path as the output stream to be written, and initializes the XML writer. The file path is used to identify the stream in error messages.

◆ XmlWriter() [3/3]

XmlWriter::XmlWriter ( const XmlWriter )
delete

The copy constructor is deleted because instances of this class should never be copied or moved.

Member Function Documentation

◆ operator=()

XmlWriter & XmlWriter::operator= ( const XmlWriter )
delete

The assignment operator is deleted because instances of this class should never be copied or moved.

◆ writeAttribute()

void XmlWriter::writeAttribute ( string  name,
string  value 
)

Writes an attribute with the specified name and value. This function can only be called after writeStartElement() before any further content is written.

◆ writeComment()

void XmlWriter::writeComment ( string  text)

Writes the specified text as XML comment. The text must not contain the forbidden sequence "--" or end with "-". Note that XML does not provide any way to escape "-" in a comment.

◆ writeEndDocument()

void XmlWriter::writeEndDocument ( )

Verifies that the number of writeStartElement() and writeEndElement() invocations match, and that the output stream is in a non-error state. If not, a FatalError is thrown. This function must be called once after any of the other functions are called.

◆ writeEndElement()

void XmlWriter::writeEndElement ( )

Closes the previous matching start element. For a particular XML document, the number of invocations of this function must exactly match the number of invocations of the writeStartElement() function. This is verified in the writeEndDocument() function.

◆ writeIndentation()

void XmlWriter::writeIndentation ( )
private

Writes \(4\times N\) spaces where \(N\) is the current element nesting depth.

◆ writeStartDocument()

void XmlWriter::writeStartDocument ( )

Writes a document start with the appropriate XML version and encoding information. This function must be called once before any of the other functions are called.

◆ writeStartElement()

void XmlWriter::writeStartElement ( string  name)

Writes a start element with the specified name. Subsequent calls to writeAttribute() will add attributes to this element.


The documentation for this class was generated from the following file: