Gyoto::Property Class Reference

Property that can be set and got using standard methods. More...

`#include <GyotoProperty.h>`

## Classes

union | setter_t
| Union holding an accessor to set any type. More...
union | getter_t
| Union holding an accessor to get any type. More...
union | setter_unit_t
| Union holding an accessor to set double or vector<double> with unit. More...
union | getter_unit_t
| Union holding an accessor to get double or vector<double> with unit. More...

## Public Types

enum | type_e { double_t , long_t , unsigned_long_t , size_t_t , bool_t , string_t , filename_t , vector_double_t , vector_unsigned_long_t , metric_t , screen_t , astrobj_t , spectrum_t , spectrometer_t , empty_t }
| Possible type of a Property instance. More...
typedef void(Object::* | set_double_t) (double val)
| Prototype for an accessor to set a double.
typedef double(Object::* | get_double_t) () const
| Prototype for an accessor to get a double.
typedef void(Object::* | set_double_unit_t) (double val, std::string const &unit)
| Prototype for an accessor to set a double, with unit.
typedef double(Object::* | get_double_unit_t) (std::string const &unit) const
| Prototype for an accessor to get a double, with unit.
typedef void(Object::* | set_long_t) (long val)
| Prototype for an accessor to set a long.
typedef long(Object::* | get_long_t) () const
| Prototype for an accessor to get a long.
typedef void(Object::* | set_unsigned_long_t) (unsigned long val)
| Prototype for an accessor to set an unsigned long.
typedef unsigned long(Object::* | get_unsigned_long_t) () const
| Prototype for an accessor to get an unsigned long.
typedef void(Object::* | set_size_t_t) (size_t val)
| Prototype for an accessor to set a size_t.
typedef size_t(Object::* | get_size_t_t) () const
| Prototype for an accessor to get a size_t.
typedef void(Object::* | set_bool_t) (bool val)
| Prototype for an accessor to set a bool.
typedef bool(Object::* | get_bool_t) () const
| Prototype for an accessor to get a bool.
typedef void(Object::* | set_string_t) (std::string const &)
| Prototype for an accessor to set a string.
typedef std::string(Object::* | get_string_t) () const
| Prototype for an accessor to get a string.
typedef void(Object::* | set_fname_t) (std::string const &)
| Prototype for an accessor to set a filename.
typedef std::string(Object::* | get_fname_t) () const
| Prototype for an accessor to get a filename.
typedef void(Object::* | set_vector_double_t) (std::vector< double > const &)
| Prototype for an accessor to set a std::vector<double>.
typedef std::vector< double >(Object::* | get_vector_double_t) () const
| Prototype for an accessor to get a std::vector<double>.
typedef void(Object::* | set_vector_double_unit_t) (std::vector< double > const &, std::string const &)
| Prototype for an accessor to set a std::vector<double>, with unit.
typedef std::vector< double >(Object::* | get_vector_double_unit_t) (std::string const &) const
| Prototype for an accessor to get a std::vector<double>, with unit.
typedef void(Object::* | set_vector_unsigned_long_t) (std::vector< unsigned long > const &)
| Prototype for an accessor to set a std::vector<unsigned long>.
typedef std::vector< unsigned long >(Object::* | get_vector_unsigned_long_t) () const
| Prototype for an accessor to get a std::vector<unsigned long>.
typedef void(Object::* | set_metric_t) (Gyoto::SmartPointer< Gyoto::Metric::Generic >)
| Prototype for an accessor to set a Gyoto::SmartPointer<Gyoto::Metric::Generic>.
typedef Gyoto::SmartPointer< Gyoto::Metric::Generic >(Object::* | get_metric_t) () const
| Prototype for an accessor to get a Gyoto::SmartPointer<Gyoto::Metric::Generic>.
typedef void(Object::* | set_screen_t) (Gyoto::SmartPointer< Gyoto::Screen >)
| Prototype for an accessor to set a Gyoto::SmartPointer<Gyoto::Screen>.
typedef Gyoto::SmartPointer< Gyoto::Screen >(Object::* | get_screen_t) () const
| Prototype for an accessor to get a Gyoto::SmartPointer<Gyoto::Screen>.
typedef void(Object::* | set_astrobj_t) (Gyoto::SmartPointer< Gyoto::Astrobj::Generic >)
| Prototype for an accessor to set a Gyoto::SmartPointer<Gyoto::Astrobj::Generic>.
typedef Gyoto::SmartPointer< Gyoto::Astrobj::Generic >(Object::* | get_astrobj_t) () const
| Prototype for an accessor to get a Gyoto::SmartPointer<Gyoto::Astrobj::Generic>.
typedef void(Object::* | set_spectrum_t) (Gyoto::SmartPointer< Gyoto::Spectrum::Generic >)
| Prototype for an accessor to set a Gyoto::SmartPointer<Gyoto::Spectrum::Generic>.
typedef Gyoto::SmartPointer< Gyoto::Spectrum::Generic >(Object::* | get_spectrum_t) () const
| Prototype for an accessor to get a Gyoto::SmartPointer<Gyoto::Spectrum::Generic>.
typedef void(Object::* | set_spectrometer_t) (Gyoto::SmartPointer< Gyoto::Spectrometer::Generic >)
| Prototype for an accessor to set a Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>.
typedef Gyoto::SmartPointer< Gyoto::Spectrometer::Generic >(Object::* | get_spectrometer_t) () const
| Prototype for an accessor to get a Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>.

