Gyoto
GyotoProperty.h
Go to the documentation of this file.
1 
6 /*
7  Copyright 2014 Thibaut Paumard
8 
9  This file is part of Gyoto.
10 
11  Gyoto is free software: you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  Gyoto is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #ifndef __GyotoProperty_H_
27 #define __GyotoProperty_H_
28 
29 #include "GyotoConfig.h"
30 #include <string>
31 #include <vector>
32 
33 namespace Gyoto {
34  class Object;
35  class Property;
36  namespace Metric { class Generic; }
37  namespace Astrobj { class Generic; }
38  namespace Spectrum { class Generic; }
39  namespace Spectrometer { class Generic; }
40  class Screen;
41  template <class T> class SmartPointer;
42 }
43 
44 
46 
50 #define GYOTO_PROPERTY_ACCESSORS(class, type, member, method) \
51  void class::method(type v) {member=v;} \
52  type class::method() const {return member;}
53 
55 
65 #define GYOTO_PROPERTY_ACCESSORS_GEOMETRICAL(class, member, method, metric) \
66  GYOTO_PROPERTY_ACCESSORS(class, double, member, method) \
67  void class::method(double v, std::string const &u) { \
68  member=Units::ToGeometrical(v, u, metric); \
69  } \
70  double class::method(std::string const &u) const { \
71  return Units::FromGeometrical(member, u, metric); \
72  }
73 
75 
78 #define GYOTO_PROPERTY_START(class) \
79  Property const class::properties[] = {
80 
82 /*
83  * Declares a static variable named "name". name and namef should not
84  * be quoted.
85  *
86  * \param[in] class name
87  * \param[in] name name of property if true;
88  * \param[in] namef name of property if false;
89  * \param[in] fname name of functions for setting or getting the property
90  * \param[in] ancestor pointer to next Property instance
91  */
92 #define GYOTO_PROPERTY_BOOL(class, name, namef, fname) \
93  Gyoto::Property \
94  (#name, \
95  #namef, \
96  (Gyoto::Property::set_bool_t)&class :: fname, \
97  (Gyoto::Property::get_bool_t)&class :: fname),
98 
100 #define GYOTO_PROPERTY_DOUBLE(class, name, fname) \
101  Gyoto::Property \
102  (#name, \
103  (Gyoto::Property::set_double_t)&class::fname, \
104  (Gyoto::Property::get_double_t)&class::fname),
105 
107 #define GYOTO_PROPERTY_LONG(class, name, fname) \
108  Gyoto::Property \
109  (#name, \
110  (Gyoto::Property::set_long_t)&class::fname, \
111  (Gyoto::Property::get_long_t)&class::fname),
112 
114 #define GYOTO_PROPERTY_UNSIGNED_LONG(class, name, fname) \
115  Gyoto::Property \
116  (#name, \
117  (Gyoto::Property::set_unsigned_long_t)&class::fname, \
118  (Gyoto::Property::get_unsigned_long_t)&class::fname),
119 
120 #if defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
121 # define GYOTO_PROPERTY_SIZE_T GYOTO_PROPERTY_UNSIGNED_LONG
122 #else
123 #define GYOTO_PROPERTY_SIZE_T(class, name, fname) \
124  Gyoto::Property \
125  (#name, \
126  (Gyoto::Property::set_size_t_t)&class::fname, \
127  (Gyoto::Property::get_size_t_t)&class::fname),
128 #endif
129 
131 #define GYOTO_PROPERTY_DOUBLE_UNIT(class, name, fname) \
132  Gyoto::Property \
133  (#name, \
134  (Gyoto::Property::set_double_t)&class::fname, \
135  (Gyoto::Property::get_double_t)&class::fname, \
136  (Gyoto::Property::set_double_unit_t)&class::fname, \
137  (Gyoto::Property::get_double_unit_t)&class::fname),
138 
140 #define GYOTO_PROPERTY_FILENAME(class, name, fname) \
141  Gyoto::Property \
142  (#name, \
143  (Gyoto::Property::set_string_t)&class::fname, \
144  (Gyoto::Property::get_string_t)&class::fname, \
145  true),
146 
148 #define GYOTO_PROPERTY_STRING(class, name, fname) \
149  Gyoto::Property \
150  (#name, \
151  (Gyoto::Property::set_string_t)&class::fname, \
152  (Gyoto::Property::get_string_t)&class::fname, \
153  false),
154 
156 #define GYOTO_PROPERTY_VECTOR_DOUBLE(class, name, fname) \
157  Gyoto::Property \
158  (#name, \
159  (Gyoto::Property::set_vector_double_t)&class::fname, \
160  (Gyoto::Property::get_vector_double_t)&class::fname),
161 
163 #define GYOTO_PROPERTY_VECTOR_DOUBLE_UNIT(class, name, fname) \
164  Gyoto::Property \
165  (#name, \
166  (Gyoto::Property::set_vector_double_t)&class::fname, \
167  (Gyoto::Property::get_vector_double_t)&class::fname, \
168  (Gyoto::Property::set_vector_double_unit_t)&class::fname, \
169  (Gyoto::Property::get_vector_double_unit_t)&class::fname),
170 
172 #define GYOTO_PROPERTY_VECTOR_UNSIGNED_LONG(class, name, fname) \
173  Gyoto::Property \
174  (#name, \
175  (Gyoto::Property::set_vector_unsigned_long_t)&class::fname, \
176  (Gyoto::Property::get_vector_unsigned_long_t)&class::fname),
177 
179 #define GYOTO_PROPERTY_METRIC(class, name, fname) \
180  Gyoto::Property \
181  (#name, \
182  (Gyoto::Property::set_metric_t)&class::fname, \
183  (Gyoto::Property::get_metric_t)&class::fname),
184 
186 #define GYOTO_PROPERTY_SCREEN(class, name, fname) \
187  Gyoto::Property \
188  (#name, \
189  (Gyoto::Property::set_screen_t)&class::fname, \
190  (Gyoto::Property::get_screen_t)&class::fname),
191 
193 #define GYOTO_PROPERTY_ASTROBJ(class, name, fname) \
194  Gyoto::Property \
195  (#name, \
196  (Gyoto::Property::set_astrobj_t)&class::fname, \
197  (Gyoto::Property::get_astrobj_t)&class::fname),
198 
200 #define GYOTO_PROPERTY_SPECTRUM(class, name, fname) \
201  Gyoto::Property \
202  (#name, \
203  (Gyoto::Property::set_spectrum_t)&class::fname, \
204  (Gyoto::Property::get_spectrum_t)&class::fname),
205 
207 #define GYOTO_PROPERTY_SPECTROMETER(class, name, fname) \
208  Gyoto::Property \
209  (#name, \
210  (Gyoto::Property::set_spectrometer_t)&class::fname, \
211  (Gyoto::Property::get_spectrometer_t)&class::fname),
212 
214 #define GYOTO_PROPERTY_END(class, next) \
215  Property(next)}; \
216  Gyoto::Property const * class::getProperties() const { \
217  return class::properties; \
218  }
219 
221 
314 {
315  private:
316 
317  public:
319 
322  enum type_e {
329 #if !defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
330  size_t_t,
332 #endif
333  bool_t,
338 
362 
371  std::string name;
373 
376  std::string name_false;
378  int type;
380  typedef void (Object::* set_double_t)(double val);
382  typedef double (Object::* get_double_t)() const;
384  typedef void (Object::* set_double_unit_t)(double val,
385  std::string const &unit);
387  typedef double (Object::* get_double_unit_t)(std::string const &unit) const;
389  typedef void (Object::* set_long_t)(long val);
391  typedef long (Object::* get_long_t)() const;
393  typedef void (Object::* set_unsigned_long_t)(unsigned long val);
395  typedef unsigned long (Object::* get_unsigned_long_t)() const;
396 #if !defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
397  typedef void (Object::* set_size_t_t)(size_t val);
400  typedef size_t (Object::* get_size_t_t)() const;
401 #endif
402  typedef void (Object::* set_bool_t)(bool val);
405  typedef bool (Object::* get_bool_t)() const;
407  typedef void (Object::* set_string_t)(std::string const&);
409  typedef std::string (Object::* get_string_t)() const;
411  typedef void (Object::* set_fname_t)(std::string const&);
413  typedef std::string (Object::* get_fname_t)() const;
415  typedef void (Object::* set_vector_double_t)(std::vector<double> const&);
417  typedef std::vector<double> (Object::* get_vector_double_t)() const;
419  typedef void (Object::* set_vector_double_unit_t)(std::vector<double> const&, std::string const &);
421  typedef std::vector<double> (Object::* get_vector_double_unit_t)(std::string const &) const;
423  typedef void (Object::* set_vector_unsigned_long_t)(std::vector<unsigned long> const&);
425  typedef std::vector<unsigned long> (Object::* get_vector_unsigned_long_t)() const;
426 
428  typedef void (Object::* set_metric_t)
432  (Object::* get_metric_t)() const;
433 
435  typedef void (Object::* set_screen_t)
439  (Object::* get_screen_t)() const;
440 
442  typedef void (Object::* set_astrobj_t)
446  (Object::* get_astrobj_t)() const;
447 
449  typedef void (Object::* set_spectrum_t)
453  (Object::* get_spectrum_t)() const;
454 
456  typedef void (Object::* set_spectrometer_t)
461 
463 
466  union setter_t {
467  set_double_t set_double;
468  set_long_t set_long;
469  set_unsigned_long_t set_unsigned_long;
470 #if !defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
471  set_size_t_t set_size_t;
472 #endif
473  set_bool_t set_bool;
474  set_string_t set_string;
475  set_vector_double_t set_vdouble;
476  set_vector_unsigned_long_t set_vulong;
477  set_metric_t set_metric;
478  set_screen_t set_screen;
479  set_astrobj_t set_astrobj;
480  set_spectrum_t set_spectrum;
481  set_spectrometer_t set_spectrometer;
482  };
484 
487  union getter_t {
488  get_double_t get_double;
489  get_long_t get_long;
490  get_unsigned_long_t get_unsigned_long;
491 #if !defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
492  get_size_t_t get_size_t;
493 #endif
494  get_bool_t get_bool;
495  get_string_t get_string;
496  get_vector_double_t get_vdouble;
497  get_vector_unsigned_long_t get_vulong;
498  get_metric_t get_metric;
499  get_screen_t get_screen;
500  get_astrobj_t get_astrobj;
501  get_spectrum_t get_spectrum;
502  get_spectrometer_t get_spectrometer;
503  };
505 
509  set_double_unit_t set_double;
510  set_vector_double_unit_t set_vdouble;
511  };
514  get_double_unit_t get_double;
515  get_vector_double_unit_t get_vdouble;
516  };
517 
519 
524 
529 
534 
538 
540  operator bool() const ;
541 
543  Property const * const parent;
544 
546  Property(Property const * const ancestor);
547 
549  Property(std::string name,
550  set_long_t set_long,
551  get_long_t get_long);
552 
554  Property(std::string name,
555  set_unsigned_long_t set_unsigned_long,
556  get_unsigned_long_t get_unsigned_long);
557 
558 #if !defined(GYOTO_SIZE__T_IS_UNSIGNED_LONG)
559  Property(std::string name,
561  set_size_t_t set_size_t,
562  get_size_t_t get_size_t);
563 #endif
564 
566  Property(std::string name,
567  set_double_t set_double,
568  get_double_t get_double);
569 
571  Property(std::string name,
572  set_double_t set_double,
573  get_double_t get_double,
574  set_double_unit_t set_double_unit,
575  get_double_unit_t get_double_unit);
576 
578  Property(std::string name,
579  std::string name_false,
580  set_bool_t set_bool,
581  get_bool_t get_bool);
582 
584 
590  Property(std::string name,
591  set_string_t set_string,
592  get_string_t get_string,
593  bool is_filename);
594 
596  Property(std::string name,
597  set_vector_double_t set_vdouble,
598  get_vector_double_t get_vdouble);
599 
601  Property(std::string name,
602  set_vector_double_t set_vdouble,
603  get_vector_double_t get_vdouble,
604  set_vector_double_unit_t set_vdouble_unit,
605  get_vector_double_unit_t get_vdouble_unit);
606 
608  Property(std::string name,
609  set_vector_unsigned_long_t set_vulong,
610  get_vector_unsigned_long_t get_vulong);
611 
613  Property(std::string name,
614  set_metric_t set_metric,
615  get_metric_t get_metric);
616 
618  Property(std::string name,
619  set_screen_t set_screen,
620  get_screen_t get_screen);
621 
623  Property(std::string name,
624  set_astrobj_t set_astrobj,
625  get_astrobj_t get_astrobj);
626 
628  Property(std::string name,
629  set_spectrum_t set_spectrum,
630  get_spectrum_t get_spectrum);
631 
633  Property(std::string name,
634  set_spectrometer_t set_spectrometer,
635  get_spectrometer_t get_spectrometer);
636 
637 };
638 
639 #endif
Union holding an accessor to set any type.
Definition: GyotoProperty.h:466
Pointers performing reference counting.
Definition: GyotoProperty.h:41
void(Object::* set_double_unit_t)(double val, std::string const &unit)
Prototype for an accessor to set a double, with unit.
Definition: GyotoProperty.h:384
Type is std::string and holds a file name.
Definition: GyotoProperty.h:346
Union holding an accessor to get any type.
Definition: GyotoProperty.h:487
Type is bool.
Definition: GyotoProperty.h:334
long(Object::* get_long_t)() const
Prototype for an accessor to get a long.
Definition: GyotoProperty.h:391
std::string name_false
Name if false.
Definition: GyotoProperty.h:376
void(Object::* set_long_t)(long val)
Prototype for an accessor to set a long.
Definition: GyotoProperty.h:389
Type is long.
Definition: GyotoProperty.h:326
#define size_t
If not defined in .
Definition: GyotoConfig.h:357
std::vector< unsigned long >(Object::* get_vector_unsigned_long_t)() const
Prototype for an accessor to get a std::vector
Definition: GyotoProperty.h:425
Type is Gyoto::SmartPointer
Definition: GyotoProperty.h:352
void(Object::* set_spectrometer_t)(Gyoto::SmartPointer< Gyoto::Spectrometer::Generic >)
Prototype for an accessor to set a Gyoto::SmartPointer ...
Definition: GyotoProperty.h:457
void(Object::* set_metric_t)(Gyoto::SmartPointer< Gyoto::Metric::Generic >)
Prototype for an accessor to set a Gyoto::SmartPointer
Definition: GyotoProperty.h:429
setter_t setter
Pointer to the setter method.
Definition: GyotoProperty.h:522
std::string name
Name of this instance.
Definition: GyotoProperty.h:371
Gyoto::SmartPointer< Gyoto::Astrobj::Generic >(Object::* get_astrobj_t)() const
Prototype for an accessor to get a Gyoto::SmartPointer
Definition: GyotoProperty.h:446
Type is std::vector
Definition: GyotoProperty.h:350
void(Object::* set_vector_double_unit_t)(std::vector< double > const &, std::string const &)
Prototype for an accessor to set a std::vector, with unit.
Definition: GyotoProperty.h:419
Gyoto::SmartPointer< Gyoto::Metric::Generic >(Object::* get_metric_t)() const
Prototype for an accessor to get a Gyoto::SmartPointer
Definition: GyotoProperty.h:432
double(Object::* get_double_t)() const
Prototype for an accessor to get a double.
Definition: GyotoProperty.h:382
unsigned long(Object::* get_unsigned_long_t)() const
Prototype for an accessor to get an unsigned long.
Definition: GyotoProperty.h:395
Type is double.
Definition: GyotoProperty.h:324
bool(Object::* get_bool_t)() const
Prototype for an accessor to get a bool.
Definition: GyotoProperty.h:405
void(Object::* set_screen_t)(Gyoto::SmartPointer< Gyoto::Screen >)
Prototype for an accessor to set a Gyoto::SmartPointer
Definition: GyotoProperty.h:436
Compile-time configuration.
type_e
Possible type of a Property instance.
Definition: GyotoProperty.h:322
Gyoto::SmartPointer< Gyoto::Spectrum::Generic >(Object::* get_spectrum_t)() const
Prototype for an accessor to get a Gyoto::SmartPointer
Definition: GyotoProperty.h:453
Property that can be set and got using standard methods.
Definition: GyotoProperty.h:313
std::vector< double >(Object::* get_vector_double_unit_t)(std::string const &) const
Prototype for an accessor to get a std::vector, with unit.
Definition: GyotoProperty.h:421
void(Object::* set_astrobj_t)(Gyoto::SmartPointer< Gyoto::Astrobj::Generic >)
Prototype for an accessor to set a Gyoto::SmartPointer
Definition: GyotoProperty.h:443
void(Object::* set_double_t)(double val)
Prototype for an accessor to set a double.
Definition: GyotoProperty.h:380
setter_unit_t setter_unit
Pointer to the setter (with unit) method.
Definition: GyotoProperty.h:532
getter_unit_t getter_unit
Pointer to the getter (with unit) method.
Definition: GyotoProperty.h:537
Type is Gyoto::SmartPointer
Definition: GyotoProperty.h:358
int type
Type of this instance.
Definition: GyotoProperty.h:378
Union holding an accessor to get double or vector with unit.
Definition: GyotoProperty.h:513
void(Object::* set_bool_t)(bool val)
Prototype for an accessor to set a bool.
Definition: GyotoProperty.h:403
std::string(Object::* get_fname_t)() const
Prototype for an accessor to get a filename.
Definition: GyotoProperty.h:413
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43
Union holding an accessor to set double or vector with unit.
Definition: GyotoProperty.h:508
Type is Gyoto::SmartPointer
Definition: GyotoProperty.h:360
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic >(Object::* get_spectrometer_t)() const
Prototype for an accessor to get a Gyoto::SmartPointer ...
Definition: GyotoProperty.h:460
void(Object::* set_vector_unsigned_long_t)(std::vector< unsigned long > const &)
Prototype for an accessor to set a std::vector
Definition: GyotoProperty.h:423
std::string(Object::* get_string_t)() const
Prototype for an accessor to get a string.
Definition: GyotoProperty.h:409
Property(Property const *const ancestor)
Constructor for type==empty_t.
Type is std::vector
Definition: GyotoProperty.h:348
Type is Gyoto::SmartPointer
Definition: GyotoProperty.h:356
void(Object::* set_vector_double_t)(std::vector< double > const &)
Prototype for an accessor to set a std::vector
Definition: GyotoProperty.h:415
double(Object::* get_double_unit_t)(std::string const &unit) const
Prototype for an accessor to get a double, with unit.
Definition: GyotoProperty.h:387
Gyoto::SmartPointer< Gyoto::Screen >(Object::* get_screen_t)() const
Prototype for an accessor to get a Gyoto::SmartPointer
Definition: GyotoProperty.h:439
void(Object::* set_string_t)(std::string const &)
Prototype for an accessor to set a string.
Definition: GyotoProperty.h:407
Type is std::string.
Definition: GyotoProperty.h:336
Object with properties.
Definition: GyotoObject.h:136
std::vector< double >(Object::* get_vector_double_t)() const
Prototype for an accessor to get a std::vector
Definition: GyotoProperty.h:417
Type is Gyoto::SmartPointer
Definition: GyotoProperty.h:354
void(Object::* set_spectrum_t)(Gyoto::SmartPointer< Gyoto::Spectrum::Generic >)
Prototype for an accessor to set a Gyoto::SmartPointer
Definition: GyotoProperty.h:450
getter_t getter
Pointer to the getter method.
Definition: GyotoProperty.h:527
Type is unsigned long (a.k.a. size_t)
Definition: GyotoProperty.h:328
void(Object::* set_fname_t)(std::string const &)
Prototype for an accessor to set a filename.
Definition: GyotoProperty.h:411
Property is empty.
Definition: GyotoProperty.h:369
void(Object::* set_unsigned_long_t)(unsigned long val)
Prototype for an accessor to set an unsigned long.
Definition: GyotoProperty.h:393
Property const *const parent
If type is empty_t, link to another Property list.
Definition: GyotoProperty.h:543