Gyoto
GyotoFactory.h
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 
112 class Gyoto::Factory
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
142  SmartPointer<Scenery> scenery_;
144  SmartPointer<Metric::Generic> gg_;
146  SmartPointer<Screen> screen_;
148  SmartPointer<Astrobj::Generic> obj_;
150  SmartPointer<Photon> photon_;
152  SmartPointer<Spectrometer::Generic> spectro_;
153 
154  // Factory stuff
156  std::string filename_;
158  std::string kind_;
159 
160  public:
162  Factory(char * filename);
163 
165  Factory(SmartPointer<Scenery> sc);
167  Factory(SmartPointer<Metric::Generic> gg);
169  Factory(SmartPointer<Astrobj::Generic> ao);
171  Factory(SmartPointer<Spectrum::Generic> sp);
173  Factory(SmartPointer<Screen> screen);
175  Factory(SmartPointer<Photon> photon);
177  Factory(SmartPointer<Spectrometer::Generic> Spectrometer);
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 kind();
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 metric(SmartPointer<Metric::Generic> gg, xercesc::DOMElement *el);
258 
260 
265  void astrobj(SmartPointer<Astrobj::Generic> ao, xercesc::DOMElement *el);
266 
268 
273  void screen(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.
Pointers performing reference counting.
Definition: GyotoSmartPointer.h:51
Compile-time configuration.
Spectrum of a simple object (e.g. Star)
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:42
A single light ray.