## Public Member Functions

| operator bool () const
| True if Gyoto::Property::type is not Gyoto::Property::empty_t.
| Property ()
| Default constructor.
| Property (Property const *const ancestor)
| Constructor for type==empty_t.
| Property (std::string classname, std::string doc="")
| Constructor for class name pseudo-property.
| Property (std::string name, set_long_t set_long, get_long_t get_long, std::string doc)
| Constructor for type==long_t.
| Property (std::string name, set_unsigned_long_t set_unsigned_long, get_unsigned_long_t get_unsigned_long, std::string doc)
| Constructor for type==unsigned_long_t.
| Property (std::string name, set_size_t_t set_size_t, get_size_t_t get_size_t, int dummy, std::string doc)
| Constructor for type==size_t_t.
| Property (std::string name, set_double_t set_double, get_double_t get_double, std::string doc)
| Constructor for type==double_t, without unit support.
| Property (std::string name, set_double_t set_double, get_double_t get_double, set_double_unit_t set_double_unit, get_double_unit_t get_double_unit, std::string doc)
| Constructor for type==double_t, with unit support.
| Property (std::string name, std::string name_false, set_bool_t set_bool, get_bool_t get_bool, std::string doc)
| Constructor for type==bool_t.
| Property (std::string name, set_string_t set_string, get_string_t get_string, bool is_filename, std::string doc)
| Constructor for type==string_t or filename_t.
| Property (std::string name, set_vector_double_t set_vdouble, get_vector_double_t get_vdouble, std::string doc)
| Constructor for type==vector_double_t, without unit support.
| Property (std::string name, set_vector_double_t set_vdouble, get_vector_double_t get_vdouble, set_vector_double_unit_t set_vdouble_unit, get_vector_double_unit_t get_vdouble_unit, std::string doc)
| Constructor for type==vector_double_t, with unit support.
| Property (std::string name, set_vector_unsigned_long_t set_vulong, get_vector_unsigned_long_t get_vulong, std::string doc)
| Constructor for type==vector_unsigned_long_t.
| Property (std::string name, set_metric_t set_metric, get_metric_t get_metric, std::string doc)
| Constructor for type==metric_t.
| Property (std::string name, set_screen_t set_screen, get_screen_t get_screen, std::string doc)
| Constructor for type==screen_t.
| Property (std::string name, set_astrobj_t set_astrobj, get_astrobj_t get_astrobj, std::string doc)
| Constructor for type==astrobj_t.
| Property (std::string name, set_spectrum_t set_spectrum, get_spectrum_t get_spectrum, std::string doc)
| Constructor for type==spectrum_t.
| Property (std::string name, set_spectrometer_t set_spectrometer, get_spectrometer_t get_spectrometer, std::string doc)
| Constructor for type==spectrometer_t.
| Property (std::string name, int type)
| Constructor setting only name and type.

## Static Public Member Functions

static type_e | typeFromString (std::string stype)
| Get Property::type_e value from name.

