GyotoFactory.h
Go to the documentation of this file.
#ifdef GYOTO_USE_XERCES
/*
Copyright 2011-2014, 2016, 2018 Thibaut Paumard, Frederic Vincent
This file is part of Gyoto.
Gyoto is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gyoto is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GyotoFactory_H_
#define __GyotoFactory_H_
#include <vector>
#include "GyotoConfig.h"
#ifndef XERCES_INCLUDE_WCHAR_H
#define XERCES_INCLUDE_WCHAR_H 0
#endif
#include <xercesc/sax/ErrorHandler.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <GyotoScenery.h>
#include <GyotoPhoton.h>
#include <GyotoSpectrum.h>
#include <sstream>
#include <string>
namespace Gyoto {
class Factory;
class FactoryMessenger;
namespace Spectrometer {
class Generic;
class Uniform;
}
}
class Gyoto::Factory
{
friend class Gyoto::FactoryMessenger;
protected:
// XERCES MACHINERY
xercesc::ErrorHandler *reporter_;
xercesc::DOMDocument *doc_;
xercesc::DOMElement *root_;
xercesc::XercesDOMParser *parser_;
xercesc::DOMXPathNSResolver* resolver_;
xercesc::DOMImplementation* impl_;
// Elements which must happen only once in a file
// but may happen about anywhere
xercesc::DOMElement *gg_el_;
xercesc::DOMElement *obj_el_;
xercesc::DOMElement *ph_el_;
// GYOTO elements
SmartPointer<Scenery> scenery_;
SmartPointer<Metric::Generic> gg_;
SmartPointer<Screen> screen_;
SmartPointer<Astrobj::Generic> obj_;
SmartPointer<Photon> photon_;
SmartPointer<Spectrometer::Generic> spectro_;
// Factory stuff
std::string filename_;
std::string kind_;
public:
Factory(char * filename);
Factory(SmartPointer<Scenery> sc);
Factory(SmartPointer<Metric::Generic> gg);
Factory(SmartPointer<Astrobj::Generic> ao);
Factory(SmartPointer<Spectrum::Generic> sp);
Factory(SmartPointer<Screen> screen);
Factory(SmartPointer<Photon> photon);
Factory(SmartPointer<Spectrometer::Generic> Spectrometer);
~Factory();
private:
void setReporter(xercesc::ErrorHandler*);
xercesc::DOMElement * getRoot();
xercesc::DOMDocument* getDoc();
public:
const std::string kind();
Gyoto::SmartPointer<Gyoto::Scenery> scenery();
Gyoto::SmartPointer<Gyoto::Metric::Generic> metric();
Gyoto::SmartPointer<Gyoto::Screen> screen();
Gyoto::SmartPointer<Gyoto::Astrobj::Generic> astrobj();
Gyoto::SmartPointer<Gyoto::Photon> photon();
Gyoto::SmartPointer<Gyoto::Spectrum::Generic> spectrum();
Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> spectrometer();
// XML OUTPUT
void write(const char* const fname=0);
std::string format();
// Setting elements
void metric(SmartPointer<Metric::Generic> gg, xercesc::DOMElement *el);
void astrobj(SmartPointer<Astrobj::Generic> ao, xercesc::DOMElement *el);
void screen(SmartPointer<Screen> scr, xercesc::DOMElement *el);
void setContent(std::string content, xercesc::DOMElement *el);
void setParameter(std::string name, xercesc::DOMElement *pel);
void setParameter(std::string name, double value,
xercesc::DOMElement *pel);
void setParameter(std::string name, int value,
xercesc::DOMElement *pel);
void setParameter(std::string name, unsigned int value,
xercesc::DOMElement *pel);
void setParameter(std::string name, long value,
xercesc::DOMElement *pel);
void setParameter(std::string name, unsigned long value,
xercesc::DOMElement *pel);
void setParameter(std::string name, std::string value,
xercesc::DOMElement*pel);
void setParameter(std::string name, double val[], size_t nelem,
xercesc::DOMElement* pel,
FactoryMessenger **child = NULL);
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);
};
#endif
#endif
GyotoConfig.h
Compile-time configuration.
GyotoPhoton.h
A single light ray.
GyotoScenery.h
Ray-tracing framework.
GyotoSpectrum.h
Spectrum of a simple object (e.g. Star).
Gyoto::Factory
XML input/output.
Definition GyotoFactory.h:115
Gyoto::Factory::setParameter
void setParameter(std::string name, double val[], size_t nelem, xercesc::DOMElement *pel, FactoryMessenger **child=NULL)
Create new XML element with array content.
Gyoto::Factory::gg_el_
xercesc::DOMElement * gg_el_
XML element representing the Metric.
Definition GyotoFactory.h:136
Gyoto::Factory::Factory
Factory(char *filename)
Constructor for reading a file.
Gyoto::Factory::astrobj
Gyoto::SmartPointer< Gyoto::Astrobj::Generic > astrobj()
Find Astrobj element, instantiate it and get it.
Gyoto::Factory::fullPath
std::string fullPath(std::string relpath)
Transform relative path into absolute path.
Gyoto::Factory::setContent
void setContent(std::string content, xercesc::DOMElement *el)
Set text content of XML element.
Gyoto::Factory::format
std::string format()
Get constructed XML representation as std::string.
Gyoto::Factory::parser_
xercesc::XercesDOMParser * parser_
Xerces parser.
Definition GyotoFactory.h:127
Gyoto::Factory::doc_
xercesc::DOMDocument * doc_
The document being read or written.
Definition GyotoFactory.h:123
Gyoto::Factory::setParameter
void setParameter(std::string name, unsigned int value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::gg_
SmartPointer< Metric::Generic > gg_
The Metric read from or written to Factory::doc_.
Definition GyotoFactory.h:146
Gyoto::Factory::Factory
Factory(SmartPointer< Scenery > sc)
Constructor for saving (or printing) a Scenery.
Gyoto::Factory::filename_
std::string filename_
XML file name, if actually reading from or writting to file.
Definition GyotoFactory.h:158
Gyoto::Factory::Factory
Factory(SmartPointer< Spectrum::Generic > sp)
Constructor for saving (or printing) a Spectrum.
Gyoto::Factory::getDoc
xercesc::DOMDocument * getDoc()
Get Factory::doc_.
Gyoto::Factory::setParameter
void setParameter(std::string name, long value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::spectrometer
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > spectrometer()
Find Spectrometer element, instantiate it and get it.
Gyoto::Factory::setParameter
void setParameter(std::string name, std::string value, xercesc::DOMElement *pel)
Create new XML element with string content.
Gyoto::Factory::kind
const std::string kind()
Get Factory::kind_.
Gyoto::Factory::Factory
Factory(SmartPointer< Screen > screen)
Constructor for saving (or printing) a Screen.
Gyoto::Factory::screen_
SmartPointer< Screen > screen_
The Screen read from or written to Factory::doc_.
Definition GyotoFactory.h:148
Gyoto::Factory::screen
Gyoto::SmartPointer< Gyoto::Screen > screen()
Find Screen element, instantiate it and get it.
Gyoto::Factory::scenery_
SmartPointer< Scenery > scenery_
The Scenery read from or written to Factory::doc_.
Definition GyotoFactory.h:144
Gyoto::Factory::kind_
std::string kind_
Kind of root element (Scenery, Metric etc.).
Definition GyotoFactory.h:160
Gyoto::Factory::Factory
Factory(SmartPointer< Astrobj::Generic > ao)
Constructor for saving (or printing) an Astrobj.
Gyoto::Factory::Factory
Factory(SmartPointer< Photon > photon)
Constructor for saving (or printing) a Photon.
Gyoto::Factory::impl_
xercesc::DOMImplementation * impl_
Xerces implementation.
Definition GyotoFactory.h:131
Gyoto::Factory::metric
void metric(SmartPointer< Metric::Generic > gg, xercesc::DOMElement *el)
Set Metric for this document.
Gyoto::Factory::Factory
Factory(SmartPointer< Metric::Generic > gg)
Constructor for saving (or printing) a Metric.
Gyoto::Factory::reporter_
xercesc::ErrorHandler * reporter_
Xerces error handler.
Definition GyotoFactory.h:121
Gyoto::Factory::ph_el_
xercesc::DOMElement * ph_el_
XML element representing the Photon.
Definition GyotoFactory.h:140
Gyoto::Factory::screen
void screen(SmartPointer< Screen > scr, xercesc::DOMElement *el)
Set Screen for this document.
Gyoto::Factory::getRoot
xercesc::DOMElement * getRoot()
Get Factory::root_.
Gyoto::Factory::write
void write(const char *const fname=0)
Write constructed XML representation to file.
Gyoto::Factory::photon_
SmartPointer< Photon > photon_
The Photon read from or written to Factory::doc_.
Definition GyotoFactory.h:152
Gyoto::Factory::resolver_
xercesc::DOMXPathNSResolver * resolver_
Xerces resolver.
Definition GyotoFactory.h:129
Gyoto::Factory::root_
xercesc::DOMElement * root_
Root element in Factory::doc_.
Definition GyotoFactory.h:125
Gyoto::Factory::scenery
Gyoto::SmartPointer< Gyoto::Scenery > scenery()
Find Scenery element, instantiate it and get it.
Gyoto::Factory::spectro_
SmartPointer< Spectrometer::Generic > spectro_
The Spectrometer read from or written to Factory::doc_.
Definition GyotoFactory.h:154
Gyoto::Factory::Factory
Factory(SmartPointer< Spectrometer::Generic > Spectrometer)
Constructor for saving (or printing) a Spectrometer.
Gyoto::Factory::setParameter
void setParameter(std::string name, double value, xercesc::DOMElement *pel)
Create new XML element with double value.
Gyoto::Factory::photon
Gyoto::SmartPointer< Gyoto::Photon > photon()
Find Photon element, instantiate it and get it.
Gyoto::Factory::obj_
SmartPointer< Astrobj::Generic > obj_
The Astrobj read from or written to Factory::doc_.
Definition GyotoFactory.h:150
Gyoto::Factory::~Factory
~Factory()
Destructor.
Gyoto::Factory::astrobj
void astrobj(SmartPointer< Astrobj::Generic > ao, xercesc::DOMElement *el)
Set Astrobj for this document.
Gyoto::Factory::spectrum
Gyoto::SmartPointer< Gyoto::Spectrum::Generic > spectrum()
Find Photon element, instantiate it and get it.
Gyoto::Factory::metric
Gyoto::SmartPointer< Gyoto::Metric::Generic > metric()
Find Metric element, instantiate it and get it.
Gyoto::Factory::setReporter
void setReporter(xercesc::ErrorHandler *)
Set Xerces reporter.
Gyoto::Factory::obj_el_
xercesc::DOMElement * obj_el_
XML element representing the Astrobj.
Definition GyotoFactory.h:138
Gyoto::Factory::setParameter
void setParameter(std::string name, unsigned long value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::setParameter
void setParameter(std::string name, int value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::setParameter
void setParameter(std::string name, xercesc::DOMElement *pel)
Create new XML element without content.
Gyoto::FactoryMessenger
Factory / SmartPointee::Subcontractor_t interface.
Definition GyotoFactoryMessenger.h:92
Gyoto::SmartPointer
Pointers performing reference counting.
Definition GyotoSmartPointer.h:135
Gyoto::Spectrometer
Access to spectrometers.
Definition GyotoComplexSpectrometer.h:34
Gyoto
Namespace for the Gyoto library.
Definition GyotoAstrobj.h:44