[Debian-astro-commits] [gyoto] 121/221: * Make SmartPointee not and Object, but most of its descendents. * New Value/Property type: unsigned long * Convert Worldline to Object/Property

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 3dfa0fd17208be7f95947062271ac9148763b3d1
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Fri Nov 28 14:57:14 2014 +0100

    * Make SmartPointee not and Object, but most of its descendents.
    * New Value/Property type: unsigned long
    * Convert Worldline to Object/Property
---
 include/GyotoAstrobj.h      |   6 ++-
 include/GyotoMetric.h       |   2 +
 include/GyotoObject.h       |   2 +-
 include/GyotoPhoton.h       |   3 --
 include/GyotoProperty.h     |  39 +++++++++++++++-
 include/GyotoScenery.h      |   6 ++-
 include/GyotoScreen.h       |   6 ++-
 include/GyotoSmartPointer.h |   6 +--
 include/GyotoSpectrometer.h |   2 +
 include/GyotoSpectrum.h     |   6 ++-
 include/GyotoValue.h        |   5 ++
 include/GyotoWorldline.h    |  52 ++++++---------------
 lib/Astrobj.C               |  13 ++++--
 lib/Metric.C                |   4 +-
 lib/Object.C                |  14 ++++++
 lib/Photon.C                |   8 ----
 lib/Property.C              |  15 ++++++
 lib/SmartPointer.C          |  13 ++----
 lib/StarTrace.C             |  12 +++--
 lib/Value.C                 |   4 ++
 lib/Worldline.C             | 111 ++++++++++++++++++++++++++------------------
 yorick/gyoto_utils.C        |  55 ++++++++++++++++++++--
 yorick/ygyoto_private.h     |   3 +-
 23 files changed, 259 insertions(+), 128 deletions(-)

diff --git a/include/GyotoAstrobj.h b/include/GyotoAstrobj.h
index 92dfa69..d97be27 100644
--- a/include/GyotoAstrobj.h
+++ b/include/GyotoAstrobj.h
@@ -38,6 +38,7 @@
 #include <GyotoDefs.h>
 #include <GyotoSmartPointer.h>
 #include <GyotoConverters.h>
