Gyoto::Factory Class Reference

XML input/output. More...

#include <GyotoFactory.h>

List of all members.

Public Member Functions

 Factory (char *filename)
 Constructor for reading a file.
 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
getScenery ()
 Find Scenery element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Metric::Generic
metric ()
 Find Metric element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Screen
screen ()
 Find Screen element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Astrobj::Generic
astrobj ()
 Find Astrobj element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Photon
getPhoton ()
 Find Photon element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Spectrum::Generic
spectrum ()
 Find Photon element, instantiate it and get it.
Gyoto::SmartPointer
< Gyoto::Spectrometer::Generic
spectrometer ()
 Find Spectrometer element, instantiate it and get it.
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.
void astrobj (SmartPointer< Astrobj::Generic > ao, xercesc::DOMElement *el)
 Set Astrobj for this document.
void screen (SmartPointer< Screen > scr, xercesc::DOMElement *el)
 Set Screen for this document.
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.
void setParameter (std::string name, double value, xercesc::DOMElement *pel)
 Create new XML element with double value.
void setParameter (std::string name, int value, xercesc::DOMElement *pel)
 Create new XML element with integer value.
void setParameter (std::string name, unsigned int value, xercesc::DOMElement *pel)
 Create new XML element with integer value.
void setParameter (std::string name, long value, xercesc::DOMElement *pel)
 Create new XML element with integer value.
void setParameter (std::string name, unsigned long value, xercesc::DOMElement *pel)
 Create new XML element with integer value.
void setParameter (std::string name, std::string value, xercesc::DOMElement *pel)
 Create new XML element with string content.
void setParameter (std::string name, double val[], size_t nelem, xercesc::DOMElement *pel, FactoryMessenger **child=NULL)
 Create new XML element with array content.
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.

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< Sceneryscenery_
 The Scenery read from or written to Factory::doc_.
SmartPointer< Metric::Genericgg_
 The Metric read from or written to Factory::doc_.
SmartPointer< Screenscreen_
 The Screen read from or written to Factory::doc_.
SmartPointer< Astrobj::Genericobj_
 The Astrobj read from or written to Factory::doc_.
SmartPointer< Photonphoton_
 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

Detailed Description

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:

  Gyoto::Factory * factory = new Gyoto::Factory("some/input/file.xml");
  const std::string kind = factory->kind();
  if (kind.compare("Scenery")) Gyoto::throwError("I wan't a Scenery");
  Gyoto::SmartPointer<Gyoto::Scenery> scenery = factory -> getScenery();
  Gyoto::SmartPointer<Gyoto::Screen>  screen = scenery->screen();
  Gyoto::SmartPointer<Gyoto::Astrobj::Generic> object = scenery->astrobj();
  Gyoto::SmartPointer<Gyoto::Metric::Generic> metric = scenery->metric();
  delete factory; factory=NULL;

or, for a single object and without checking the kind (kind()) first:

  Gyoto::SmartPointer<Gyoto::Scenery> scenery = Factory("some/input/file.xml").getScenery();

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:

  Gyoto::Factory * factory = new Gyoto::Factory(object);
  factory -> write("some/output/file.xml");
  delete factory; factory=NULL;

or, for short:

  Gyoto::Factory(object).write("some/output/file.xml");

You can also directly display the object to stdout:

  std::cout << Gyoto::Factory(object).format() << std::endl;

Constructor & Destructor Documentation

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.


Member Function Documentation

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().

Gyoto::SmartPointer<Gyoto::Astrobj::Generic> Gyoto::Factory::astrobj (  ) 

Find Astrobj element, instantiate it and get it.

Astrobj may be either the root element or directly within the root element.

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.

Parameters:
relpath Path specification.
Returns:
Absolute path to same file.
Gyoto::SmartPointer<Gyoto::Photon> Gyoto::Factory::getPhoton (  ) 

Find Photon element, instantiate it and get it.

Photon may be either the root element or directly within the root element.

Gyoto::SmartPointer<Gyoto::Scenery> Gyoto::Factory::getScenery (  ) 

Find Scenery element, instantiate it and get it.

Scenery must be the root element. getScenery() will call metric(), astrobj() and screen().

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::Metric::Generic> Gyoto::Factory::metric (  ) 

Find Metric element, instantiate it and get it.

Metric may be either the root element or directly within the root element.

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().

Gyoto::SmartPointer<Gyoto::Screen> Gyoto::Factory::screen (  ) 

Find Screen element, instantiate it and get it.

Screen may be either the root element or directly within the root element.

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.

 <Position> 0. 10. 3.14. 0. </Position>
Parameters:
[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,
std::string  value,
xercesc::DOMElement *  pel 
)

Create new XML element with string content.

E.g.

 <StringParameter> Text </StringParameter>

Any parameter can acually be set this way if total control over Text formatting is wished for.

Parameters:
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.

 <IntParameter> 7 </IntParameter>
Parameters:
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.

 <IntParameter> 7 </IntParameter>
Parameters:
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.

 <IntParameter> 7 </IntParameter>
Parameters:
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.

 <IntParameter> 7 </IntParameter>
Parameters:
name XML entity name.
value Entity content.
pel Parent XML element.
void Gyoto::Factory::setParameter ( std::string  name,
double  value,
xercesc::DOMElement *  pel 
)

Create new XML element with double value.

E.g.

 <Radius> 2. </Radius>
Parameters:
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.

 <OpticallyThin/>
Parameters:
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 (  ) 

Find Photon element, instantiate it and get it.

Photon may be either the root element or directly within the root element.


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

Generated on 22 Jul 2017 for Gyoto by  doxygen 1.6.1