This file is indexed.

/usr/include/Gyoto/GyotoFactory.h is in libgyoto4-dev 1.0.2-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#ifdef GYOTO_USE_XERCES

/**
 * \file GyotoFactory.h
 * \brief XML I/O
 *
 * The Factory is a place where objects are built.
 *
 */
/*
    Copyright 2011 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"

/// Xerces internal.
/**
 * For some reason it sometimes need to be set to 0 instead of being
 * undefined.
 */
#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
 * \brief 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:
 * \code
 *  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;
 * \endcode or, for a single object and without checking the kind
 * (kind()) first:
 * \code
 *  Gyoto::SmartPointer<Gyoto::Scenery> scenery = Factory("some/input/file.xml").getScenery();
 * \endcode
 *
 *
 * 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:
 * \code
 *  Gyoto::Factory * factory = new Gyoto::Factory(object);
 *  factory -> write("some/output/file.xml");
 *  delete factory; factory=NULL;
 * \endcode
 *
 * or, for short:
 * \code
 *  Gyoto::Factory(object).write("some/output/file.xml");
 * \endcode
 *
 * You can also directly display the object to stdout:
 * \code
 *  std::cout << Gyoto::Factory(object).format() << std::endl;
 * \endcode
 */
class Gyoto::Factory
{
  friend class Gyoto::FactoryMessenger;

 protected:
  // XERCES MACHINERY
  /// Xerces error handler 
  xercesc::ErrorHandler *reporter_;
  /// The document being read or written
  xercesc::DOMDocument *doc_;
  /// Root element in Factory::doc_
  xercesc::DOMElement *root_;
  /// Xerces parser
  xercesc::XercesDOMParser *parser_;
  /// Xerces resolver
  xercesc::DOMXPathNSResolver* resolver_;
  /// Xerces implementation
  xercesc::DOMImplementation* impl_;

  // Elements which must happen only once in a file
  // but may happen about anywhere
  /// XML element representing the Metric
  xercesc::DOMElement *gg_el_;
  /// XML element representing the Astrobj
  xercesc::DOMElement *obj_el_;
  /// XML element representing the Photon
  xercesc::DOMElement *ph_el_;

  // GYOTO elements
  /// The Scenery read from or written to Factory::doc_
  SmartPointer<Scenery> scenery_;
  /// The Metric read from or written to Factory::doc_
  SmartPointer<Metric::Generic> gg_;
  /// The Screen read from or written to Factory::doc_
  SmartPointer<Screen> screen_; 
  /// The Astrobj read from or written to Factory::doc_
  SmartPointer<Astrobj::Generic> obj_;
  /// The Photon read from or written to Factory::doc_
  SmartPointer<Photon> photon_;
  /// The Spectrometer read from or written to Factory::doc_
  SmartPointer<Spectrometer::Generic> spectro_;

  // Factory stuff
  /// XML file name, if actually reading from or writting to file.
  std::string filename_;
  /// Kind of root element (Scenery, Metric etc.)
  std::string kind_;

 public:
  /// 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.
   */
  Factory(char * filename);

  /// Constructor for saving (or printing) a Scenery
  Factory(SmartPointer<Scenery> sc);
  /// Constructor for saving (or printing) a Metric
  Factory(SmartPointer<Metric::Generic> gg);
  /// Constructor for saving (or printing) an Astrobj
  Factory(SmartPointer<Astrobj::Generic> ao);
  /// Constructor for saving (or printing) a Spectrum
  Factory(SmartPointer<Spectrum::Generic> sp);
  /// Constructor for saving (or printing) a Screen
  Factory(SmartPointer<Screen> screen);
  /// Constructor for saving (or printing) a Photon
  Factory(SmartPointer<Photon> photon);
  /// Constructor for saving (or printing) a Spectrometer
  Factory(SmartPointer<Spectrometer::Generic> Spectrometer);

  /// Destructor
  ~Factory();