## Public Attributes

std::string | name
| Name of this instance.
std::string | name_false
| Name if false.
int | type
| Type of this instance.
setter_t | setter
| Pointer to the setter method.
getter_t | getter
| Pointer to the getter method.
setter_unit_t | setter_unit
| Pointer to the setter (with unit) method.
getter_unit_t | getter_unit
| Pointer to the getter (with unit) method.
std::string | doc
Property const *const | parent
| If type is empty_t, link to another Property list.

## Detailed Description

Property that can be set and got using standard methods.

The Property API makes it easy to declare the parameters that can be set in a class.

Developpers who simply write classes (deriving from Astrobj::Generic, , Metric::Generic, Spectrum::Generic) need not know the inners of the Property class and interact with it only using macros to declare the parameters they need to read from XML.

To make use of the Property framework, a class must derive from Gyoto::Object and use the GYOTO_OBJECT in a public section of the class declaration (i.e. in the .h file). Then, in the corresponding .C file, the GYOTO_PROPERTY_* macros are used as follows (note the absence of punctuation after the macros):

GYOTO_PROPERTY_START(MyClass)
GYOTO_PROPERTY_<type>(MyClass, PropertyName, accessor)
...
GYOTO_PROPERTY_END(MyClass, ParentClass::properties)
GYOTO_PROPERTY_START
#define GYOTO_PROPERTY_START(...)
Start Property list.
Definition GyotoProperty.h:141

In the above, GYOTO_PROPERTY_START starts the definition of the static member MyClass::properties. Each GYOTO_PROPERTY_<type> macro declares a new property. GYOTO_PROPERTY_END ends the definition of the property list, with an optional pointer to the parent's class Property list, and defines the MyClass::getProperties() method.

The underlying accessors must always be defined, both to set and to get the property. For the sake of simplicity, only a limited number of data types are allowed:

- double: see GYOTO_PROPERTY_DOUBLE, GYOTO_PROPERTY_DOUBLE_UNIT;
- long: see GYOTO_PROPERTY_LONG;
- unsigned long: see GYOTO_PROPERTY_UNSIGNED_LONG (a.k.a. size_t: see GYOTO_PROPERTY_SIZE_T, this may break on architectures where size_t is not the same as unsigned long);
- bool: see GYOTO_PROPERTY_BOOL;
- std::vector<double>: see GYOTO_PROPERTY_VECTOR_DOUBLE and GYOTO_PROPERTY_VECTOR_DOUBLE_UNIT;
- std::vector<unsigned long>: see GYOTO_PROPERTY_VECTOR_UNSIGNED_LONG;
- Gyoto::SmartPointers to various base classes: Screen, Metric::Generic, Astrobj::Generic, Spectrum::Generic and Spectrometer::Generic. See GYOTO_PROPERTY_METRIC, GYOTO_PROPERTY_SCREEN, GYOTO_PROPERTY_ASTROBJ, GYOTO_PROPERTY_SPECTRUM and GYOTO_PROPERTY_SPECTROMETER.

For the floating point data-types (double and vector<double>), two additional accessors supporting units can be provided. The accessors must have the same name and have specific prototypes, see the various function pointer typedefs, e.g. set_double_t and get_double_t.

The type used in these accessors may not be the same as the type of the underlying class member. For instance, to read an array, it was chosen to use the std::vector<type> type because it is easy to read such a vector from XML and to thus determine dynamically the number of elements provided. But this type is slow, so it is expected that the class member will rather be a C-style array (double arr[]) or something else entirely. It is not forbidden to have a set of high-level accessors for the Property interface on top of lower-level, more efficient accessors to be used in compiled, static code:

void MyClass::arrayMember(double const * const tab) {
for (int i=0; i<5; ++i) member_[i]=tab[i];
}
void MyClass::arrayMemberVector(std::vector<double> const &vect) {
if (vect.size()!=5) throwError("Please provide 5 elements");
for (int i=0; i<5; ++i) member_[i]=vect[i];
}
double const * MyClass::arrayMember() const {return member_;}
std::vector<double> MyClass::arrayMemberVector() const {
std::vector<double> v(5, 0.);
for (int i=0; i<5; ++i) v[i]=member_[i];
return v;
}
Gyoto::throwError
void throwError(std::string)
Throw a Gyoto::Error.

