[Debian-astro-commits] [gyoto] 123/221: Change Object/Property API to use arrays (with "links") rather than chained lists. Much easier to understand and to read.
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:39 UTC 2015
This is an automated email from the git hooks/post-receive script.
thibaut pushed a commit to branch master
in repository gyoto.
commit 020d8486c265ef169bee8d0ddaf836d22a367141
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Tue Dec 2 12:20:16 2014 +0100
Change Object/Property API to use arrays (with "links") rather than chained lists. Much easier to understand and to read.
---
include/GyotoObject.h | 2 +-
include/GyotoPhoton.h | 1 -
include/GyotoProperty.h | 184 ++++++++++++++++++--------------------------
include/GyotoWorldline.h | 74 ++++++++++++++----
lib/Astrobj.C | 16 ++--
lib/FixedStar.C | 9 +--
lib/KerrBL.C | 12 +--
lib/KerrKS.C | 11 +--
lib/Metric.C | 16 ++--
lib/Minkowski.C | 22 ++++--
lib/NumericalMetricLorene.C | 30 ++++----
lib/Object.C | 34 +++++---
lib/Photon.C | 23 +-----
lib/Property.C | 60 ++++++---------
lib/RotStar3_1.C | 7 +-
lib/StandardAstrobj.C | 6 +-
lib/Star.C | 10 +--
lib/Torus.C | 15 ++--
lib/UniformSphere.C | 25 +++---
19 files changed, 267 insertions(+), 290 deletions(-)
diff --git a/include/GyotoObject.h b/include/GyotoObject.h
index 02a471e..fec7ff9 100644
--- a/include/GyotoObject.h
+++ b/include/GyotoObject.h
@@ -39,7 +39,7 @@ namespace Gyoto {
/// Declare class::properties and class::getProperties()
#define GYOTO_OBJECT \
- static Property const * const properties; \
+ static Property const properties[]; \
virtual Property const * getProperties() const
/**
diff --git a/include/GyotoPhoton.h b/include/GyotoPhoton.h
index e0c18c5..058a23d 100644
--- a/include/GyotoPhoton.h
+++ b/include/GyotoPhoton.h
@@ -229,7 +229,6 @@ class Gyoto::Photon
#ifdef GYOTO_USE_XERCES
virtual void setParameters(FactoryMessenger *fmp) ;
- virtual void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const ;
virtual void fillElement(Gyoto::FactoryMessenger *fmp) const ;
static SmartPointer<Photon> Subcontractor(Gyoto::FactoryMessenger*);
#endif
diff --git a/include/GyotoProperty.h b/include/GyotoProperty.h
index c382d27..ee12d7d 100644
--- a/include/GyotoProperty.h
+++ b/include/GyotoProperty.h
@@ -38,20 +38,8 @@ namespace Gyoto {
template <class T> class SmartPointer;
}
-/// Make an NULL-terminated array of ancestors
-/**
- * Called automatically in GYOTO_PROPERTY_*
- */
-#define GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor) \
- Property const * const name##_ancestors[] = {ancestor, NULL}
-
-#define GYOTO_PROPERTY_MAKE_ANCESTORS2(name, ancestor1, ancestor2) \
- Property const * const name##_ancestors[] = {ancestor1, ancestor2, NULL}
-
-#define GYOTO_PROPERTY_EMPTY2(class, name, ancestor1, ancestor2) \
- GYOTO_PROPERTY_MAKE_ANCESTORS2(name, ancestor1, ancestor2); \
- Property const name \
- (name##_ancestors)
+#define GYOTO_PROPERTY_START(class) \
+ Property const class::properties[] = {
/// Define a new Property of type Bool
/*
@@ -64,106 +52,88 @@ namespace Gyoto {
* \param[in] fname name of functions for setting or getting the property
* \param[in] ancestor pointer to next Property instance
*/
-#define GYOTO_PROPERTY_BOOL(class, name, namef, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
+#define GYOTO_PROPERTY_BOOL(class, name, namef, fname) \
+ Gyoto::Property \
+ (#name, \
#namef, \
(Gyoto::Property::set_bool_t)&class :: fname, \
- (Gyoto::Property::get_bool_t)&class :: fname, \
- name##_ancestors)
+ (Gyoto::Property::get_bool_t)&class :: fname),
/// Define a Property of type Double
-#define GYOTO_PROPERTY_DOUBLE(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_double_t)&class::fname, \
- (Gyoto::Property::get_double_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_DOUBLE(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_double_t)&class::fname, \
+ (Gyoto::Property::get_double_t)&class::fname),
/// Define a Property of type Long
-#define GYOTO_PROPERTY_LONG(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_long_t)&class::fname, \
- (Gyoto::Property::get_long_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_LONG(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_long_t)&class::fname, \
+ (Gyoto::Property::get_long_t)&class::fname),
/// Define a Property of type Long
-#define GYOTO_PROPERTY_UNSIGNED_LONG(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_unsigned_long_t)&class::fname, \
- (Gyoto::Property::get_unsigned_long_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_UNSIGNED_LONG(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_unsigned_long_t)&class::fname, \
+ (Gyoto::Property::get_unsigned_long_t)&class::fname),
#define GYOTO_PROPERTY_SIZE_T GYOTO_PROPERTY_UNSIGNED_LONG
/// Define a Property of type Double supporting unit
-#define GYOTO_PROPERTY_DOUBLE_UNIT(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_double_t)&class::fname, \
- (Gyoto::Property::get_double_t)&class::fname, \
- (Gyoto::Property::set_double_unit_t)&class::fname, \
- (Gyoto::Property::get_double_unit_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_DOUBLE_UNIT(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_double_t)&class::fname, \
+ (Gyoto::Property::get_double_t)&class::fname, \
+ (Gyoto::Property::set_double_unit_t)&class::fname, \
+ (Gyoto::Property::get_double_unit_t)&class::fname),
/// Define a Property of type Filename
-#define GYOTO_PROPERTY_FILENAME(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_string_t)&class::fname, \
- (Gyoto::Property::get_string_t)&class::fname, \
- name##_ancestors, true)
+#define GYOTO_PROPERTY_FILENAME(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_string_t)&class::fname, \
+ (Gyoto::Property::get_string_t)&class::fname, \
+ true),
/// Define a Property of type String
-#define GYOTO_PROPERTY_STRING(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_string_t)&class::fname, \
- (Gyoto::Property::get_string_t)&class::fname, \
- name##_ancestors, false)
+#define GYOTO_PROPERTY_STRING(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_string_t)&class::fname, \
+ (Gyoto::Property::get_string_t)&class::fname, \
+ false),
/// Define a Property of type vector<double>
-#define GYOTO_PROPERTY_VECTOR_DOUBLE(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_vector_double_t)&class::fname, \
- (Gyoto::Property::get_vector_double_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_VECTOR_DOUBLE(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_vector_double_t)&class::fname, \
+ (Gyoto::Property::get_vector_double_t)&class::fname),
/// Define a Property of type Gyoto::Metric::Generic
-#define GYOTO_PROPERTY_METRIC(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_metric_t)&class::fname, \
- (Gyoto::Property::get_metric_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_METRIC(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_metric_t)&class::fname, \
+ (Gyoto::Property::get_metric_t)&class::fname),
/// Define a Property of type Gyoto::Spectrum::Generic
-#define GYOTO_PROPERTY_SPECTRUM(class, name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Gyoto::Property::set_spectrum_t)&class::fname, \
- (Gyoto::Property::get_spectrum_t)&class::fname, \
- name##_ancestors)
+#define GYOTO_PROPERTY_SPECTRUM(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_spectrum_t)&class::fname, \
+ (Gyoto::Property::get_spectrum_t)&class::fname),
/// Define class::properties and class::getProperties()
-#define GYOTO_PROPERTY_FINALIZE(class, ancestor) \
- Property const * const class::properties = ancestor; \
- Property const * class::getProperties() const { \
- return class::properties; \
- }
+#define GYOTO_PROPERTY_END(class, next) \
+ Property(next)}; \
+ Gyoto::Property const * class::getProperties() const { \
+ return class::properties; \
+ }
/**
* \brief Property
@@ -233,58 +203,52 @@ class Gyoto::Property
getter_t getter;
setter_unit_t setter_unit;
getter_unit_t getter_unit;
- Property const * const * const parents;
+
+ operator bool() const ;
+
+ Property const * const parent;
- Property(Property const * const * ancestors);
+ Property(Property const * const ancestor);
Property(std::string name,
set_long_t set_long,
- get_long_t get_long,
- Property const * const * ancestors);
+ get_long_t get_long);
Property(std::string name,
set_unsigned_long_t set_unsigned_long,
- get_unsigned_long_t get_unsigned_long,
- Property const * const * ancestors);
+ get_unsigned_long_t get_unsigned_long);
Property(std::string name,
set_double_t set_double,
- get_double_t get_double,
- Property const * const * ancestors);
+ get_double_t get_double);
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,
- Property const * const * ancestors);
+ get_double_unit_t get_double_unit);
Property(std::string name,
std::string name_false,
set_bool_t set_bool,
- get_bool_t get_bool,
- Property const * const * ancestors);
+ get_bool_t get_bool);
Property(std::string name,
set_string_t set_string,
get_string_t get_string,
- Property const * const * ancestors,
- bool is_filename=false);
+ bool is_filename);
Property(std::string name,
set_vector_double_t set_vdouble,
- get_vector_double_t get_vdouble,
- Property const * const * ancestors);
+ get_vector_double_t get_vdouble);
Property(std::string name,
set_metric_t set_metric,
- get_metric_t get_metric,
- Property const * const * ancestors);
+ get_metric_t get_metric);
Property(std::string name,
set_spectrum_t set_spectrum,
- get_spectrum_t get_spectrum,
- Property const * const * ancestors);
+ get_spectrum_t get_spectrum);
Property const * find(std::string name) const;
diff --git a/include/GyotoWorldline.h b/include/GyotoWorldline.h
index b9b945e..c41141a 100644
--- a/include/GyotoWorldline.h
+++ b/include/GyotoWorldline.h
@@ -47,19 +47,43 @@ namespace Gyoto {
#include <GyotoScreen.h>
#include <GyotoHooks.h>
-#define GYOTO_WORLDLINE_PROPERTIES(c, a) \
- GYOTO_PROPERTY_BOOL(c, HighOrderImages, PrimaryOnly, _secondary, a); \
- GYOTO_PROPERTY_DOUBLE(c, RelTol, _relTol, &HighOrderImages); \
- GYOTO_PROPERTY_DOUBLE(c, AbsTol, _absTol, &RelTol); \
- GYOTO_PROPERTY_DOUBLE(c, DeltaMaxOverR, _deltaMaxOverR, &AbsTol); \
- GYOTO_PROPERTY_DOUBLE(c, DeltaMax, _deltaMax, &DeltaMaxOverR); \
- GYOTO_PROPERTY_DOUBLE(c, DeltaMin, _deltaMin, &DeltaMax); \
- GYOTO_PROPERTY_STRING(c, Integrator, _integrator, &DeltaMin); \
- GYOTO_PROPERTY_SIZE_T(c, MaxIter, _maxiter, &Integrator); \
- GYOTO_PROPERTY_BOOL(c, Adaptive, NonAdaptive, _adaptive, &MaxIter); \
- GYOTO_PROPERTY_DOUBLE_UNIT(c, Delta, _delta, &Adaptive); \
- GYOTO_PROPERTY_VECTOR_DOUBLE(c, InitCoord, _initCoord, &Delta); \
- GYOTO_PROPERTY_METRIC(c, Metric, _metric, &InitCoord); \
+/// Define the bunch of Properties that make up the Worldline interface
+/**
+ * This macro, which is called automatically by
+ * GYOTO_WORLDLINE_PROPERTY_END(c, a), must be inserted in the
+ * definition of the Property list for any class derived from
+ * Worldline.
+ */
+#define GYOTO_WORLDLINE_PROPERTIES(c) \
+ GYOTO_PROPERTY_BOOL(c, HighOrderImages, PrimaryOnly, _secondary) \
+ GYOTO_PROPERTY_DOUBLE(c, RelTol, _relTol) \
+ GYOTO_PROPERTY_DOUBLE(c, AbsTol, _absTol) \
+ GYOTO_PROPERTY_DOUBLE(c, DeltaMaxOverR, _deltaMaxOverR) \
+ GYOTO_PROPERTY_DOUBLE(c, DeltaMax, _deltaMax) \
+ GYOTO_PROPERTY_DOUBLE(c, DeltaMin, _deltaMin) \
+ GYOTO_PROPERTY_STRING(c, Integrator, _integrator) \
+ GYOTO_PROPERTY_SIZE_T(c, MaxIter, _maxiter) \
+ GYOTO_PROPERTY_BOOL(c, Adaptive, NonAdaptive, _adaptive) \
+ GYOTO_PROPERTY_DOUBLE_UNIT(c, Delta, _delta) \
+ GYOTO_PROPERTY_VECTOR_DOUBLE(c, InitCoord, _initCoord) \
+ GYOTO_PROPERTY_METRIC(c, Metric, _metric)
+
+/// Define the wrapper accessors used in GYOTO_WORLDLINE_PROPERTIES(class)
+/**
+ This macro, which is called automatically by
+ GYOTO_WORLDLINE_PROPERTY_END(c, a), must be called once with the
+ definition of the methods (.C file) of any class that derives from
+ Worldline. The corresponding macro GYOTO_WORLDLINE must be called
+ in the corresponding class declaration (.h file).
+
+ This is made necessary by how multiple inheritence works: directly
+ using the accessors in the Worldline API leads to segfault at
+ runtime (unless too much extra care is taken) and may go unnoticed.
+
+ These accessors must be declared in the class declaration using the
+ GYOTO_WORLDLINE macro.
+*/
+#define GYOTO_WORLDLINE_ACCESSORS(c) \
void c::_secondary(bool s) {secondary(s);} \
bool c::_secondary() const {return secondary();} \
void c::_adaptive(bool s) {adaptive(s);} \
@@ -70,8 +94,8 @@ namespace Gyoto {
double c::_absTol()const{return absTol();} \
void c::_deltaMin(double f){deltaMin(f);} \
double c::_deltaMin()const{return deltaMin();} \
- void c::_deltaMax(double f){deltaMax(f);} \
- double c::_deltaMax()const{return deltaMax();} \
+ void c::_deltaMax(double f){deltaMax(f);} \
+ double c::_deltaMax()const{return deltaMax();} \
void c::_deltaMaxOverR(double f){deltaMaxOverR(f);} \
double c::_deltaMaxOverR()const{return deltaMaxOverR();} \
void c::_delta(double f){delta(f);} \
@@ -87,8 +111,26 @@ namespace Gyoto {
void c::_metric(SmartPointer<Metric::Generic>f){metric(f);} \
SmartPointer<Metric::Generic> c::_metric() const{return metric();}
-#define GYOTO_WORLDLINE_FIRST_PROPERTY ::Metric
+/// Drop-in replacement for GYOTO_PROPERTY_END(), which adds the Worldline interface
+/**
+ * This macro replaces GYOTO_PROPERTY_END(c, a) for classes that
+ * derive from Worldline. It calls GYOTO_WORLDLINE_PROPERTIES(a) and
+ * GYOTO_WORLDLINE_ACCESSORS(c). If this macro is used,
+ * GYOTO_WORLDLINE must be called in the class declaration (.h file).
+ */
+#define GYOTO_WORLDLINE_PROPERTY_END(c, a) \
+ GYOTO_WORLDLINE_PROPERTIES(c) \
+ GYOTO_PROPERTY_END(c, a) \
+ GYOTO_WORLDLINE_ACCESSORS(c)
+/// Declare the Worldline interface wrappers
+/**
+ This macro must be called in the class declaration (.h file), in a
+ public section. Its sibling GYOTO_WORLDLINE_ACCESSORS(c) must be
+ called with the class method definition (.C file). Note that
+ GYOTO_WORLDLINE_PROPERTY_END(c, a) calls
+ GYOTO_WORLDLINE_ACCESSORS(c).
+*/
#define GYOTO_WORLDLINE \
void _delta(const double delta); \
void _delta(double, const std::string &unit); \
diff --git a/lib/Astrobj.C b/lib/Astrobj.C
index ed614a6..5ca732a 100644
--- a/lib/Astrobj.C
+++ b/lib/Astrobj.C
@@ -42,15 +42,13 @@ using namespace Gyoto::Astrobj;
Register::Entry* Gyoto::Astrobj::Register_ = NULL;
-GYOTO_PROPERTY_BOOL(Generic, OpticallyThin, OpticallyThick,
- opticallyThin, Object::properties);
-GYOTO_PROPERTY_BOOL(Generic, RadiativeQ, NoRadiativeQ,
- radiativeQ, &OpticallyThin);
-GYOTO_PROPERTY_BOOL(Generic, Redshift, NoRedshift,
- redshift, &RadiativeQ);
-GYOTO_PROPERTY_DOUBLE_UNIT(Generic, RMax, rMax, &Redshift);
-GYOTO_PROPERTY_METRIC(Generic, Metric, metric, &RMax);
-GYOTO_PROPERTY_FINALIZE(Generic, &::Metric);
+GYOTO_PROPERTY_START(Generic)
+GYOTO_PROPERTY_METRIC(Generic, Metric, metric)
+GYOTO_PROPERTY_DOUBLE_UNIT(Generic, RMax, rMax)
+GYOTO_PROPERTY_BOOL(Generic, Redshift, NoRedshift, redshift)
+GYOTO_PROPERTY_BOOL(Generic, RadiativeQ, NoRadiativeQ, radiativeQ)
+GYOTO_PROPERTY_BOOL(Generic, OpticallyThin, OpticallyThick, opticallyThin)
+GYOTO_PROPERTY_END(Generic, Object::properties)
Generic::Generic(string kin) :
SmartPointee(), Object(kin),
diff --git a/lib/FixedStar.C b/lib/FixedStar.C
index 7464ed8..a4c3829 100644
--- a/lib/FixedStar.C
+++ b/lib/FixedStar.C
@@ -38,11 +38,10 @@ using namespace std;
using namespace Gyoto;
using namespace Gyoto::Astrobj;
-GYOTO_PROPERTY_BOOL(FixedStar,
- Rotating, NonRotating, rotating,
- UniformSphere::properties);
-GYOTO_PROPERTY_VECTOR_DOUBLE(FixedStar, Position, position, &Rotating);
-GYOTO_PROPERTY_FINALIZE(FixedStar, &Position);
+GYOTO_PROPERTY_START(FixedStar)
+GYOTO_PROPERTY_VECTOR_DOUBLE(FixedStar, Position, position)
+GYOTO_PROPERTY_BOOL(FixedStar, Rotating, NonRotating, rotating)
+GYOTO_PROPERTY_END(FixedStar, UniformSphere::properties)
FixedStar::FixedStar() : UniformSphere("FixedStar"), rotating_(false)
{
diff --git a/lib/KerrBL.C b/lib/KerrBL.C
index 509805b..27f77fa 100644
--- a/lib/KerrBL.C
+++ b/lib/KerrBL.C
@@ -36,13 +36,13 @@ using namespace std ;
using namespace Gyoto ;
using namespace Gyoto::Metric ;
-GYOTO_PROPERTY_DOUBLE(KerrBL, HorizonSecurity, horizonSecurity,
- Generic::properties);
+GYOTO_PROPERTY_START(KerrBL)
+GYOTO_PROPERTY_DOUBLE(KerrBL, Spin, spin)
+GYOTO_PROPERTY_DOUBLE(KerrBL, HorizonSecurity, horizonSecurity)
GYOTO_PROPERTY_BOOL(KerrBL, GenericIntegrator, SpecificIntegrator,
- genericIntegrator, &HorizonSecurity);
-GYOTO_PROPERTY_DOUBLE(KerrBL, DiffTol, difftol, &GenericIntegrator);
-GYOTO_PROPERTY_DOUBLE(KerrBL, Spin, spin, &DiffTol);
-GYOTO_PROPERTY_FINALIZE(KerrBL, &Spin);
+ genericIntegrator)
+GYOTO_PROPERTY_DOUBLE(KerrBL, DiffTol, difftol)
+GYOTO_PROPERTY_END(KerrBL, Generic::properties)
/*
NB: points delicats de KerrBL:
diff --git a/lib/KerrKS.C b/lib/KerrKS.C
index ba42cde..a2a9537 100644
--- a/lib/KerrKS.C
+++ b/lib/KerrKS.C
@@ -36,12 +36,13 @@ using namespace std ;
using namespace Gyoto ;
using namespace Gyoto::Metric ;
-GYOTO_PROPERTY_DOUBLE(KerrKS, HorizonSecurity, horizonSecurity,
- Generic::properties);
+
+GYOTO_PROPERTY_START(KerrKS)
+GYOTO_PROPERTY_DOUBLE(KerrKS, Spin, spin)
+GYOTO_PROPERTY_DOUBLE(KerrKS, HorizonSecurity, horizonSecurity)
GYOTO_PROPERTY_BOOL(KerrKS, GenericIntegrator, SpecificIntegrator,
- genericIntegrator, &HorizonSecurity);
-GYOTO_PROPERTY_DOUBLE(KerrKS, Spin, spin, &GenericIntegrator);
-GYOTO_PROPERTY_FINALIZE(KerrKS, &Spin);
+ genericIntegrator)
+GYOTO_PROPERTY_END(KerrKS, Generic::properties)
/*
NOTA BENE: to improve KerrKS
diff --git a/lib/Metric.C b/lib/Metric.C
index 23a8c3f..efda430 100644
--- a/lib/Metric.C
+++ b/lib/Metric.C
@@ -36,15 +36,13 @@ Register::Entry* Metric::Register_ = NULL;
//// Gyoto::Object API
// Keplerian/NonKeplerian
-GYOTO_PROPERTY_BOOL(Metric::Generic, Keplerian, NonKeplerian,
- keplerian, Object::properties);
-GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMaxOverR,
- deltaMaxOverR, &Keplerian);
-GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMax, deltaMax, &DeltaMaxOverR);
-GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMin, deltaMin, &DeltaMax);
-GYOTO_PROPERTY_DOUBLE_UNIT(Metric::Generic, Mass, mass, &DeltaMin);
-
-GYOTO_PROPERTY_FINALIZE(Metric::Generic, &Mass);
+GYOTO_PROPERTY_START(Metric::Generic)
+GYOTO_PROPERTY_DOUBLE_UNIT(Metric::Generic, Mass, mass)
+GYOTO_PROPERTY_BOOL(Metric::Generic, Keplerian, NonKeplerian, keplerian)
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMin, deltaMin)
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMax, deltaMax)
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMaxOverR, deltaMaxOverR)
+GYOTO_PROPERTY_END(Metric::Generic, NULL)
///
diff --git a/lib/Minkowski.C b/lib/Minkowski.C
index c997400..19d421a 100644
--- a/lib/Minkowski.C
+++ b/lib/Minkowski.C
@@ -28,12 +28,22 @@ using namespace std ;
using namespace Gyoto ;
using namespace Gyoto::Metric ;
-// We create one property; its "parent" is the Generic Property list
-GYOTO_PROPERTY_BOOL(Minkowski, Spherical, Cartesian,
- spherical, Generic::properties);
-// We still need to connect this (single) property to
-// Minkowski::properties and define getProperties():
-GYOTO_PROPERTY_FINALIZE(Minkowski, &Spherical);
+//// Property list:
+//
+// Note that none of those lines ends with punctation. "," and ";" are
+// added by the macros where needed. Three steps:
+// 1- GYOTO_PROPERTY_START(<classname>)
+// 2- For each Property we want to support, a line such as:
+// GYOTO_PROPERTY_<type>(<classname>, <propertyname>, <accessorname>)
+// Note that the BOOL type is a bit special: the argument
+// <propertyname> is replaced by two arguments: <name_if_true> and
+// <name_if_false>.
+// 3- GYOTO_PROPERTY_END(<classname>, <pointer to parent's property list>)
+//
+////
+GYOTO_PROPERTY_START(Minkowski)
+GYOTO_PROPERTY_BOOL(Minkowski, Spherical, Cartesian, spherical)
+GYOTO_PROPERTY_END(Minkowski, Generic::properties)
// This is the minimal constructor: it just sets the coordinate kind and
// the metric kind name.
diff --git a/lib/NumericalMetricLorene.C b/lib/NumericalMetricLorene.C
index 32db31c..2bf435a 100644
--- a/lib/NumericalMetricLorene.C
+++ b/lib/NumericalMetricLorene.C
@@ -29,25 +29,23 @@ using namespace Lorene;
using namespace Gyoto;
using namespace Gyoto::Metric;
-// Keep File first here, so it is processed last in fillElement()
-GYOTO_PROPERTY_FILENAME(NumericalMetricLorene,
- File, directory, Generic::properties);
-GYOTO_PROPERTY_VECTOR_DOUBLE(NumericalMetricLorene,
- RefineIntegStep, refineIntegStep,
- &File);
-GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene,
- Time, initialTime, &RefineIntegStep);
-GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene,
- Horizon, horizon, &Time);
-GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
- HasSurface, HasNoSurface, hasSurface, &Horizon);
+GYOTO_PROPERTY_START(NumericalMetricLorene)
+GYOTO_PROPERTY_BOOL(NumericalMetricLorene, MapEt, MapAf, mapEt)
GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
SpecifyMarginalOrbits, DontSpecifyMarginalOrbits,
- specifyMarginalOrbits, &HasSurface);
+ specifyMarginalOrbits)
GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
- MapEt, MapAf,
- mapEt, &SpecifyMarginalOrbits);
-GYOTO_PROPERTY_FINALIZE(NumericalMetricLorene, &MapEt);
+ HasSurface, HasNoSurface, hasSurface)
+GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene, Horizon, horizon)
+GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene, Time, initialTime)
+GYOTO_PROPERTY_VECTOR_DOUBLE(NumericalMetricLorene,
+ RefineIntegStep, refineIntegStep)
+// Keep File last here, so it is processed last in fillElement()
+// (just before the generic Properties, that is
+GYOTO_PROPERTY_FILENAME(NumericalMetricLorene, File, directory)
+GYOTO_PROPERTY_END(NumericalMetricLorene, Generic::properties)
+
+
NumericalMetricLorene::NumericalMetricLorene() :
WIP("Metric::NumericalMetricLorene"),
diff --git a/lib/Object.C b/lib/Object.C
index df0dedf..a182980 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -11,7 +11,14 @@
using namespace std ;
using namespace Gyoto ;
-GYOTO_PROPERTY_FINALIZE(Object, NULL);
+// We do have a propert list. In contains a single item, wich is a
+// link to the NULL pointer, meaning end-of-the list. This is used to
+// terminate the property list of our descendents in a
+// forward-compatible manner, i.e., we may well add very generic
+// Properties in the future.
+GYOTO_PROPERTY_START(Object)
+GYOTO_PROPERTY_END(Object, NULL)
+
Gyoto::Object::Object(std::string const &name):kind_(name) {}
Gyoto::Object::Object():kind_("") {}
@@ -139,7 +146,14 @@ Value Object::get(Property const &p) const {
}
Property const * Object::property(std::string const pname) const {
- return getProperties() -> find(pname);
+ Property const * prop = getProperties();
+ while (prop) {
+ if (*prop) {
+ if (prop->name == pname) return prop;
+ ++prop;
+ } else prop=prop->parent;
+ }
+ return NULL;
}
#ifdef GYOTO_USE_XERCES
@@ -179,19 +193,17 @@ void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const
default:
throwError("Property type unimplemented in Object::fillProperty()");
}
- Property const * const * parent = p.parents;
- if (parent) {
- for ( ; *parent; ++parent) {
- fillProperty(fmp, **parent);
- }
- }
}
void Object::fillElement(Gyoto::FactoryMessenger *fmp) const {
fmp -> setSelfAttribute("kind", kind_);
-
- Property const * prop = getProperties();
- if (prop) fillProperty(fmp, *prop);
+ Property const * prop = getProperties();
+ while (prop) {
+ if (*prop) {
+ fillProperty(fmp, *prop);
+ ++prop;
+ } else prop=prop->parent;
+ }
}
void Object::setParameters(Gyoto::FactoryMessenger *fmp) {
diff --git a/lib/Photon.C b/lib/Photon.C
index 48aa801..2410fce 100644
--- a/lib/Photon.C
+++ b/lib/Photon.C
@@ -41,8 +41,8 @@
using namespace std;
using namespace Gyoto;
-GYOTO_WORLDLINE_PROPERTIES(Photon, Object::properties);
-GYOTO_PROPERTY_FINALIZE(Photon, &GYOTO_WORLDLINE_FIRST_PROPERTY);
+GYOTO_PROPERTY_START(Photon)
+GYOTO_WORLDLINE_PROPERTY_END(Photon, Object::properties)
Photon::Photon() :
Worldline(),
@@ -576,25 +576,6 @@ void Photon::Refined::transmit(size_t i, double t) {
#ifdef GYOTO_USE_XERCES
-void Photon::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const {
- if (p.name == "InitCoord") {
- if (imin_ <= imax_) {
- double coord[8];
- getInitialCoord(coord);
- // For massless particle, only 4-velocity is meaningfull
- fmp -> setParameter("InitCoord", coord, 8);
- }
- Property const * const * parent = p.parents;
- if (parent) {
- for ( ; *parent; ++parent) {
- fillProperty(fmp, **parent);
- }
- }
- return;
- }
- Object::fillProperty(fmp, p);
-}
-
void Photon::fillElement(FactoryMessenger *fmp) const {
if (object_) fmp -> astrobj (object_) ;
Object::fillElement(fmp);
diff --git a/lib/Property.C b/lib/Property.C
index e3cd1fe..eed42c2 100644
--- a/lib/Property.C
+++ b/lib/Property.C
@@ -3,27 +3,24 @@
using namespace std ;
using namespace Gyoto ;
-Property::Property(Property const * const * ancestors)
- : name(""), type(empty_t), parents(ancestors) {}
+Property::Property(Property const * const ancestors)
+ : name(""), type(empty_t), parent(ancestors) {}
-Property::Property(string n, set_long_t set, get_long_t get,
- Property const * const * ancestors)
- : name(n), type(long_t), parents(ancestors) {
+Property::Property(string n, set_long_t set, get_long_t get)
+ : name(n), type(long_t), parent(NULL) {
setter.set_long=set;
getter.get_long=get;
}
Property::Property(string n,
- set_unsigned_long_t set, get_unsigned_long_t get,
- Property const * const * ancestors)
- : name(n), type(unsigned_long_t), parents(ancestors) {
+ set_unsigned_long_t set, get_unsigned_long_t get)
+ : name(n), type(unsigned_long_t), parent(NULL) {
setter.set_unsigned_long=set;
getter.get_unsigned_long=get;
}
-Property::Property(string n, set_double_t set, get_double_t get,
- Property const * const * ancestors)
- : name(n), type(double_t), parents(ancestors) {
+Property::Property(string n, set_double_t set, get_double_t get)
+ : name(n), type(double_t), parent(NULL) {
setter.set_double=set;
getter.get_double=get;
setter_unit.set_double=NULL;
@@ -31,66 +28,55 @@ Property::Property(string n, set_double_t set, get_double_t get,
}
Property::Property(string n, set_double_t set, get_double_t get,
- set_double_unit_t setu, get_double_unit_t getu,
- Property const * const * ancestors)
- : name(n), type(double_t), parents(ancestors) {
+ set_double_unit_t setu, get_double_unit_t getu)
+ : name(n), type(double_t), parent(NULL) {
setter.set_double=set;
getter.get_double=get;
setter_unit.set_double=setu;
getter_unit.get_double=getu;
}
-Property::Property(string n, string nf, set_bool_t set, get_bool_t get,
- Property const * const * ancestors)
- : name(n), name_false(nf), type(bool_t), parents(ancestors) {
+Property::Property(string n, string nf, set_bool_t set, get_bool_t get)
+ : name(n), name_false(nf), type(bool_t), parent(NULL) {
setter.set_bool=set;
getter.get_bool=get;
}
Property::Property(string n, set_string_t set, get_string_t get,
- Property const * const * ancestors,
bool is_filename)
- : name(n), type(is_filename?filename_t:string_t), parents(ancestors) {
+ : name(n), type(is_filename?filename_t:string_t), parent(NULL) {
setter.set_string=set;
getter.get_string=get;
}
Property::Property(string n,
set_vector_double_t set,
- get_vector_double_t get,
- Property const * const * ancestors)
- : name(n), type(vector_double_t), parents(ancestors) {
+ get_vector_double_t get)
+ : name(n), type(vector_double_t), parent(NULL) {
setter.set_vdouble=set;
getter.get_vdouble=get;
}
Property::Property(string n,
set_metric_t set,
- get_metric_t get,
- Property const * const * ancestors)
- : name(n), type(metric_t), parents(ancestors) {
+ get_metric_t get)
+ : name(n), type(metric_t), parent(NULL) {
setter.set_metric=set;
getter.get_metric=get;
}
Property::Property(string n,
set_spectrum_t set,
- get_spectrum_t get,
- Property const * const * ancestors)
- : name(n), type(spectrum_t), parents(ancestors) {
+ get_spectrum_t get)
+ : name(n), type(spectrum_t), parent(NULL) {
setter.set_spectrum=set;
getter.get_spectrum=get;
}
Property const * Property::find(std::string n) const {
- if (this == NULL) return NULL;
+ if (type == empty_t) return parent;
if (name == n || (type == bool_t && name_false == n)) return this;
- if (parents == NULL) return NULL;
- Property const * const * p ;
- Property const * result = NULL;
- for (p=parents; *p != NULL; ++p) {
- result = (*p)->find(n);
- if (result) break;
- }
- return result;
+ return this + 1;
}
+
+Property::operator bool() const { return type != empty_t; }
diff --git a/lib/RotStar3_1.C b/lib/RotStar3_1.C
index 7fa3135..a467f4e 100644
--- a/lib/RotStar3_1.C
+++ b/lib/RotStar3_1.C
@@ -44,10 +44,11 @@ using namespace Lorene;
using namespace Gyoto;
using namespace Gyoto::Metric;
-GYOTO_PROPERTY_FILENAME(RotStar3_1, File, file, Generic::properties);
+GYOTO_PROPERTY_START(RotStar3_1)
GYOTO_PROPERTY_BOOL(RotStar3_1, GenericIntegrator, SpecificIntegrator,
- genericIntegrator, &File);
-GYOTO_PROPERTY_FINALIZE(RotStar3_1, &GenericIntegrator);
+ genericIntegrator)
+GYOTO_PROPERTY_FILENAME(RotStar3_1, File, file)
+GYOTO_PROPERTY_END(RotStar3_1, Generic::properties)
RotStar3_1::RotStar3_1() :
Generic(GYOTO_COORDKIND_SPHERICAL, "RotStar3_1"),
diff --git a/lib/StandardAstrobj.C b/lib/StandardAstrobj.C
index 83f5894..f8587b4 100644
--- a/lib/StandardAstrobj.C
+++ b/lib/StandardAstrobj.C
@@ -40,9 +40,9 @@ using namespace std;
using namespace Gyoto;
using namespace Gyoto::Astrobj;
-GYOTO_PROPERTY_DOUBLE(Standard,
- SafetyValue, safetyValue, Generic::properties);
-GYOTO_PROPERTY_FINALIZE(Standard, &SafetyValue);
+GYOTO_PROPERTY_START(Standard)
+GYOTO_PROPERTY_DOUBLE(Standard, SafetyValue, safetyValue)
+GYOTO_PROPERTY_END(Standard, Generic::properties)
Standard::Standard(string kin) :
Generic(kin),
diff --git a/lib/Star.C b/lib/Star.C
index ac74fab..14b0105 100644
--- a/lib/Star.C
+++ b/lib/Star.C
@@ -38,8 +38,8 @@ using namespace std;
using namespace Gyoto;
using namespace Gyoto::Astrobj;
-GYOTO_WORLDLINE_PROPERTIES(Star, UniformSphere::properties);
-GYOTO_PROPERTY_FINALIZE(Star, &GYOTO_WORLDLINE_FIRST_PROPERTY);
+GYOTO_PROPERTY_START(Star)
+GYOTO_WORLDLINE_PROPERTY_END(Star, UniformSphere::properties)
Star::Star() :
UniformSphere("Star"),
@@ -163,12 +163,6 @@ void Star::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const {
fmp -> setParameter ("Position", coord, 4);
fmp -> setParameter ("Velocity", vel, 3);
}
- Property const * const * parent = p.parents;
- if (parent) {
- for ( ; *parent; ++parent) {
- fillProperty(fmp, **parent);
- }
- }
return;
}
UniformSphere::fillProperty(fmp, p);
diff --git a/lib/Torus.C b/lib/Torus.C
index ebf8c7b..5f18736 100644
--- a/lib/Torus.C
+++ b/lib/Torus.C
@@ -35,15 +35,12 @@ using namespace Gyoto;
using namespace Gyoto::Astrobj;
using namespace std;
-GYOTO_PROPERTY_DOUBLE(Torus,
- LargeRadius, largeRadius, Standard::properties);
-GYOTO_PROPERTY_DOUBLE(Torus,
- SmallRadius, smallRadius, &LargeRadius);
-GYOTO_PROPERTY_SPECTRUM(Torus,
- Opacity, opacity, &SmallRadius);
-GYOTO_PROPERTY_SPECTRUM(Torus,
- Spectrum, spectrum, &Opacity);
-GYOTO_PROPERTY_FINALIZE(Torus, &::Spectrum);
+GYOTO_PROPERTY_START(Torus)
+GYOTO_PROPERTY_SPECTRUM(Torus, Spectrum, spectrum)
+GYOTO_PROPERTY_SPECTRUM(Torus, Opacity, opacity)
+GYOTO_PROPERTY_DOUBLE(Torus, SmallRadius, smallRadius)
+GYOTO_PROPERTY_DOUBLE(Torus, LargeRadius, largeRadius)
+GYOTO_PROPERTY_END(Torus, Standard::properties)
Torus::Torus() : Standard("Torus"),
c_(3.5)
diff --git a/lib/UniformSphere.C b/lib/UniformSphere.C
index 75578a2..c552835 100644
--- a/lib/UniformSphere.C
+++ b/lib/UniformSphere.C
@@ -38,22 +38,19 @@ using namespace std;
using namespace Gyoto;
using namespace Gyoto::Astrobj;
-GYOTO_PROPERTY_DOUBLE_UNIT(UniformSphere, Radius, radius, Standard::properties);
-GYOTO_PROPERTY_DOUBLE(UniformSphere, Alpha, alpha, &Radius);
+GYOTO_PROPERTY_START(UniformSphere)
+GYOTO_PROPERTY_SPECTRUM(UniformSphere, Spectrum, spectrum)
+GYOTO_PROPERTY_SPECTRUM(UniformSphere,Opacity, opacity)
+GYOTO_PROPERTY_BOOL(UniformSphere,
+ IsotropicEmittedIntensity, TrueEmittedIntensity,
+ isotropic)
GYOTO_PROPERTY_DOUBLE(UniformSphere,
- DeltaMaxOverRadius, deltaMaxOverRadius, &Alpha);
+ DeltaMaxOverDistance, deltaMaxOverDistance)
GYOTO_PROPERTY_DOUBLE(UniformSphere,
- DeltaMaxOverDistance, deltaMaxOverDistance,
- &DeltaMaxOverRadius);
-GYOTO_PROPERTY_BOOL(UniformSphere,
- IsotropicEmittedIntensity,
- TrueEmittedIntensity,
- isotropic, &DeltaMaxOverDistance);
-GYOTO_PROPERTY_SPECTRUM(UniformSphere,
- Opacity, opacity, &IsotropicEmittedIntensity);
-GYOTO_PROPERTY_SPECTRUM(UniformSphere,
- Spectrum, spectrum, &Opacity);
-GYOTO_PROPERTY_FINALIZE(UniformSphere, &::Spectrum);
+ DeltaMaxOverRadius, deltaMaxOverRadius)
+GYOTO_PROPERTY_DOUBLE(UniformSphere, Alpha, alpha)
+GYOTO_PROPERTY_DOUBLE_UNIT(UniformSphere, Radius, radius)
+GYOTO_PROPERTY_END(UniformSphere, Standard::properties)
#define GYOTO_USPH_DELTAMAX_OVER_RAD 0.1
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git
More information about the Debian-astro-commits
mailing list