Gyoto
GyotoFactory.h
Go to the documentation of this file.
1 #ifdef GYOTO_USE_XERCES
2 
10 /*
11  Copyright 2011 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 "GyotoConfig.h"
33 
35 
39 #ifndef XERCES_INCLUDE_WCHAR_H
40 #define XERCES_INCLUDE_WCHAR_H 0
41 #endif
42 
43 #include <xercesc/sax/ErrorHandler.hpp>
44 #include <xercesc/dom/DOM.hpp>
45 #include <xercesc/parsers/XercesDOMParser.hpp>
46 #include <GyotoScenery.h>
47 #include <GyotoPhoton.h>
48 #include <GyotoSpectrum.h>
49 #include <sstream>
50 #include <string>
51 
52 namespace Gyoto {
53  class Factory;
54  class FactoryMessenger;
55  namespace Spectrometer {
56  class Generic;
57  class Uniform;
58  }
59 }
60 
113 {
114  friend class Gyoto::FactoryMessenger;
115 
116  protected:
117  // XERCES MACHINERY
119  xercesc::ErrorHandler *reporter_;
121  xercesc::DOMDocument *doc_;
123  xercesc::DOMElement *root_;
125  xercesc::XercesDOMParser *parser_;
127  xercesc::DOMXPathNSResolver* resolver_;
129  xercesc::DOMImplementation* impl_;
130 
131  // Elements which must happen only once in a file
132  // but may happen about anywhere
134  xercesc::DOMElement *gg_el_;
136  xercesc::DOMElement *obj_el_;
138  xercesc::DOMElement *ph_el_;
139 
140  // GYOTO elements
153 
154  // Factory stuff
156  std::string filename_;
158  std::string kind_;
159 
160  public:
162  Factory(char * filename);
163 
178 
180  ~Factory();
181 
182  private:
184  void setReporter(xercesc::ErrorHandler*);
186  xercesc::DOMElement * getRoot();
188  xercesc::DOMDocument* getDoc();
189 
190  public:
192  const std::string getKind();
193 
195 
200 
202 
207 
209 
214 
216 
221 
223 
228 
230 
235 
237 
242 
243  // XML OUTPUT
245  void write(const char* const fname=0);
246 
248  std::string format();
249 
250  // Setting elements
252 
257  void setMetric(SmartPointer<Metric::Generic> gg, xercesc::DOMElement *el);
258 
260 
265  void setAstrobj(SmartPointer<Astrobj::Generic> ao, xercesc::DOMElement *el);
266 
268 
273  void setScreen(SmartPointer<Screen> scr, xercesc::DOMElement *el);
274 
276  void setContent(std::string content, xercesc::DOMElement *el);
277 
279 
287  void setParameter(std::string name, xercesc::DOMElement *pel);
288 
290 
299  void setParameter(std::string name, double value,
300  xercesc::DOMElement *pel);
301 
303 
312  void setParameter(std::string name, int value,
313  xercesc::DOMElement *pel);
314 
316 
325  void setParameter(std::string name, unsigned int value,
326  xercesc::DOMElement *pel);
327 
329 
338  void setParameter(std::string name, long value,
339  xercesc::DOMElement *pel);
340 
342 
351  void setParameter(std::string name, unsigned long value,
352  xercesc::DOMElement *pel);
353 
355 
367  void setParameter(std::string name, std::string value,
368  xercesc::DOMElement*pel);
369 
371 
383  void setParameter(std::string name, double val[], size_t nelem,
384  xercesc::DOMElement* pel,
385  FactoryMessenger **child = NULL);
386 
388 
392  std::string fullPath(std::string relpath);
393 };
394 
395 #endif
396 #endif
Ray-tracing framework.
xercesc::DOMImplementation * impl_
Xerces implementation.
Definition: GyotoFactory.h:129
Gyoto::SmartPointer< Gyoto::Scenery > getScenery()
Find Scenery element, instanciate it and get it.
std::string filename_
XML file name, if actually reading from or writting to file.
Definition: GyotoFactory.h:156
std::string format()
Get constructed XML representation as std::string.
SmartPointer< Screen > screen_
The Screen read from or written to Factory::doc_.
Definition: GyotoFactory.h:146
Factory(char *filename)
Constructor for reading a file.
void setParameter(std::string name, xercesc::DOMElement *pel)
Create new XML element without content.
void setAstrobj(SmartPointer< Astrobj::Generic > ao, xercesc::DOMElement *el)
Set Astrobj for this document.
void setScreen(SmartPointer< Screen > scr, xercesc::DOMElement *el)
Set Screen for this document.
SmartPointer< Photon > photon_
The Photon read from or written to Factory::doc_.
Definition: GyotoFactory.h:150
Factory / SmartPointee::Subcontractor_t interface.
Definition: GyotoFactoryMessenger.h:91
xercesc::DOMXPathNSResolver * resolver_
Xerces resolver.
Definition: GyotoFactory.h:127
std::string fullPath(std::string relpath)
Transform relative path into absolute path.
std::string kind_
Kind of root element (Scenery, Metric etc.)
Definition: GyotoFactory.h:158
xercesc::XercesDOMParser * parser_
Xerces parser.
Definition: GyotoFactory.h:125
xercesc::DOMDocument * doc_
The document being read or written.
Definition: GyotoFactory.h:121
void setReporter(xercesc::ErrorHandler *)
Set Xerces reporter.
~Factory()
Destructor.
Compile-time configuration.
xercesc::DOMElement * obj_el_
XML element representing the Astrobj.
Definition: GyotoFactory.h:136
Gyoto::SmartPointer< Gyoto::Astrobj::Generic > getAstrobj()
Find Astrobj element, instanciate it and get it.
xercesc::DOMElement * ph_el_
XML element representing the Photon.
Definition: GyotoFactory.h:138
Gyoto::SmartPointer< Gyoto::Screen > getScreen()
Find Screen element, instanciate it and get it.
xercesc::DOMElement * getRoot()
Get Factory::root_.
Gyoto::SmartPointer< Gyoto::Spectrum::Generic > getSpectrum()
Find Photon element, instanciate it and get it.
Spectrum of a simple object (e.g. Star)
xercesc::DOMElement * root_
Root element in Factory::doc_.
Definition: GyotoFactory.h:123
SmartPointer< Metric::Generic > gg_
The Metric read from or written to Factory::doc_.
Definition: GyotoFactory.h:144
Gyoto::SmartPointer< Gyoto::Metric::Generic > getMetric()
Find Metric element, instanciate it and get it.
Pointers performing reference counting.
Definition: GyotoSmartPointer.h:51
SmartPointer< Astrobj::Generic > obj_
The Astrobj read from or written to Factory::doc_.
Definition: GyotoFactory.h:148
void setMetric(SmartPointer< Metric::Generic > gg, xercesc::DOMElement *el)
Set Metric for this document.
xercesc::ErrorHandler * reporter_
Xerces error handler.
Definition: GyotoFactory.h:119
SmartPointer< Spectrometer::Generic > spectro_
The Spectrometer read from or written to Factory::doc_.
Definition: GyotoFactory.h:152
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > getSpectrometer()
Find Spectrometer element, instanciate it and get it.
XML input/output.
Definition: GyotoFactory.h:112
Gyoto::SmartPointer< Gyoto::Photon > getPhoton()
Find Photon element, instanciate it and get it.
xercesc::DOMDocument * getDoc()
Get Factory::doc_.
SmartPointer< Scenery > scenery_
The Scenery read from or written to Factory::doc_.
Definition: GyotoFactory.h:142
xercesc::DOMElement * gg_el_
XML element representing the Metric.
Definition: GyotoFactory.h:134
const std::string getKind()
Get Factory::kind_.
void write(const char *const fname=0)
Write constructed XML representation to file.
void setContent(std::string content, xercesc::DOMElement *el)
Set text content of XML element.
A single light ray.