+#include <GyotoObject.h>
 
 namespace Gyoto{
   class Photon;
@@ -184,7 +185,10 @@ namespace Gyoto{
  *
  * See introduction in the Gyoto::Astrobj namespace.
  */
-class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
+class Gyoto::Astrobj::Generic
+: public Gyoto::SmartPointee,
+  public Gyoto::Object
+{
   friend class Gyoto::SmartPointer<Gyoto::Astrobj::Generic>;
 
 
diff --git a/include/GyotoMetric.h b/include/GyotoMetric.h
index 0e6487f..0bd2609 100644
--- a/include/GyotoMetric.h
+++ b/include/GyotoMetric.h
@@ -36,6 +36,7 @@
 #include <string>
 
 #include <GyotoSmartPointer.h>
+#include <GyotoObject.h>
 #include <GyotoAstrobj.h>
 #include <GyotoRegister.h>
 #include <GyotoHooks.h>
@@ -146,6 +147,7 @@ namespace Gyoto {
  */
 class Gyoto::Metric::Generic
 : public Gyoto::SmartPointee,
+  public Gyoto::Object,
   public Gyoto::Hook::Teller
 {
   friend class Gyoto::SmartPointer<Gyoto::Metric::Generic>;
diff --git a/include/GyotoObject.h b/include/GyotoObject.h
index 5769b4a..02a471e 100644
--- a/include/GyotoObject.h
+++ b/include/GyotoObject.h
@@ -64,7 +64,7 @@ class Gyoto::Object
   Property const * property(std::string const pname) const;
 
 #ifdef GYOTO_USE_XERCES
-  void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const ;
+  virtual void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const ;
 
   /// Called from Factory
   /**
diff --git a/include/GyotoPhoton.h b/include/GyotoPhoton.h
index a439e1c..07145f3 100644
--- a/include/GyotoPhoton.h
+++ b/include/GyotoPhoton.h
@@ -267,9 +267,6 @@ class Gyoto::Photon : public Gyoto::Worldline, public Gyoto::SmartPointee {
    */
   virtual void transmit(size_t i, double t);
 
-  int setParameter(std::string name,
-			   std::string content,
-			   std::string unit) ;
  private:
   /// Allocate Photon::transmission_
   void _allocateTransmission();
diff --git a/include/GyotoProperty.h b/include/GyotoProperty.h
index 723be57..3fb0f52 100644
--- a/include/GyotoProperty.h
+++ b/include/GyotoProperty.h
@@ -74,6 +74,26 @@ namespace Gyoto {
 	   (Gyoto::Property::get_double_t)&class::fname,	\
          name##_ancestors)
 
+/// 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 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_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); \
@@ -145,7 +165,8 @@ class Gyoto::Property
  private:
 
  public:
-  enum type_e {double_t, long_t, bool_t, string_t, filename_t,
+  enum type_e {double_t, long_t, unsigned_long_t, bool_t,
+	       string_t, filename_t,
 	       vector_double_t, metric_t, spectrum_t};
   std::string name;
   std::string name_false;
@@ -155,8 +176,10 @@ class Gyoto::Property
   typedef void (Object::* set_double_unit_t)(double val,
 					     std::string const &unit);
   typedef double (Object::* get_double_unit_t)(std::string const &unit) const;
-  typedef void (Object::* set_long_t)(double val);
+  typedef void (Object::* set_long_t)(long val);
   typedef long (Object::* get_long_t)() const;
+  typedef void (Object::* set_unsigned_long_t)(unsigned long val);
+  typedef unsigned long (Object::* get_unsigned_long_t)() const;
   typedef void (Object::* set_bool_t)(bool val);
   typedef bool (Object::* get_bool_t)() const;
   typedef void (Object::* set_string_t)(std::string const&);
@@ -179,6 +202,7 @@ class Gyoto::Property
   union setter_t {
     set_double_t set_double;
     set_long_t set_long;
+    set_unsigned_long_t set_unsigned_long;
     set_bool_t set_bool;
     set_string_t set_string;
     set_vector_double_t set_vdouble;
@@ -188,6 +212,7 @@ class Gyoto::Property
   union getter_t {
     get_double_t get_double;
     get_long_t get_long;
+    get_unsigned_long_t get_unsigned_long;
     get_bool_t get_bool;
     get_string_t get_string;
     get_vector_double_t get_vdouble;
@@ -203,6 +228,16 @@ class Gyoto::Property
   Property const * const  * const parents;
   
   Property(std::string name,
+	   set_long_t set_long,
+	   get_long_t get_long,
+	   Property const * const * ancestors);
+
+  Property(std::string name,
+	   set_unsigned_long_t set_unsigned_long,
+	   get_unsigned_long_t get_unsigned_long,
+	   Property const * const * ancestors);
+
+  Property(std::string name,
 	   set_double_t set_double,
 	   get_double_t get_double,
 	   Property const * const * ancestors);
diff --git a/include/GyotoScenery.h b/include/GyotoScenery.h
index 9e0c7aa..4f6b4ac 100644
--- a/include/GyotoScenery.h
+++ b/include/GyotoScenery.h
@@ -33,6 +33,7 @@ namespace Gyoto{
 
 #include <GyotoDefs.h>
 #include <GyotoSmartPointer.h>
+#include <GyotoObject.h>
 #include <GyotoAstrobj.h>
 #include <GyotoMetric.h>
 #include <GyotoScreen.h>
@@ -158,7 +159,10 @@ namespace Gyoto{
  * </Scenery>
  * \endcode
  */
-class Gyoto::Scenery : public Gyoto::SmartPointee {
+class Gyoto::Scenery
+: public Gyoto::SmartPointee,
+  public Gyoto::Object
+{
   friend class Gyoto::SmartPointer<Gyoto::Scenery>;
   
   
diff --git a/include/GyotoScreen.h b/include/GyotoScreen.h
index e60ae83..9624480 100644
--- a/include/GyotoScreen.h
+++ b/include/GyotoScreen.h
@@ -48,6 +48,7 @@ namespace Gyoto {
 #include <GyotoDefs.h>
 #include <GyotoUtils.h>
 #include <GyotoSmartPointer.h>
+#include <GyotoObject.h>
 #include <GyotoMetric.h>
 #include <GyotoSpectrometer.h>
 
@@ -162,7 +163,10 @@ namespace Gyoto {
  * "`pwd`/".
  *
  */
-class Gyoto::Screen : public Gyoto::SmartPointee {
+class Gyoto::Screen
+: public Gyoto::SmartPointee,
+  public Gyoto::Object
+{
   friend class Gyoto::SmartPointer<Gyoto::Screen>;
 
  private:
diff --git a/include/GyotoSmartPointer.h b/include/GyotoSmartPointer.h
index 79b09e7..0497107 100644
--- a/include/GyotoSmartPointer.h
+++ b/include/GyotoSmartPointer.h
@@ -46,10 +46,10 @@
 
 namespace Gyoto {
   class SmartPointee;
+  class FactoryMessenger;
   template <class T> class SmartPointer;
 }
 
-#include <GyotoObject.h>
 #include <GyotoError.h>
 #include <stddef.h>
 #include <iostream>
@@ -75,7 +75,7 @@ namespace Gyoto {
  * @endcode
  *
  */
-class Gyoto::SmartPointee : public Gyoto::Object
+class Gyoto::SmartPointee
 {
  private:
   int refCount; ///< Reference counter.
@@ -89,7 +89,7 @@ class Gyoto::SmartPointee : public Gyoto::Object
 
  public:
   SmartPointee () ;
-  SmartPointee (std::string kind) ;
+  virtual ~SmartPointee() ;
   SmartPointee (const   SmartPointee&) ; ///< Copy constructor
   void incRefCount () ; ///< Increment the reference counter. Warning: Don't mess with the counter.
   int decRefCount () ;  ///< Decrement the reference counter and return current value. Warning: Don't mess with the counter.
diff --git a/include/GyotoSpectrometer.h b/include/GyotoSpectrometer.h
index 4b47d55..69635be 100644
--- a/include/GyotoSpectrometer.h
+++ b/include/GyotoSpectrometer.h
@@ -29,6 +29,7 @@
 
 #include <GyotoDefs.h>
 #include <GyotoSmartPointer.h>
+#include <GyotoObject.h>
 #include <GyotoRegister.h>
 #include <GyotoHooks.h>
 #include <string>
@@ -170,6 +171,7 @@ namespace Gyoto{
 
 class Gyoto::Spectrometer::Generic
 : public Gyoto::SmartPointee,
+  public Gyoto::Object,
   public Gyoto::Hook::Teller
 {
   friend class Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>;
diff --git a/include/GyotoSpectrum.h b/include/GyotoSpectrum.h
index b496666..42efefb 100644
--- a/include/GyotoSpectrum.h
+++ b/include/GyotoSpectrum.h
@@ -28,6 +28,7 @@
 #define __GyotoSpectrum_H_ 
 
 #include "GyotoRegister.h"
+#include "GyotoObject.h"
 
 namespace Gyoto{
   namespace Register { class Entry; }
@@ -122,7 +123,10 @@ namespace Gyoto{
  *  Light emitted by e.g. a Star
  *
  */
-class Gyoto::Spectrum::Generic : public Gyoto::SmartPointee {
+class Gyoto::Spectrum::Generic
+: public Gyoto::SmartPointee,
+  public Gyoto::Object
+{
   friend class Gyoto::SmartPointer<Gyoto::Spectrum::Generic>;
  protected:
   std::string kind_; ///< e.g. constants, blackbody...
diff --git a/include/GyotoValue.h b/include/GyotoValue.h
index 5a311a7..e1a25f1 100644
--- a/include/GyotoValue.h
+++ b/include/GyotoValue.h
@@ -32,6 +32,7 @@
 #include <vector>
 
 namespace Gyoto {
+  class Value;
   namespace Metric {class Generic;}
   namespace Spectrum {class Generic;}
 }
@@ -55,6 +56,10 @@ class Gyoto::Value {
   Value(long);
   operator long() const;
 
+  unsigned long ULong;
+  Value(unsigned long);
+  operator unsigned long() const;
+
   std::string String;
   Value(std::string);
   operator std::string() const;
diff --git a/include/GyotoWorldline.h b/include/GyotoWorldline.h
index 6044d9e..4b8c0c8 100644
--- a/include/GyotoWorldline.h
+++ b/include/GyotoWorldline.h
@@ -79,7 +79,7 @@ namespace Gyoto {
  * 
  */
 class Gyoto::Worldline
-:  protected Gyoto::Hook::Listener
+:  protected Gyoto::Hook::Listener, public Gyoto::Object
 {
 
   // Data : 
@@ -187,6 +187,7 @@ class Gyoto::Worldline
   // Constructors - Destructor
   // -------------------------
  public: 
+  GYOTO_OBJECT;
   Worldline() ; ///< Default constructor
   
   Worldline(const Worldline& ) ;                ///< Copy constructor
@@ -216,6 +217,10 @@ class Gyoto::Worldline
   virtual double getMass() const = 0; ///< Get mass of particule.
   void   metric(SmartPointer<Metric::Generic>); ///< Set metric Smartpointer
   SmartPointer<Metric::Generic> metric() const; ///< Get metric
+
+  void initCoord(std::vector<double> const&); 
+  std::vector<double> initCoord() const; 
+
   virtual void   setInitCoord(const double coord[8], int dir = 0); ///< Set Initial coordinate
 
   /**
@@ -246,7 +251,7 @@ class Gyoto::Worldline
    *                 "runge_kutta_fehlberg78", "runge_kutta_dopri5",
    *                 "runge_kutta_cash_karp54_classic"
    */
-  void integrator(std::string type);
+  void integrator(std::string const & type);
 
   /**
    * \brief Describe the integrator used by #state_
@@ -383,46 +388,19 @@ class Gyoto::Worldline
   virtual void xStore(size_t ind, double coord[8]) ; ///< Store coord at index ind
   virtual void xFill(double tlim) ; ///< Fill x0, x1... by integrating the Worldline from previously set inittial condition to time tlim
 
-  /**
-   * \brief Set parameter by name
-   *
-   * Assume MyKind is a subclass of Worldline which has two
-   * members (a string StringMember and a double DoubleMember):
-   * \code
-   * int MyKind::setParameter(std::string name,
-   *                          std::string content,
-   *                          std::string unit) {
-   *   if      (name=="StringMember") setStringMember(content);
-   *   else if (name=="DoubleMember") setDoubleMember(atof(content.c_str()),
-   *                                                  unit);
-   *   else return Worldline::setParameter(name, content, unit);
-   *   return 0;
-   * }
-   * \endcode
-   *
-   * \param name XML name of the parameter
-   * \param content string representation of the value
-   * \param unit string representation of the unit
-   * \return 0 if this parameter is known, 1 if it is not.
-   */
+
+  // Object / Property overloading for special needs:
+  // Overload to interpret InitialCoordinate alias, and to interpret
+  // Position/Velocity
   virtual int setParameter(std::string name,
 			   std::string content,
 			   std::string unit) ;
-
 #ifdef GYOTO_USE_XERCES
-  /**
-   * \brief Process XML entity
-   * Uses wait_pos_ and init_vel_ to make sure setVelocity() is called
-   * after setPosition().
-   */
+  // Overload to 1- get metric first and 2- interpret Position/Velocity
   virtual void setParameters(FactoryMessenger *fmp) ;
-  /**
-   * Derived classes implementations should implement fillElement to save their
-   * parameters to XML and call the generic implementation to save
-   * generic parts such as adaptive_: Worldline::fillElement(fmp).
-   */
-  virtual void fillElement(FactoryMessenger *fmp) const ;
-                                             ///< XML output
+  // Overload to dispatch InitCoord into Position and Velocity
+  // for massive particle
+  virtual void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const ;
 #endif
 
   // Accessors
diff --git a/lib/Astrobj.C b/lib/Astrobj.C
index 1bd13f6..ed614a6 100644
--- a/lib/Astrobj.C
+++ b/lib/Astrobj.C
@@ -53,7 +53,8 @@ GYOTO_PROPERTY_METRIC(Generic, Metric, metric, &RMax);
 GYOTO_PROPERTY_FINALIZE(Generic, &::Metric);
 
 Generic::Generic(string kin) :
-  SmartPointee(kin), gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
+  SmartPointee(), Object(kin),
+  gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
   radiativeq_(0), noredshift_(0)
 {
 #if GYOTO_DEBUG_ENABLED
@@ -62,8 +63,8 @@ Generic::Generic(string kin) :
 }
 
 Generic::Generic() :
-
-  SmartPointee("Default"), gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
+  SmartPointee(), Object("Default"),
+  gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
   radiativeq_(0), noredshift_(0)
 {
 #if GYOTO_DEBUG_ENABLED
@@ -72,7 +73,8 @@ Generic::Generic() :
 }
 
 Generic::Generic(double radmax) :
-  SmartPointee("Default"), gg_(NULL), rmax_(radmax), flag_radtransf_(0),
+  SmartPointee(), Object("Default"),
+  gg_(NULL), rmax_(radmax), flag_radtransf_(0),
   radiativeq_(0), noredshift_(0)
 {
 #if GYOTO_DEBUG_ENABLED
@@ -81,7 +83,8 @@ Generic::Generic(double radmax) :
 }
 
 Generic::Generic(const Generic& orig) :
-  SmartPointee(orig), gg_(NULL),
+  SmartPointee(orig), Object(orig),
+  gg_(NULL),
   rmax_(orig.rmax_),
   flag_radtransf_(orig.flag_radtransf_), radiativeq_(orig.radiativeq_),
   noredshift_(orig.noredshift_)
diff --git a/lib/Metric.C b/lib/Metric.C
index 2986300..23a8c3f 100644
--- a/lib/Metric.C
+++ b/lib/Metric.C
@@ -49,7 +49,7 @@ GYOTO_PROPERTY_FINALIZE(Metric::Generic, &Mass);
 ///
 
 Metric::Generic::Generic(const int coordkind, const std::string &name) :
-  SmartPointee(name), mass_(1.), coordkind_(coordkind),
+  SmartPointee(), Object(name), mass_(1.), coordkind_(coordkind),
   delta_min_(GYOTO_DEFAULT_DELTA_MIN),
   delta_max_(GYOTO_DEFAULT_DELTA_MAX),
   delta_max_over_r_(GYOTO_DEFAULT_DELTA_MAX_OVER_R),
@@ -64,7 +64,7 @@ Metric::Generic::Generic(const int coordkind, const std::string &name) :
 }
 
 Metric::Generic::Generic(Generic const &o):
-  SmartPointee(o), mass_(o.mass_), coordkind_(o.coordkind_),
+  SmartPointee(o), Object(o), mass_(o.mass_), coordkind_(o.coordkind_),
   delta_min_(o.delta_min_), delta_max_(o.delta_max_),
   delta_max_over_r_(o.delta_max_over_r_), keplerian_(o.keplerian_)
 {}
diff --git a/lib/Object.C b/lib/Object.C
index 3673e4f..3c58d9b 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -56,6 +56,7 @@ void Object::set(Property const &p, Value val) {
     ___local_case(double);
     ___local_case(bool);
     ___local_case(long);
+    ___local_case(unsigned_long);
   case Property::filename_t:
     ___local_case(string);
   case Property::vector_double_t:
@@ -104,6 +105,7 @@ Value Object::get(Property const &p) const {
     ___local_case(bool);
     ___local_case(double);
     ___local_case(long);
+    ___local_case(unsigned_long);
   case Property::filename_t:
     ___local_case(string);
   case Property::vector_double_t:
@@ -134,6 +136,12 @@ void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const
   case Property::bool_t:
     fmp->setParameter(get(p)?name:p.name_false);
     break;
+  case Property::long_t:
+    fmp->setParameter(name, long(get(p)));
+    break;
+  case Property::unsigned_long_t:
+    fmp->setParameter(name, (unsigned long)(get(p)));
+    break;
   case Property::double_t:
     fmp->setParameter(name, double(get(p)));
     break;
@@ -213,6 +221,12 @@ void Object::setParameter(Property const &p, string const &name,
   case Property::bool_t:
     val = (name==p.name);
     break;
+  case Property::long_t:
+    val = long(atoi(content.c_str()));
+    break;
+  case Property::unsigned_long_t:
+    val = (unsigned long)(atoi(content.c_str()));
+    break;
   case Property::double_t:
     val = atof(content.c_str());
     set(p, val, unit);
diff --git a/lib/Photon.C b/lib/Photon.C
index d30fecd..be01bf0 100644
--- a/lib/Photon.C
+++ b/lib/Photon.C
@@ -584,15 +584,7 @@ SmartPointer<Photon> Gyoto::Photon::Subcontractor(FactoryMessenger* fmp) {
   SmartPointer<Photon> ph = new Photon();
   ph -> astrobj( fmp->astrobj() );
   ph -> Worldline::setParameters(fmp);
-  ph -> SmartPointee::setParameters(fmp);
 
   return ph;
 }
 #endif
-
-int Photon::setParameter(std::string name,
-			   std::string content,
-			 std::string unit) {
-  return (Worldline::setParameter(name, content, unit) &&
-	  SmartPointee::setParameter(name, content, unit));
-}
diff --git a/lib/Property.C b/lib/Property.C
index 683b138..9f31b49 100644
--- a/lib/Property.C
+++ b/lib/Property.C
@@ -3,6 +3,21 @@
 using namespace std ;
 using namespace Gyoto ;
 
+Property::Property(string n, set_long_t set, get_long_t get,
+		   Property const * const * ancestors)
+  : name(n), type(long_t), parents(ancestors) {
+  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) {
+  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) {
diff --git a/lib/SmartPointer.C b/lib/SmartPointer.C
index 850505f..7644a55 100644
--- a/lib/SmartPointer.C
+++ b/lib/SmartPointer.C
@@ -30,20 +30,17 @@ Gyoto::SmartPointee::SmartPointee() :
   pthread_mutex_init(&mutex_, NULL);
 #endif
 }
-Gyoto::SmartPointee::SmartPointee(std::string name) :
-  Object(name), refCount (0)
-{
-#ifdef HAVE_PTHREAD
-  pthread_mutex_init(&mutex_, NULL);
-#endif
-}
+
+Gyoto::SmartPointee::~SmartPointee() {}
+
 Gyoto::SmartPointee::SmartPointee(const SmartPointee&o) :
-  Object(o), refCount (0)
+  refCount (0)
 {
 #ifdef HAVE_PTHREAD
   pthread_mutex_init(&mutex_, NULL);
 #endif
 }
+
 void Gyoto::SmartPointee::incRefCount () {
 #ifdef HAVE_PTHREAD
  pthread_mutex_lock(&mutex_);
diff --git a/lib/StarTrace.C b/lib/StarTrace.C
index 4d6b403..db3e813 100644
--- a/lib/StarTrace.C
+++ b/lib/StarTrace.C
@@ -35,7 +35,8 @@ using namespace Gyoto::Astrobj;
 
 StarTrace::StarTrace() : Star()
 {
-  kind_="StarTrace";
+  Generic::kind_="StarTrace";
+  Worldline::kind_="StarTrace";
   xAllocateXYZ();
 # ifdef GYOTO_DEBUG_ENABLED
   GYOTO_DEBUG << "done." << endl;
@@ -47,14 +48,16 @@ StarTrace::StarTrace(SmartPointer<Metric::Generic> met, double rad,
 		double v[3]) :
   Star(met, rad, pos, v)
 {
-  kind_="StarTrace";
+  Generic::kind_="StarTrace";
+  Worldline::kind_="StarTrace";
   xAllocateXYZ();
   computeXYZ(i0_);
 }
 
 StarTrace::StarTrace(const StarTrace& o) : Star(o), tmin_(o.tmin_), tmax_(o.tmax_)
 {
-  kind_="StarTrace";
+  Generic::kind_="StarTrace";
+  Worldline::kind_="StarTrace";
   xAllocateXYZ();
   size_t sz = get_nelements()*sizeof(double);
   memcpy(x_+imin_, o.x_+imin_, sz);
@@ -65,7 +68,8 @@ StarTrace::StarTrace(const StarTrace& o) : Star(o), tmin_(o.tmin_), tmax_(o.tmax
 StarTrace::StarTrace(const Star& o, double tmin, double tmax) :
   Star(o), tmin_(tmin), tmax_(tmax)
 {
-  kind_="StarTrace";
+  Generic::kind_="StarTrace";
+  Worldline::kind_="StarTrace";
   xAllocateXYZ();
   computeXYZ();
 }
diff --git a/lib/Value.C b/lib/Value.C
index 0143ae7..172fa54 100644
--- a/lib/Value.C
+++ b/lib/Value.C
@@ -19,6 +19,9 @@ Value::operator bool() const {return Bool;}
 Value::Value(long val) : Long(val) {}
 Value::operator long() const {return Long;}
 
+Value::Value(unsigned long val) : ULong(val) {}
+Value::operator unsigned long() const {return ULong;}
+
 Value::Value(std::string val) : String(val) {}
 Value::operator std::string() const {return String;}
 
@@ -40,6 +43,7 @@ Value& Value::operator=(Value const &right) {
   ___local_case(Double);
   ___local_case(Bool);
   ___local_case(Long);
+  ___local_case(ULong);
   ___local_case(String);
   ___local_case(VDouble);
   ___local_case(Metric);
diff --git a/lib/Worldline.C b/lib/Worldline.C
index ff21efa..78328e7 100644
--- a/lib/Worldline.C
+++ b/lib/Worldline.C
@@ -19,7 +19,7 @@
 
 #include <GyotoWorldline.h>
 #include <GyotoUtils.h>
-//#include <GyotoKerrBL.h>
+#include <GyotoProperty.h>
 #include <GyotoFactoryMessenger.h>
 #include <iostream>
 #include <sstream>
@@ -31,6 +31,21 @@
 using namespace std;
 using namespace Gyoto;
 
+GYOTO_PROPERTY_BOOL(Worldline,
+		    HighOrderImages, PrimaryOnly, secondary,
+		    Object::properties);
+GYOTO_PROPERTY_DOUBLE(Worldline, RelTol, relTol, &HighOrderImages);
+GYOTO_PROPERTY_DOUBLE(Worldline, AbsTol, absTol, &RelTol);
+GYOTO_PROPERTY_DOUBLE(Worldline, DeltaMaxOverR, deltaMaxOverR, &AbsTol);
+GYOTO_PROPERTY_DOUBLE(Worldline, DeltaMax, deltaMax, &DeltaMaxOverR);
+GYOTO_PROPERTY_DOUBLE(Worldline, DeltaMin, deltaMin, &DeltaMax);
+GYOTO_PROPERTY_STRING(Worldline, Integrator, integrator, &DeltaMin);
+GYOTO_PROPERTY_SIZE_T(Worldline, MaxIter, maxiter, &Integrator);
+GYOTO_PROPERTY_BOOL(Worldline, Adaptive, NonAdaptive, adaptive, &MaxIter);
+GYOTO_PROPERTY_DOUBLE_UNIT(Worldline, Delta, delta, &Adaptive);
+GYOTO_PROPERTY_VECTOR_DOUBLE(Worldline, InitCoord, initCoord, &Delta);
+GYOTO_PROPERTY_METRIC(Worldline, Metric, metric, &InitCoord);
+GYOTO_PROPERTY_FINALIZE(Worldline, &::Metric);
 
 Worldline::Worldline() : stopcond(0), metric_(NULL),
                          imin_(1), i0_(0), imax_(0), adaptive_(1),
@@ -281,41 +296,37 @@ void Worldline::tell(Gyoto::Hook::Teller* msg) {
 }
 
 #ifdef GYOTO_USE_XERCES
-void Worldline::fillElement(FactoryMessenger *fmp) const {
-  if (metric_)     fmp -> metric (metric_) ;
 
-  if (imin_ <= imax_) {
-    double coord[8];
-    getInitialCoord(coord);
-    if (getMass()) {
-      // For massive particule, express initial condition with 3-velocity
-      double vel[3] = {coord[5]/coord[4], coord[6]/coord[4], coord[7]/coord[4]};
-      fmp -> setParameter ("Position", coord, 4);
-      fmp -> setParameter ("Velocity", vel, 3);
-    } else {
-      // For massless particle, only 4-velocity is meaningfull
-      fmp -> setParameter("InitCoord", coord, 8);
+void Worldline::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const {
+  if (p.name == "InitCoord") {
+    if (imin_ <= imax_) {
+      double coord[8];
+      getInitialCoord(coord);
+      if (getMass()) {
+	// For massive particule, express initial condition with 3-velocity
+	double vel[3] = {coord[5]/coord[4], coord[6]/coord[4], coord[7]/coord[4]};
+	fmp -> setParameter ("Position", coord, 4);
+	fmp -> setParameter ("Velocity", vel, 3);
+      } else {
+	// 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;
   }
-
-  fmp -> setParameter ("Delta", delta_);
-  fmp -> setParameter(adaptive_?"Adaptive":"NonAdaptive");
-  fmp -> setParameter("MaxIter", maxiter_);
-  fmp -> setParameter("Integrator", state_->kind());
-  fmp -> setParameter("DeltaMin", delta_min_);
-  fmp -> setParameter("DeltaMax", delta_max_);
-  fmp -> setParameter("DeltaMaxOverR", delta_max_over_r_);
-  fmp -> setParameter("AbsTol", abstol_);
-  fmp -> setParameter("RelTol", reltol_);
+  Object::fillProperty(fmp, p);
 }
 
 void Worldline::setParameters(FactoryMessenger* fmp) {
-  if (!fmp) return;
-  string name="", content="", unit="";
   wait_pos_ = 1;
   metric(fmp->metric());
-  while (fmp->getNextParameter(&name, &content, &unit))
-    setParameter(name, content, unit);
+  Object::setParameters(fmp);
   wait_pos_ = 0;
   if (init_vel_) {
     delete[] init_vel_; init_vel_=NULL;
@@ -330,10 +341,9 @@ int Worldline::setParameter(std::string name,
 			    std::string unit) {
   double coord[8];
   char* tc = const_cast<char*>(content.c_str());
-  if (name=="InitialCoordinate" || name=="InitCoord") {
-    if (FactoryMessenger::parseArray(content, coord, 8) != 8)
-      throwError("Worldline \"InitialCoordinate\" requires exactly 8 tokens");
-    setInitCoord(coord);
+  if (name=="InitialCoordinate") {
+    name=="InitCoord";
+    return Object::setParameter(name, content, unit);
   } else if (name=="Position") {
     if (FactoryMessenger::parseArray(content, coord, 4) != 4)
       throwError("Worldline \"Position\" requires exactly 4 tokens");
@@ -350,22 +360,12 @@ int Worldline::setParameter(std::string name,
       init_vel_ = new double[3];
       memcpy(init_vel_, coord, 3*sizeof(double));
     } else setVelocity(coord);
-  } else   if (name=="Delta")   delta(atof(content.c_str()), unit);
-  else if (name=="MaxIter")     maxiter_  = atoi(content.c_str());
-  else if (name=="NonAdaptive") adaptive_ = false;
-  else if (name=="Adaptive")    adaptive_ = true;
-  else if (name=="PrimaryOnly") secondary_= false;
-  else if (name=="Integrator") integrator(content);
-  else if (name=="DeltaMin") deltaMin(atof(content.c_str()));
-  else if (name=="DeltaMax") deltaMax(atof(content.c_str()));
-  else if (name=="DeltaMaxOverR") deltaMaxOverR (atof(content.c_str()));
-  else if (name=="AbsTol") absTol(atof(content.c_str()));
-  else if (name=="RelTol") relTol(atof(content.c_str()));
-  else return 1;
+  }
+  else return Object::setParameter(name, content, unit);
   return 0;
 }
 
-void Worldline::integrator(std::string type) {
+void Worldline::integrator(std::string const &type) {
   if (type=="Legacy") state_ = new IntegState::Legacy(this);
 #ifdef HAVE_BOOST
   else state_ = new IntegState::Boost(this, type);
@@ -383,6 +383,27 @@ SmartPointer<Metric::Generic> Worldline::metric() const { return metric_; }
 string Worldline::className() const { return  string("Worldline"); }
 string Worldline::className_l() const { return  string("worldline"); }
 
+void Worldline::initCoord(std::vector<double> const &v) {
+  if (v.size() != 8)
+    throwError("Worldline::initCoord() requires an 8-element vector");
+  double c[8];
+  for (size_t i=0; i<8; ++i) c[i]=v[i];
+  setInitCoord(c);
+}
+
+std::vector<double> Worldline::initCoord() const {
+  std::vector<double> coord(8, 0.);
+  coord[0] = x0_[i0_];
+  coord[1] = x1_[i0_];
+  coord[2] = x2_[i0_];
+  coord[3] = x3_[i0_];
+  coord[4] = x0dot_[i0_];
+  coord[5] = x1dot_[i0_];
+  coord[6] = x2dot_[i0_];
+  coord[7] = x3dot_[i0_];
+  return coord;
+}
+
 void Worldline::setInitCoord(const double coord[8], int dir) {
   GYOTO_DEBUG_ARRAY(coord, 8);
   if (dir==0) dir = getMass() ? 1 : -1;
diff --git a/yorick/gyoto_utils.C b/yorick/gyoto_utils.C
index 8ee10ef..a6674de 100644
--- a/yorick/gyoto_utils.C
+++ b/yorick/gyoto_utils.C
@@ -21,6 +21,11 @@
 #include "GyotoRegister.h"
 #include "GyotoProperty.h"
 #include "GyotoValue.h"
+#include "GyotoObject.h"
+#include "GyotoMetric.h"
+#include "GyotoAstrobj.h"
+#include "GyotoSpectrum.h"
+#include "GyotoSpectrometer.h"
 #include <yapi.h>
 #include <pstdlib.h>
 #include <cstring>
@@ -357,15 +362,35 @@ void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
 		    Gyoto::Property const& p, int iarg,
 		    std::string name, std::string unit) {
   Gyoto::Value val;
+
+  Gyoto::SmartPointee * smptee = (Gyoto::SmartPointee*) ptr();
+  Gyoto::Object * object = dynamic_cast<Gyoto::Object*> (smptee);
+  Gyoto::Astrobj::Generic * ao=NULL;
+
+  if (!smptee) Gyoto::throwError("NULL SmartPointee*");
+
+  // Some Astrobj (in particular Star) inherit twice from Object.
+  if (!object && (ao=dynamic_cast<Gyoto::Astrobj::Generic*> (smptee)) )
+    object = dynamic_cast<Gyoto::Object*> (ao);
+
+  if (!object)
+    Gyoto::throwError("dynamic_cast from SmartPointee* to Object* failed");
+
   if (p.type == Gyoto::Property::double_t)
-    val = ptr->get(p, unit);
+    val = object -> get(p, unit);
   else
-    val = ptr->get(p);
+    val = object -> get(p);
 
   switch(p.type) {
   case Gyoto::Property::bool_t:
     ypush_long(name==p.name?bool(val):!val);
     break;
+  case Gyoto::Property::long_t:
+    ypush_long(long(val));
+    break;
+  case Gyoto::Property::unsigned_long_t:
+    ypush_long(long((unsigned long)(val)));
+    break;
   case Gyoto::Property::double_t:
     ypush_double(val);
     break;
@@ -397,15 +422,35 @@ void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
 		   Gyoto::Property const& p, int iarg, std::string name,
 		   std::string unit) {
   Gyoto::Value val;
+
+  Gyoto::SmartPointee * smptee = (Gyoto::SmartPointee*) ptr();
+  Gyoto::Object * object = dynamic_cast<Gyoto::Object*> (smptee);
+  Gyoto::Astrobj::Generic * ao=NULL;
+
+  if (!smptee) Gyoto::throwError("NULL SmartPointee*");
+
+  // Some Astrobj (in particular Star) inherit twice from Object.
+  if (!object && (ao=dynamic_cast<Gyoto::Astrobj::Generic*> (smptee)) )
+    object = dynamic_cast<Gyoto::Object*> (ao);
+
+  if (!object)
+    Gyoto::throwError("dynamic_cast from SmartPointee* to Object* failed");
+
   switch(p.type) {
   case Gyoto::Property::bool_t:
     {
-      val=ygets_l(iarg);
+      val=bool(ygets_l(iarg));
       if (name != p.name) val = !val;
     }
     break;
+  case Gyoto::Property::long_t:
+    val = long(ygets_l(iarg));
+    break;
+  case Gyoto::Property::unsigned_long_t:
+    val = (unsigned long)(ygets_l(iarg));
+    break;
   case Gyoto::Property::double_t:
-    ptr->set(p, ygets_d(iarg), unit);
+    object->set(p, ygets_d(iarg), unit);
     return;
   case Gyoto::Property::filename_t:
   case Gyoto::Property::string_t:
@@ -429,5 +474,5 @@ void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
   default:
     y_error("Property type unimplemented in yget_property()");
    }
-  ptr->set(p, val);
+  object->set(p, val);
 }
diff --git a/yorick/ygyoto_private.h b/yorick/ygyoto_private.h
index 374eeee..6c9da3f 100644
--- a/yorick/ygyoto_private.h
+++ b/yorick/ygyoto_private.h
@@ -94,7 +94,8 @@ long int __ygyoto_var_idx(long id);
     }									\
     void gyoto_##NAME##_eval(void *obj, int argc);			\
     void gyoto_##NAME##_closure_eval(void *obj, int argc) {		\
-      Property const * prop = ((gyoto_##NAME##_closure*)obj)->smptr	\
+      Property const * prop = \
+	((Gyoto::Object*)((gyoto_##NAME##_closure*)obj)->smptr())	\
 	->property(((gyoto_##NAME##_closure*)obj)->member);		\
 	if (prop) {							\
 	  std::string unit="";						\

-- 
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