[Debian-astro-commits] [gyoto] 179/221: Python: + don't ignore any class (only constructors for abstract classes and some other methods) + work around a swig bug that makes "help(<module>)" fail + expose the Unit and Converters system

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:44 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 3dcf970c10046d2302b90af217f8f3d0ffd4e939
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Wed Jan 7 17:40:19 2015 +0100

    Python:
      + don't ignore any class (only constructors for abstract classes and some other methods)
      + work around a swig bug that makes "help(<module>)" fail
      + expose the Unit and Converters system
---
 include/GyotoAstrobj.h    |  2 +-
 include/GyotoConverters.h |  4 +--
 include/GyotoWorldline.h  |  2 +-
 python/gyoto.i            | 77 ++++++++++++++++++++++++++++++-----------------
 python/gyoto_lorene.i     |  6 ++++
 python/gyoto_std.i        | 21 +++++++++++++
 6 files changed, 81 insertions(+), 31 deletions(-)

diff --git a/include/GyotoAstrobj.h b/include/GyotoAstrobj.h
index 588f7c1..7ca9b2e 100644
--- a/include/GyotoAstrobj.h
+++ b/include/GyotoAstrobj.h
@@ -588,7 +588,7 @@ class Gyoto::Astrobj::Generic
  *
  *  Also see Gyoto::Scenery and Gyoto::Quantity_t.
  */
