Gyoto
GyotoFactory.h
Go to the documentation of this file.
1 #ifdef GYOTO_USE_XERCES
2 
10 /*
11  Copyright 2011-2014, 2016, 2018 Thibaut Paumard, Frederic Vincent
12 
13  This file is part of Gyoto.
14 
15  Gyoto is free software: you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  Gyoto is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef __GyotoFactory_H_
30 #define __GyotoFactory_H_
31 
32 #include <vector>
33 
34 #include "GyotoConfig.h"
35 
37 
41 #ifndef XERCES_INCLUDE_WCHAR_H
42 #define XERCES_INCLUDE_WCHAR_H 0
43 #endif
44 
45 #include <xercesc/sax/ErrorHandler.hpp>
46 #include <xercesc/dom/DOM.hpp>
47 #include <xercesc/parsers/XercesDOMParser.hpp>
48 #include <GyotoScenery.h>
49 #include <GyotoPhoton.h>
50 #include <GyotoSpectrum.h>
51 #include <sstream>
52 #include <string>
53 
54 namespace Gyoto {
55  class Factory;
56  class FactoryMessenger;
57  namespace Spectrometer {
58  class Generic;
59  class Uniform;
60  }
61 }
62 
115 {
116  friend class Gyoto::FactoryMessenger;
117 
118  protected:
119  // XERCES MACHINERY
121  xercesc::ErrorHandler *reporter_;
123  xercesc::DOMDocument *doc_;
125  xercesc::DOMElement *root_;
127  xercesc::XercesDOMParser *parser_;
129  xercesc::DOMXPathNSResolver* resolver_;
131  xercesc::DOMImplementation* impl_;
132 
133  // Elements which must happen only once in a file
134  // but may happen about anywhere
136  xercesc::DOMElement *gg_el_;
138  xercesc::DOMElement *obj_el_;
140  xercesc::DOMElement *ph_el_;
141 
142  // GYOTO elements
155 
156  // Factory stuff
158  std::string filename_;
160  std::string kind_;
161 
162  public:
164 
171  Factory(char * filename);
172 
187 
190 
191  private:
193  void setReporter(xercesc::ErrorHandler*);
195  xercesc::DOMElement * getRoot();
197  xercesc::DOMDocument* getDoc();
198 
199  public:
201  const std::string kind();
202 
204 
209 
211 
216 
218 
223 
225 
230 
232 
237 
239 
244 
246 
251 
252  // XML OUTPUT
254  void write(const char* const fname=0);
255 
257  std::string format();
258 
259  // Setting elements
261 
266  void metric(SmartPointer<Metric::Generic> gg, xercesc::DOMElement *el);
267 
269 
274  void astrobj(SmartPointer<Astrobj::Generic> ao, xercesc::DOMElement *el);
275 
277 
282  void screen(SmartPointer<Screen> scr, xercesc::DOMElement *el);
283 
285  void setContent(std::string content, xercesc::DOMElement *el);
286 
288 
296  void setParameter(std::string name, xercesc::DOMElement *pel);
297 
299 
308  void setParameter(std::string name, double value,
309  xercesc::DOMElement *pel);
310 
312 
321  void setParameter(std::string name, int value,
322  xercesc::DOMElement *pel);
323 
325 
334  void setParameter(std::string name, unsigned int value,
335  xercesc::DOMElement *pel);
336 
338 
347  void setParameter(std::string name, long value,
348  xercesc::DOMElement *pel);
349 
351 
360  void setParameter(std::string name, unsigned long value,
361  xercesc::DOMElement *pel);
362 
364 
376  void setParameter(std::string name, std::string value,
377  xercesc::DOMElement*pel);
378 
380 
392  void setParameter(std::string name, double val[], size_t nelem,
393  xercesc::DOMElement* pel,
394  FactoryMessenger **child = NULL);
395 
396  void setParameter(std::string name, std::vector<double> const &val,
397  xercesc::DOMElement* pel,
398  FactoryMessenger **child = NULL);
399 
400  void setParameter(std::string name, std::vector<unsigned long> const &val,
401  xercesc::DOMElement* pel,
402  FactoryMessenger **child = NULL);
403 
405 
422  std::string fullPath(std::string relpath);
423 };
424 
425 #endif
426 #endif
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::getDoc
xercesc::DOMDocument * getDoc()
Get Factory::doc_.
Gyoto::Factory::setParameter
void setParameter(std::string name, xercesc::DOMElement *pel)
Create new XML element without content.
Gyoto::Factory::resolver_
xercesc::DOMXPathNSResolver * resolver_
Xerces resolver.
Definition: GyotoFactory.h:129
Gyoto::Factory::photon_
SmartPointer< Photon > photon_
The Photon read from or written to Factory::doc_.
Definition: GyotoFactory.h:152
Gyoto::Factory::metric
void metric(SmartPointer< Metric::Generic > gg, xercesc::DOMElement *el)
Set Metric for this document.
Gyoto::Factory::fullPath
std::string fullPath(std::string relpath)
Transform relative path into absolute path.
Gyoto::Factory::setParameter
void setParameter(std::string name, std::string value, xercesc::DOMElement *pel)
Create new XML element with string content.
Gyoto::Factory::kind_
std::string kind_
Kind of root element (Scenery, Metric etc.)
Definition: GyotoFactory.h:160
Gyoto::FactoryMessenger
Factory / SmartPointee::Subcontractor_t interface.
Definition: GyotoFactoryMessenger.h:92
GyotoScenery.h
Ray-tracing framework.
Gyoto::Factory::impl_
xercesc::DOMImplementation * impl_
Xerces implementation.
Definition: GyotoFactory.h:131
Gyoto::Factory::screen
void screen(SmartPointer< Screen > scr, xercesc::DOMElement *el)
Set Screen for this document.
Gyoto::Factory::format
std::string format()
Get constructed XML representation as std::string.
Gyoto::Factory::~Factory
~Factory()
Destructor.
Gyoto::Factory::metric
Gyoto::SmartPointer< Gyoto::Metric::Generic > metric()
Find Metric element, instantiate it and get it.
Gyoto::Factory::filename_
std::string filename_
XML file name, if actually reading from or writting to file.
Definition: GyotoFactory.h:158
Gyoto::Factory::doc_
xercesc::DOMDocument * doc_
The document being read or written.
Definition: GyotoFactory.h:123
GyotoPhoton.h
A single light ray.
Gyoto::Factory::screen_
SmartPointer< Screen > screen_
The Screen read from or written to Factory::doc_.
Definition: GyotoFactory.h:148
Gyoto::Factory::Factory
Factory(SmartPointer< Scenery > sc)
Constructor for saving (or printing) a Scenery.
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::obj_
SmartPointer< Astrobj::Generic > obj_
The Astrobj read from or written to Factory::doc_.
Definition: GyotoFactory.h:150
Gyoto
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43
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, double value, xercesc::DOMElement *pel)
Create new XML element with double value.
Gyoto::Factory::parser_
xercesc::XercesDOMParser * parser_
Xerces parser.
Definition: GyotoFactory.h:127
Gyoto::Factory::scenery_
SmartPointer< Scenery > scenery_
The Scenery read from or written to Factory::doc_.
Definition: GyotoFactory.h:144
Gyoto::Factory::obj_el_
xercesc::DOMElement * obj_el_
XML element representing the Astrobj.
Definition: GyotoFactory.h:138
Gyoto::Factory::Factory
Factory(SmartPointer< Spectrum::Generic > sp)
Constructor for saving (or printing) a Spectrum.
Gyoto::SmartPointer
Pointers performing reference counting.
Definition: GyotoSmartPointer.h:135
Gyoto::Factory::ph_el_
xercesc::DOMElement * ph_el_
XML element representing the Photon.
Definition: GyotoFactory.h:140
Gyoto::Factory::setReporter
void setReporter(xercesc::ErrorHandler *)
Set Xerces reporter.
Gyoto::Factory::Factory
Factory(SmartPointer< Spectrometer::Generic > Spectrometer)
Constructor for saving (or printing) a Spectrometer.
Gyoto::Factory::astrobj
Gyoto::SmartPointer< Gyoto::Astrobj::Generic > astrobj()
Find Astrobj element, instantiate it and get it.
Gyoto::Factory::photon
Gyoto::SmartPointer< Gyoto::Photon > photon()
Find Photon element, instantiate it and get it.
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::write
void write(const char *const fname=0)
Write constructed XML representation to file.
Gyoto::Factory::astrobj
void astrobj(SmartPointer< Astrobj::Generic > ao, xercesc::DOMElement *el)
Set Astrobj for this document.
Gyoto::Factory::setParameter
void setParameter(std::string name, int value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::Factory
Factory(SmartPointer< Photon > photon)
Constructor for saving (or printing) a Photon.
Gyoto::Factory::Factory
Factory(SmartPointer< Metric::Generic > gg)
Constructor for saving (or printing) a Metric.
Gyoto::Factory::getRoot
xercesc::DOMElement * getRoot()
Get Factory::root_.
Gyoto::Factory::kind
const std::string kind()
Get Factory::kind_.
Gyoto::Factory::gg_
SmartPointer< Metric::Generic > gg_
The Metric read from or written to Factory::doc_.
Definition: GyotoFactory.h:146
Gyoto::Factory::setContent
void setContent(std::string content, xercesc::DOMElement *el)
Set text content of XML element.
Gyoto::Factory::spectrometer
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > spectrometer()
Find Spectrometer element, instantiate it and get it.
Gyoto::Factory::Factory
Factory(SmartPointer< Screen > screen)
Constructor for saving (or printing) a Screen.
Gyoto::Factory
XML input/output.
Definition: GyotoFactory.h:115
Gyoto::Factory::setParameter
void setParameter(std::string name, long value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::spectrum
Gyoto::SmartPointer< Gyoto::Spectrum::Generic > spectrum()
Find Photon element, instantiate it and get it.
Gyoto::Factory::screen
Gyoto::SmartPointer< Gyoto::Screen > screen()
Find Screen element, instantiate it and get it.
Gyoto::Factory::setParameter
void setParameter(std::string name, unsigned int value, xercesc::DOMElement *pel)
Create new XML element with integer value.
Gyoto::Factory::spectro_
SmartPointer< Spectrometer::Generic > spectro_
The Spectrometer read from or written to Factory::doc_.
Definition: GyotoFactory.h:154
Gyoto::Factory::reporter_
xercesc::ErrorHandler * reporter_
Xerces error handler.
Definition: GyotoFactory.h:121
GyotoSpectrum.h
Spectrum of a simple object (e.g. Star)
GyotoConfig.h
Compile-time configuration.
Gyoto::Factory::Factory
Factory(SmartPointer< Astrobj::Generic > ao)
Constructor for saving (or printing) an Astrobj.