In this example, assuming MyClass is based directly on Object and member_ is the only parameter to read from XML, the Property list may be defined as:

GYOTO_PROPERTY_START(MyClass)
GYOTO_PROPERTY_VECTOR_DOUBLE(MyClass, ArrayMember, arrayMemberVector)
GYOTO_PROPERTY_END(MyClass, Object::properties)
GYOTO_PROPERTY_END
#define GYOTO_PROPERTY_END(class, next)
Define class::properties and class::getProperties().
Definition GyotoProperty.h:496
GYOTO_PROPERTY_VECTOR_DOUBLE
#define GYOTO_PROPERTY_VECTOR_DOUBLE(...)
Define a Property of type vector<double>.
Definition GyotoProperty.h:228
Gyoto::Object::properties
static GYOTO_OBJECT Property const properties[]
Property list.
Definition GyotoObject.h:200

Again, nothing more is required to read and write ArrayMember from XML and from Yorick.

## Member Enumeration Documentation

## type_e

enum Gyoto::Property::type_e

Possible type of a Property instance.

These are all the values that Property::type may take.

Enumerator
double_t | Type is double.
long_t | Type is long.
unsigned_long_t | Type is unsigned long (a.k.a. size_t).
size_t_t | Type is size_t (only if distinct from unsigned long).
bool_t | Type is bool.
string_t | Type is std::string.
filename_t | Type is std::string and holds a file name. In this case, the value may be changed to include relative or absolute path. The prefix "`pwd`/" forces path to be interpreted relative to the current working directory. If the value starts with "/", it is interpreted as an absolute path. Otherwise, when reading from XML, the path is interpreted relative to the XML file.
vector_double_t | Type is std::vector<double>.
vector_unsigned_long_t | Type is std::vector<unsigned long>.
metric_t | Type is Gyoto::SmartPointer<Gyoto::Metric::Generic>.
screen_t | Type is Gyoto::SmartPointer<Gyoto::Screen::Generic>.
astrobj_t | Type is Gyoto::SmartPointer<Gyoto::Astrobj::Generic>.
spectrum_t | Type is Gyoto::SmartPointer<Gyoto::Spectrum::Generic>.
spectrometer_t | Type is Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>.

empty_t

Property is empty.

In this case (and only in this case):

1. Gyoto::Property::operator bool() const return false;
2. Property::parent may be different from NULL and point to another array of Property instances, that should be interpreted as appended to this list.

## Constructor & Destructor Documentation

## Property() [1/3]

Gyoto::Property::Property | ( | std::string | name,
|  | set_size_t_t | set_size_t,
|  | get_size_t_t | get_size_t,
|  | int | dummy,
|  | std::string | doc )

Constructor for type==size_t_t.

The dummy int parameter is only there to differenciate from the unsigned long constructor on platforms where size_t is a typdef to unsigned long.

## Property() [2/3]

Gyoto::Property::Property | ( | std::string | name,
|  | set_string_t | set_string,
|  | get_string_t | get_string,
|  | bool | is_filename,
|  | std::string | doc )

Constructor for type==string_t or filename_t.

Parameters

  name | name of the Property
  set_string | pointer to the setter accessor
  get_string | pointer to the getter accessor
  is_filename | true means type=filename_t

## Property() [3/3]

Gyoto::Property::Property | ( | std::string | name,
|  | int | type )

Constructor setting only name and type.

Used in the Python plug-in to provide peudo-properties

## Member Data Documentation

## getter

getter_t Gyoto::Property::getter

Pointer to the getter method.

Right type is stored in type

## getter_unit

getter_unit_t Gyoto::Property::getter_unit

Pointer to the getter (with unit) method.

Right type is stored in type

## name_false

std::string Gyoto::Property::name_false

Name if false.

Only if type is empty_t

## setter

setter_t Gyoto::Property::setter

Pointer to the setter method.

Right type is stored in type

## setter_unit

setter_unit_t Gyoto::Property::setter_unit

Pointer to the setter (with unit) method.

Right type is stored in type

The documentation for this class was generated from the following file:

- GyotoProperty.h