-class Gyoto::Astrobj::Properties : protected Gyoto::SmartPointee {
+class Gyoto::Astrobj::Properties : public Gyoto::SmartPointee {
   friend class Gyoto::SmartPointer<Gyoto::Astrobj::Properties>;
  public:
   double *intensity; ///< GYOTO_QUANTITY_INTENSITY   : Intensity
diff --git a/include/GyotoConverters.h b/include/GyotoConverters.h
index af13a9a..4462a34 100644
--- a/include/GyotoConverters.h
+++ b/include/GyotoConverters.h
@@ -400,7 +400,7 @@ namespace Gyoto {
 }
 
 #ifdef HAVE_UDUNITS
-class Gyoto::Units::Unit : protected Gyoto::SmartPointee {
+class Gyoto::Units::Unit : public Gyoto::SmartPointee {
   friend class Gyoto::SmartPointer<Gyoto::Units::Unit>;
   friend class Gyoto::Units::Converter;
  private:
@@ -469,7 +469,7 @@ class Gyoto::Units::Unit : protected Gyoto::SmartPointee {
   operator ut_unit*() const ;
 };
 
-class Gyoto::Units::Converter : protected Gyoto::SmartPointee {
+class Gyoto::Units::Converter : public Gyoto::SmartPointee {
   friend class Gyoto::SmartPointer<Gyoto::Units::Converter>;
  private:
   cv_converter * converter_; ///< Underlying ut_converter object from udunits
diff --git a/include/GyotoWorldline.h b/include/GyotoWorldline.h
index 043de1e..bfce881 100644
--- a/include/GyotoWorldline.h
+++ b/include/GyotoWorldline.h
@@ -636,7 +636,7 @@ class Gyoto::Worldline
  * \class Gyoto::Worldline::IntegState::Generic
  * \brief Current state of a geodesic integration
  */
-class Gyoto::Worldline::IntegState::Generic : SmartPointee {
+class Gyoto::Worldline::IntegState::Generic : public SmartPointee {
   friend class Gyoto::SmartPointer<Gyoto::Worldline::IntegState::Generic>;
  protected:
   /// Worldline that we are integrating.
diff --git a/python/gyoto.i b/python/gyoto.i
index fe846d8..9f9eedb 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -118,14 +118,20 @@
 // ref/unref features
 %define GyotoSmPtrClassGeneric(klass)
 %rename(klass) klass ## Ptr;
-%ignore Gyoto::klass::Register_;
-%ignore Gyoto::klass::Register;
-%ignore Gyoto::klass::initRegister;
-%ignore Gyoto::klass::getSubcontractor;
+%rename(klass ## Register) Gyoto::klass::Register_;
+%inline {
+  Gyoto::Register::Entry * get ## klass ## Register() { return Gyoto::klass::Register_; }
+ }
+%rename(register ## klass) Gyoto::klass::Register;
+%rename(init ## klass ## Register) Gyoto::klass::initRegister;
+%rename(get ## klass ## Subcontractor) Gyoto::klass::getSubcontractor;
 %rename(klass) Gyoto::klass::Generic;
 %feature("ref") Gyoto:: klass ::Generic"$this->incRefCount();";
 %feature("unref") Gyoto:: klass ::Generic"$this->decRefCount(); if (!$this->getRefCount()) delete $this;";
+// Need to mark the base classes as "notabstract" to extend them with
+// a down-cast constructor
 %feature("notabstract") Gyoto::klass::Generic;
+// Ignore all the actual constructors are these classes are really abstract
 %ignore  Gyoto::klass::Generic::Generic(Gyoto::klass::Generic const &);
 %ignore  Gyoto::klass::Generic::Generic(const Generic &);
 %ignore  Gyoto::klass::Generic::Generic(const klass::Generic &);
@@ -133,6 +139,7 @@
 %ignore  Gyoto::klass::Generic::Generic(double);
 %ignore  Gyoto::klass::Generic::Generic(kind_t);
 %ignore  Gyoto::klass::Generic::Generic(const std::string);
+// Make a pseudo constructor for down-casting.
 %extend Gyoto::klass::Generic {
   Generic(std::string nm) {
     Gyoto::SmartPointer<Gyoto::klass::Generic> pres=
@@ -192,13 +199,13 @@ GyotoSmPtrClassDerivedHdr(nspace, klass, Gyoto ## klass ## .h)
 #include "GyotoWorldline.h"
 #include "GyotoPhoton.h"
 #include "GyotoScreen.h"
-#include "GyotoStandardAstrobj.h"
-#include "GyotoUniformSphere.h"
 #include "GyotoThinDisk.h"
 #include "GyotoSpectrometer.h"
 #include "GyotoComplexSpectrometer.h"
 #include "GyotoUniformSpectrometer.h"
 #include "GyotoRegister.h"
+#include "GyotoWIP.h"
+#include "GyotoConverters.h"
 using namespace Gyoto;
 
 %}
@@ -217,6 +224,7 @@ GyotoSmPtrTypeMapClassGeneric(Metric);
 GyotoSmPtrTypeMapClassGeneric(Astrobj);
 GyotoSmPtrTypeMapClassGeneric(Spectrum);
 GyotoSmPtrTypeMapClassGeneric(Spectrometer);
+GyotoSmPtrTypeMapClassDerived(Astrobj, ThinDisk);
 
 GyotoSmPtrTypeMapClass(Screen);
 GyotoSmPtrTypeMapClass(Scenery);
@@ -225,6 +233,9 @@ GyotoSmPtrTypeMapClass(Photon);
 GyotoSmPtrTypeMapClassDerived(Spectrometer, Complex);
 GyotoSmPtrTypeMapClassDerived(Spectrometer, Uniform);
 
+GyotoSmPtrTypeMapClassDerived(Units, Unit);
+GyotoSmPtrTypeMapClassDerived(Units, Converter);
+
 // Non-Gyoto typemaps:
 // Handle std::string
 %include "std_string.i";
@@ -261,27 +272,24 @@ GyotoSmPtrTypeMapClassDerived(Spectrometer, Uniform);
 	}
 }
 
+%ignore Gyoto::SmartPointer::operator();
+%rename(assign) Gyoto::SmartPointer::operator=;
+%include "GyotoSmartPointer.h"
+
 // Expose Gyoto::Register::list as gyoto.listRegister
-%ignore Gyoto::Register::Entry;
-%ignore Gyoto::Register::init;
+%rename(RegisterEntry) Gyoto::Register::Entry;
+%rename(initRegister) Gyoto::Register::init;
 %rename(listRegister) Gyoto::Register::list;
 %include GyotoRegister.h
 
-%ignore Gyoto::Functor::Double_constDoubleArray;
-%ignore Gyoto::Functor::Double_Double_const;
+%rename(Functor__Double_constDoubleArray) Gyoto::Functor::Double_constDoubleArray;
+%rename(Functor__Double_Double_const) Gyoto::Functor::Double_Double_const;
 %include "GyotoFunctors.h"
 
-%ignore Gyoto::Hook::Listener;
-%ignore Gyoto::Hook::Teller;
 %include "GyotoHooks.h"
 
-%ignore Gyoto::WIP;
 %include "GyotoWIP.h"
 
-%ignore Gyoto::SmartPointer::operator();
-%rename(assign) Gyoto::SmartPointer::operator=;
-%include "GyotoSmartPointer.h"
-
 %immutable Gyoto::Value::type;
 %rename(assign) Gyoto::Value::operator=;
 %rename(toDouble) Gyoto::Value::operator double;
@@ -300,10 +308,9 @@ GyotoSmPtrTypeMapClassDerived(Spectrometer, Uniform);
 %include "GyotoValue.h"
 %include "GyotoObject.h"
 
-%ignore Gyoto::Worldline::IntegState;
-%ignore Gyoto::Worldline::IntegState::Generic;
-%ignore Gyoto::Worldline::IntegState::Boost;
-%ignore Gyoto::Worldline::IntegState::Legacy;
+%rename(Worldline__IntegState__Generic) Gyoto::Worldline::IntegState::Generic;
+%rename(Worldline__IntegState__Boost) Gyoto::Worldline::IntegState::Boost;
+%rename(Worldline__IntegState__Legacy) Gyoto::Worldline::IntegState::Legacy;
 %include "GyotoWorldline.h"
 
 GyotoSmPtrClass(Screen)
@@ -313,12 +320,7 @@ GyotoSmPtrClass(Photon)
 %rename(increment) Gyoto::Astrobj::Properties::operator++;
 GyotoSmPtrClassGeneric(Astrobj)
 
-%ignore Gyoto::Astrobj::Standard;
-%ignore Gyoto::Astrobj::UniformSphere;
-%ignore Gyoto::Astrobj::ThinDisk;
-%include GyotoStandardAstrobj.h
-%include GyotoUniformSphere.h
-%include GyotoThinDisk.h
+GyotoSmPtrClassDerived(Astrobj, ThinDisk)
 
 %define _PAccessor2(member, setter)
   void setter(double *IN_ARRAY2, size_t DIM1, size_t DIM2) {
@@ -330,6 +332,14 @@ void setter(double *IN_ARRAY3, size_t DIM1, size_t DIM2, size_t DIM3) {
     $self->member = IN_ARRAY3;
   }
 %enddef
+%define _PConverter(member, method)
+  Gyoto::Units::Converter * method() {
+  Gyoto::Units::Converter * res = $self->member;
+    if (!res) Gyoto::throwError(#member " converter not set");
+    res -> incRefCount();
+    return res;
+  }
+%enddef
 %extend Gyoto::Astrobj::Properties{
   _PAccessor2(intensity, Intensity)
   _PAccessor3(binspectrum, BinSpectrum)
@@ -344,6 +354,9 @@ void setter(double *IN_ARRAY3, size_t DIM1, size_t DIM2, size_t DIM3) {
   _PAccessor2(user3, User3)
   _PAccessor2(user4, User4)
   _PAccessor2(user5, User5)
+  _PConverter(binspectrum_converter_, binSpectrumConverter)
+  _PConverter(intensity_converter_, intensityConverter)
+  _PConverter(spectrum_converter_, spectrumConverter)
  };
 
 GyotoSmPtrClassGeneric(Metric)
@@ -523,3 +536,13 @@ enum {
   Property_spectrometer_t=Gyoto::Property::spectrometer_t,
   Property_empty_t=Gyoto::Property::empty_t};
 }
+
+
+%include "GyotoConverters.h"
+
+// Workaround cvar bug in Swig which makes help(gyoto) fail:
+%inline {
+  namespace Gyoto {
+    extern int __class__=0;
+  }
+}
diff --git a/python/gyoto_lorene.i b/python/gyoto_lorene.i
index 19bae3a..845d3a5 100644
--- a/python/gyoto_lorene.i
+++ b/python/gyoto_lorene.i
@@ -27,3 +27,9 @@
 GyotoSmPtrClassDerived(Metric, RotStar3_1)
 GyotoSmPtrClassDerived(Metric, NumericalMetricLorene)
 
+// Workaround cvar bug in Swig which makes help(module) fail:
+%inline {
+  namespace GyotoLorene {
+    extern int __class__=0;
+  }
+}
diff --git a/python/gyoto_std.i b/python/gyoto_std.i
index b00ee88..dfaff73 100644
--- a/python/gyoto_std.i
+++ b/python/gyoto_std.i
@@ -20,6 +20,7 @@
 #include "GyotoKerrKS.h"
 #include "GyotoMinkowski.h"
 // include Astrobj headers
+#include "GyotoStandardAstrobj.h"
 #include "GyotoComplexAstrobj.h"
 #include "GyotoStar.h"
 #include "GyotoStarTrace.h"
@@ -49,6 +50,8 @@ using namespace Gyoto;
 %array_class(double, array_unsigned_long)
 
 // Typemaps to translate SmartPointer to specific classes
+GyotoSmPtrTypeMapClassDerived(Astrobj, Standard)
+GyotoSmPtrTypeMapClassDerived(Astrobj, UniformSphere)
 GyotoSmPtrTypeMapClassDerived(Astrobj, Star)
 GyotoSmPtrTypeMapClassDerived(Astrobj, StarTrace)
 GyotoSmPtrTypeMapClassDerived(Astrobj, FixedStar)
@@ -72,6 +75,18 @@ GyotoSmPtrTypeMapClassDerived(Spectrum, PowerLaw)
 GyotoSmPtrTypeMapClassDerived(Spectrum, BlackBody)
 GyotoSmPtrTypeMapClassDerived(Spectrum, ThermalBremsstrahlung)
 
+
+%ignore Gyoto::Astrobj::Standard::Standard();
+%ignore Gyoto::Astrobj::Standard::Standard(double radmax);
+%ignore Gyoto::Astrobj::Standard::Standard(std::string kind);
+%ignore Gyoto::Astrobj::Standard::Standard(const Standard& );
+GyotoSmPtrClassDerivedPtrHdr(Astrobj, Standard, StandardAstrobj, GyotoStandardAstrobj.h)
+
+%ignore Gyoto::Astrobj::UniformSphere::UniformSphere (std::string kind, SmartPointer<Metric::Generic> gg, double radius);
+%ignore Gyoto::Astrobj::UniformSphere::UniformSphere (std::string kind);
+%ignore Gyoto::Astrobj::UniformSphere::UniformSphere (const UniformSphere& orig);
+GyotoSmPtrClassDerived(Astrobj, UniformSphere)
+
 %extend Gyoto::Astrobj::Complex {
   Gyoto::Astrobj::Generic * __getitem__ (int i) {
     Gyoto::Astrobj::Generic * res = ($self)->operator[](i);
@@ -110,3 +125,9 @@ GyotoSmPtrClassDerivedHdr(Spectrum, PowerLaw, GyotoPowerLawSpectrum.h)
 GyotoSmPtrClassDerivedHdr(Spectrum, BlackBody, GyotoBlackBodySpectrum.h)
 GyotoSmPtrClassDerivedHdr(Spectrum, ThermalBremsstrahlung, GyotoThermalBremsstrahlungSpectrum.h)
 
+// Workaround cvar bug in Swig which makes help(gyoto_std) fail:
+%inline {
+  namespace GyotoStd {
+    extern int __class__=0;
+  }
+}

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