Gyoto
|
XML input/output. More...
#include <GyotoFactory.h>
Public Member Functions | |
Factory (char *filename) | |
Constructor for reading a file. More... | |
Factory (SmartPointer< Scenery > sc) | |
Constructor for saving (or printing) a Scenery. | |
Factory (SmartPointer< Metric::Generic > gg) | |
Constructor for saving (or printing) a Metric. | |
Factory (SmartPointer< Astrobj::Generic > ao) | |
Constructor for saving (or printing) an Astrobj. | |
Factory (SmartPointer< Spectrum::Generic > sp) | |
Constructor for saving (or printing) a Spectrum. | |
Factory (SmartPointer< Screen > screen) | |
Constructor for saving (or printing) a Screen. | |
Factory (SmartPointer< Photon > photon) | |
Constructor for saving (or printing) a Photon. | |
Factory (SmartPointer< Spectrometer::Generic > Spectrometer) | |
Constructor for saving (or printing) a Spectrometer. | |
~Factory () | |
Destructor. | |
const std::string | kind () |
Get Factory::kind_. | |
Gyoto::SmartPointer< Gyoto::Scenery > | scenery () |
Find Scenery element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Metric::Generic > | metric () |
Find Metric element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Screen > | screen () |
Find Screen element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Astrobj::Generic > | astrobj () |
Find Astrobj element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Photon > | photon () |
Find Photon element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Spectrum::Generic > | spectrum () |
Find Photon element, instantiate it and get it. More... | |
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > | spectrometer () |
Find Spectrometer element, instantiate it and get it. More... | |
void | write (const char *const fname=0) |
Write constructed XML representation to file. | |
std::string | format () |
Get constructed XML representation as std::string. | |
void | metric (SmartPointer< Metric::Generic > gg, xercesc::DOMElement *el) |
Set Metric for this document. More... | |
void | astrobj (SmartPointer< Astrobj::Generic > ao, xercesc::DOMElement *el) |
Set Astrobj for this document. More... | |
void | screen (SmartPointer< Screen > scr, xercesc::DOMElement *el) |
Set Screen for this document. More... | |
void | setContent (std::string content, xercesc::DOMElement *el) |
Set text content of XML element. | |
void | setParameter (std::string name, xercesc::DOMElement *pel) |
Create new XML element without content. More... | |
void | setParameter (std::string name, double value, xercesc::DOMElement *pel) |
Create new XML element with double value. More... | |
void | setParameter (std::string name, int value, xercesc::DOMElement *pel) |
Create new XML element with integer value. More... | |
void | setParameter (std::string name, unsigned int value, xercesc::DOMElement *pel) |
Create new XML element with integer value. More... | |
void | setParameter (std::string name, long value, xercesc::DOMElement *pel) |
Create new XML element with integer value. More... | |
void | setParameter (std::string name, unsigned long value, xercesc::DOMElement *pel) |
Create new XML element with integer value. More... | |
void | setParameter (std::string name, std::string value, xercesc::DOMElement *pel) |
Create new XML element with string content. More... | |
void | setParameter (std::string name, double val[], size_t nelem, xercesc::DOMElement *pel, FactoryMessenger **child=NULL) |
Create new XML element with array content. More... | |
void | setParameter (std::string name, std::vector< double > const &val, xercesc::DOMElement *pel, FactoryMessenger **child=NULL) |
void | setParameter (std::string name, std::vector< unsigned long > const &val, xercesc::DOMElement *pel, FactoryMessenger **child=NULL) |
std::string | fullPath (std::string relpath) |
Transform relative path into absolute path. More... | |
Protected Attributes | |
xercesc::ErrorHandler * | reporter_ |
Xerces error handler. | |
xercesc::DOMDocument * | doc_ |
The document being read or written. | |
xercesc::DOMElement * | root_ |
Root element in Factory::doc_. | |
xercesc::XercesDOMParser * | parser_ |
Xerces parser. | |
xercesc::DOMXPathNSResolver * | resolver_ |
Xerces resolver. | |
xercesc::DOMImplementation * | impl_ |
Xerces implementation. | |
xercesc::DOMElement * | gg_el_ |
XML element representing the Metric. | |
xercesc::DOMElement * | obj_el_ |
XML element representing the Astrobj. | |
xercesc::DOMElement * | ph_el_ |
XML element representing the Photon. | |
SmartPointer< Scenery > | scenery_ |
The Scenery read from or written to Factory::doc_. | |
SmartPointer< Metric::Generic > | gg_ |
The Metric read from or written to Factory::doc_. | |
SmartPointer< Screen > | screen_ |
The Screen read from or written to Factory::doc_. | |
SmartPointer< Astrobj::Generic > | obj_ |
The Astrobj read from or written to Factory::doc_. | |
SmartPointer< Photon > | photon_ |
The Photon read from or written to Factory::doc_. | |
SmartPointer< Spectrometer::Generic > | spectro_ |
The Spectrometer read from or written to Factory::doc_. | |
std::string | filename_ |
XML file name, if actually reading from or writting to file. | |
std::string | kind_ |
Kind of root element (Scenery, Metric etc.) | |
Private Member Functions | |
void | setReporter (xercesc::ErrorHandler *) |
Set Xerces reporter. | |
xercesc::DOMElement * | getRoot () |
Get Factory::root_. | |
xercesc::DOMDocument * | getDoc () |
Get Factory::doc_. | |
Friends | |
class | Gyoto::FactoryMessenger |
XML input/output.
The Factory is responsible from building objects from their XML description, and from saving an XML description of existing objects. Since the Factory doesn't know how to build the variety of objects available in Gyoto and in external plug-ins, the Factory orders Metric, Astrobj and Spectrum objects from registered subcontractors (see SmartPointee::Subcontractor_t). The factory an the various subcontractors communicate through a FactoryMessenger.
To read an XML file, you simply create an instance of the Factory with a filename, and get whichever object type you are interested in:
or, for a single object and without checking the kind (kind()) first:
Writing an object to a file is even easier. Assuming "object" below is a Gyoto::SmartPointer<class> where "class" is one of Scenery, Metric::Generic, Astrobj::Generic, Spectrum::Generic, Screen, Photon or Spectrometer:
or, for short:
You can also directly display the object to stdout:
Gyoto::Factory::Factory | ( | char * | filename | ) |
Constructor for reading a file.
If filename starts with "<?xml", it is interpreted as XML data and parsed directly (with no file access). It is possible to parse a file that actually starts with those unlikely characters by escaping the first with '\'. If filename starts with '\', this single character is always stripped.
Gyoto::SmartPointer< Gyoto::Astrobj::Generic > Gyoto::Factory::astrobj | ( | ) |
void Gyoto::Factory::astrobj | ( | SmartPointer< Astrobj::Generic > | ao, |
xercesc::DOMElement * | el | ||
) |
Set Astrobj for this document.
If called several times for the same document, the astrobj SmartPointers must point to the same instance or an error will be thrown using Gyoto::throwError().
std::string Gyoto::Factory::fullPath | ( | std::string | relpath | ) |
Transform relative path into absolute path.
relpath is interpreted as follows:
If it starts with "/", it is interpreted as an absolute path and is returned as is.
If it is prefixed with "`pwd`/", the rest of relpath is interpreted as relative to the current working directory, i.e. fullPath() tries to mimic how the shell would expand relpath into an absolute path.
In any other circumstance, relpath is interpreted to relative to the directory where the XML file resides.
relpath | Path specification. |
Gyoto::SmartPointer< Gyoto::Metric::Generic > Gyoto::Factory::metric | ( | ) |
void Gyoto::Factory::metric | ( | SmartPointer< Metric::Generic > | gg, |
xercesc::DOMElement * | el | ||
) |
Set Metric for this document.
If called several times for the same document, the metric SmartPointers must point to the same instance or an error will be thrown using Gyoto::throwError().
Gyoto::SmartPointer< Gyoto::Photon > Gyoto::Factory::photon | ( | ) |
Gyoto::SmartPointer< Gyoto::Scenery > Gyoto::Factory::scenery | ( | ) |
Gyoto::SmartPointer< Gyoto::Screen > Gyoto::Factory::screen | ( | ) |
void Gyoto::Factory::screen | ( | SmartPointer< Screen > | scr, |
xercesc::DOMElement * | el | ||
) |
Set Screen for this document.
If called several times for the same document, the screen SmartPointers must point to the same instance or an error will be thrown using Gyoto::throwError().
void Gyoto::Factory::setParameter | ( | std::string | name, |
double | val[], | ||
size_t | nelem, | ||
xercesc::DOMElement * | pel, | ||
FactoryMessenger ** | child = NULL |
||
) |
Create new XML element with array content.
E.g.
[in] | name | XML entity name. |
[in] | val | Entity content. |
[in] | nelem | Number of elements in val to output. |
[in] | pel | Parent XML element. |
[out] | child | If not NULL, set to a new Gyoto::FactoryMessenger pointing to the new element. It must be deleted later. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
double | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with double value.
E.g.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
int | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with integer value.
E.g.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
long | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with integer value.
E.g.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
std::string | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with string content.
E.g.
Any parameter can acually be set this way if total control over Text formatting is wished for.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
unsigned int | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with integer value.
E.g.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
unsigned long | value, | ||
xercesc::DOMElement * | pel | ||
) |
Create new XML element with integer value.
E.g.
name | XML entity name. |
value | Entity content. |
pel | Parent XML element. |
void Gyoto::Factory::setParameter | ( | std::string | name, |
xercesc::DOMElement * | pel | ||
) |
Create new XML element without content.
E.g.
name | XML entity name. |
pel | Parent XML element. |
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > Gyoto::Factory::spectrometer | ( | ) |
Find Spectrometer element, instantiate it and get it.
Spectrometer may be either the root element or directly within the root element.
Gyoto::SmartPointer< Gyoto::Spectrum::Generic > Gyoto::Factory::spectrum | ( | ) |