 private:
  /// Set Xerces reporter
  void setReporter(xercesc::ErrorHandler*);
  /// Get Factory::root_
  xercesc::DOMElement * getRoot();
  /// Get Factory::doc_
  xercesc::DOMDocument* getDoc();

 public:
  /// Get Factory::kind_
  const std::string kind();

  /// Find Scenery element, instanciate it and get it.
  /**
   * Scenery must be the root element. getScenery() will call
   * metric(), astrobj() and screen().
   */
  Gyoto::SmartPointer<Gyoto::Scenery> getScenery();

  /// Find Metric element, instanciate it and get it.
  /**
   * Metric may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Metric::Generic>  metric();

  /// Find Screen element, instanciate it and get it.
  /**
   * Screen may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Screen>  screen();

  /// Find Astrobj element, instanciate it and get it.
  /**
   * Astrobj may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Astrobj::Generic> astrobj();

  /// Find Photon element, instanciate it and get it.
  /**
   * Photon may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Photon>  getPhoton();

  /// Find Photon element, instanciate it and get it.
  /**
   * Photon may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Spectrum::Generic>  spectrum();

  /// Find Spectrometer element, instanciate it and get it.
  /**
   * Spectrometer may be either the root element or directly within the root
   * element.
   */
  Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>  spectrometer();

  // XML OUTPUT
  /// Write constructed XML representation to file
  void write(const char* const fname=0);

  /// Get constructed XML representation as std::string
  std::string format();

  // Setting elements
  /// 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().
   */
  void metric(SmartPointer<Metric::Generic> gg, 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().
   */
  void astrobj(SmartPointer<Astrobj::Generic> ao, 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().
   */
  void screen(SmartPointer<Screen> scr, xercesc::DOMElement *el);

  /// Set text content of XML element
  void setContent(std::string content, xercesc::DOMElement *el);

  /// Create new XML element without content
  /**
   * E.g.
   * \code
   * <OpticallyThin/>
   * \endcode
   * \param name XML entity name.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, xercesc::DOMElement *pel);

  /// Create new XML element with double value
  /**
   * E.g.
   * \code
   * <Radius> 2. </Radius>
   * \endcode
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, double value,
		    xercesc::DOMElement *pel);

  /// Create new XML element with integer value
  /**
   * E.g.
   * \code
   * <IntParameter> 7 </IntParameter>
   * \endcode
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, int value,
		    xercesc::DOMElement *pel);

  /// Create new XML element with integer value
  /**
   * E.g.
   * \code
   * <IntParameter> 7 </IntParameter>
   * \endcode
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, unsigned int value,
		    xercesc::DOMElement *pel);

  /// Create new XML element with integer value
  /**
   * E.g.
   * \code
   * <IntParameter> 7 </IntParameter>
   * \endcode
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, long value,
		    xercesc::DOMElement *pel);

  /// Create new XML element with integer value
  /**
   * E.g.
   * \code
   * <IntParameter> 7 </IntParameter>
   * \endcode
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, unsigned long value,
		    xercesc::DOMElement *pel);

  /// Create new XML element with string content
  /**
   * E.g.
   * \code
   * <StringParameter> Text </StringParameter>
   * \endcode
   *
   * Any parameter can acually be set this way if total control over
   * Text formatting is wished for.
   * \param name XML entity name.
   * \param value Entity content.
   * \param pel Parent XML element.
   */
  void setParameter(std::string name, std::string value,
		    xercesc::DOMElement*pel);

  /// Create new XML element with array content
  /**
   * E.g.
   * \code
   * <Position> 0. 10. 3.14. 0. </Position>
   * \endcode
   * \param[in] name XML entity name.
   * \param[in] val Entity content.
   * \param[in] nelem Number of elements in val to output.
   * \param[in] pel Parent XML element.
   * \param[out] child If not NULL, set to a new Gyoto::FactoryMessenger
   * pointing to the new element. It must be deleted later.
   */
  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);

  /// 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 mimick 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.
   *
   * \param relpath Path specification.
   * \return Absolute path to same file.
   */
  std::string fullPath(std::string relpath);
};

#endif
#endif