[Debian-astro-commits] [gyoto] 147/221: Yorick: support setting/getting Properties with the eval operator in all object types.

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:41 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 57e2d588adc6dfc0f44be8d28edacd14a2a00be2
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Fri Dec 12 14:48:03 2014 +0100

    Yorick: support setting/getting Properties with the eval operator in all object types.
---
 yorick/gyoto_Scenery.C  | 36 ----------------------------------
 yorick/gyoto_utils.C    |  6 +++++-
 yorick/ygyoto.h         | 52 +++++++++++++++++++++++++++++++++++++++++++++++--
 yorick/ygyoto_private.h |  7 +------
 4 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/yorick/gyoto_Scenery.C b/yorick/gyoto_Scenery.C
index 534f93a..64762d9 100644
--- a/yorick/gyoto_Scenery.C
+++ b/yorick/gyoto_Scenery.C
@@ -50,42 +50,6 @@ extern "C" {
   void gyoto_Scenery_eval(void *obj, int argc) {
     SmartPointer<Scenery> *OBJ_ = &(((gyoto_Scenery*)obj)->smptr);
 
-    { // First look for introspected Properties at the beginning of
-      // the argument list. Only four syntaxes possible for each
-      // property:
-      //   obj, Property=value;
-      //   obj, Property=value, unit="unit";
-      //   obj(Property=);
-      //   obj(Property=, unit="unit");
-
-      long kidx;
-      Property const * prop;
-      std::string pname="", unit="";
-      bool unit_found, prop_pushed=false;
-      ypush_nil(); ++argc;
-      while ( (  argc > 0                 ) &&  
-	      ( (kidx=yarg_key(argc-1)) >=0 ) &&
-	      ( (prop=(*OBJ_)->property(pname=yfind_name(kidx)))) ) {
-	if ( (kidx=yarg_key(argc-3)) >=0 &&
-	     !strcmp(yfind_name(kidx),"unit") ) {
-	  unit=ygets_q(argc-4);
-	  unit_found=true;
-	} else {
-	  unit_found=false;
-	  unit="";
-	}
-	if (yarg_nil(argc-2)) {
-	  if (prop_pushed++) y_error("Can push only one return value");
-	  yarg_drop(1);
-	  ypush_property(*OBJ_, *prop, -1, pname, unit);
-	}
-	else yget_property(*OBJ_, *prop, argc-2, pname, unit);
-	argc -= unit_found?4:2;
-      }
-      if (prop_pushed) return;
-      yarg_drop(1); --argc;
-    }
-
     double * impactcoords = NULL;
     bool precompute = 0;
 
diff --git a/yorick/gyoto_utils.C b/yorick/gyoto_utils.C
index 15beec0..fcd07df 100644
--- a/yorick/gyoto_utils.C
+++ b/yorick/gyoto_utils.C
@@ -320,6 +320,10 @@ extern "C" {
 	                           = &ygyoto_Spectrometer_register;
       YGyotoGlobalSupplier -> ygyoto_Spectrometer_generic_eval
                                    = &ygyoto_Spectrometer_generic_eval;
+
+      // Property ABI
+      YGyotoGlobalSupplier -> yget_property = &yget_property;
+      YGyotoGlobalSupplier -> ypush_property = &ypush_property;
     }
     ypush_long(long(YGyotoGlobalSupplier));
   }
@@ -360,7 +364,7 @@ long int __ygyoto_var_idx(long id) {
 }
 
 void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
-		    Gyoto::Property const& p, int iarg,
+		    Gyoto::Property const& p,
 		    std::string name, std::string unit) {
   Gyoto::Value val;
 
diff --git a/yorick/ygyoto.h b/yorick/ygyoto.h
index 46c500f..2534cb8 100644
--- a/yorick/ygyoto.h
+++ b/yorick/ygyoto.h
@@ -79,6 +79,10 @@ int yarg_Spectrum(int iarg);
 Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>* yget_Spectrometer(int iarg);
 Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>* ypush_Spectrometer();
 int yarg_Spectrometer(int iarg);
+void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+		    Gyoto::Property const&, std::string, std::string);
+void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+		   Gyoto::Property const&, int, std::string, std::string);
 
 /*
   You can register your own on_eval worker. It will be called when a
@@ -250,8 +254,37 @@ void ygyoto_Spectrometer_generic_eval
 #define YGYOTO_WORKER_INIT1(BASE, CLASS, KNAMES, NKW)			\
   int rvset[1]={0}, paUsed[1]={0};					\
   *ypush_##BASE()=*YGYOTO_CAT(OBJ, _);					\
-  Gyoto::SmartPointer<CLASS> *OBJ =				\
-    (Gyoto::SmartPointer<CLASS> *)YGYOTO_CAT(OBJ, _);	\
+  {									\
+  long kidx;								\
+  Gyoto::Property const * prop;						\
+  std::string pname="", unit="";					\
+  bool unit_found, prop_pushed=false;					\
+  ++argc;								\
+  while ( (  argc > 0                 ) &&				\
+	  ( (kidx=yarg_key(argc-1)) >=0 ) &&				\
+	  ( (prop=(*YGYOTO_CAT(OBJ, _))					\
+	     ->property(pname=yfind_name(kidx)))) ) {			\
+    if ( (kidx=yarg_key(argc-3)) >=0 &&					\
+	 !strcmp(yfind_name(kidx),"unit") ) {				\
+      unit=ygets_q(argc-4);						\
+      unit_found=true;							\
+    } else {								\
+      unit_found=false;							\
+      unit="";								\
+    }									\
+    if (yarg_nil(argc-2)) {						\
+      if (prop_pushed++) y_error("Can push only one return value");	\
+      yarg_drop(1);							\
+      ypush_property(*YGYOTO_CAT(OBJ, _), *prop, pname, unit);	\
+    }									\
+    else yget_property(*YGYOTO_CAT(OBJ, _), *prop, argc-2, pname, unit); \
+    argc -= unit_found?4:2;						\
+  }									\
+  if (prop_pushed) ++*rvset;						\
+  --argc;								\
+  }									\
+  Gyoto::SmartPointer<CLASS> *OBJ =					\
+    (Gyoto::SmartPointer<CLASS> *)YGYOTO_CAT(OBJ, _);			\
   static long kglobs[NKW+1];						\
   int kiargs[NKW];							\
   int piargs[]={-1,-1,-1,-1};						\
@@ -459,6 +492,14 @@ void ygyoto_Spectrometer_generic_eval
 
 typedef Gyoto::SmartPointer<Gyoto::Metric::Generic> *ygyoto_yget_Metric_t(int);
 typedef Gyoto::SmartPointer<Gyoto::Metric::Generic> *ygyoto_ypush_Metric_t();
+
+typedef void ygyoto_ypush_property_t
+(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+ Gyoto::Property const&, std::string, std::string);
+typedef void ygyoto_yget_property_t
+(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+ Gyoto::Property const&, int, std::string, std::string);
+
 typedef int yarg_OBJTYPE_t(int);
 typedef void ygyoto_Metric_register_t(char const * const, ygyoto_Metric_eval_worker_t*);
 typedef void ygyoto_Metric_generic_eval_t(Gyoto::SmartPointer<Gyoto::Metric::Generic>*, \
@@ -538,6 +579,9 @@ typedef struct YGyotoSupplier {
   yarg_OBJTYPE_t        *yarg_Spectrometer;
   ygyoto_Spectrometer_register_t *ygyoto_Spectrometer_register;
   ygyoto_Spectrometer_generic_eval_t* ygyoto_Spectrometer_generic_eval;
+  // Properties
+  ygyoto_ypush_property_t *ypush_property;
+  ygyoto_yget_property_t *yget_property;
 } YGyotoSupplier_t;
 
 
@@ -548,6 +592,10 @@ extern YGyotoSupplier_t* YGYOTO_LOCAL_SUPPLIER;
 
 #define yget_Metric(iarg) YGYOTO_LOCAL_SUPPLIER -> yget_Metric(iarg)
 #define ypush_Metric()   YGYOTO_LOCAL_SUPPLIER  -> ypush_Metric()
+#define yget_property(a, b, c, d, e) \
+  YGYOTO_LOCAL_SUPPLIER -> yget_property(a, b, c, d, e)
+#define ypush_property(a, b, c, d)\
+  YGYOTO_LOCAL_SUPPLIER  -> ypush_property(a, b, c, d)
 #define yarg_Metric(iarg) YGYOTO_LOCAL_SUPPLIER -> yarg_Metric(iarg)
 #define ygyoto_Metric_register(kind, on_eval) \
                           YGYOTO_LOCAL_SUPPLIER -> \
diff --git a/yorick/ygyoto_private.h b/yorick/ygyoto_private.h
index 713bb10..183a7d7 100644
--- a/yorick/ygyoto_private.h
+++ b/yorick/ygyoto_private.h
@@ -27,11 +27,6 @@
 
 #include "GyotoSmartPointer.h"
 
-void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
-		    Gyoto::Property const&, int, std::string, std::string);
-void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
-		   Gyoto::Property const&, int, std::string, std::string);
-
 /*
   The following are to declare a new base (such as Metric or Astrobj)
   or independent (such as Photon) class. Seldom used in a Gyoto
@@ -118,7 +113,7 @@ long int __ygyoto_var_idx(long id);
 	  if (yarg_nil(parg)) parg=-1;					\
 	  if (parg==-1)							\
 	    ypush_property(((gyoto_##NAME##_closure*)obj)->smptr,	\
-			   *prop, parg,					\
+			   *prop,					\
 			   ((gyoto_##NAME##_closure*)obj)->member,	\
 			   unit);					\
 	  else	{							\

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