[Debian-astro-commits] [gyoto] 156/221: Python: hide base classes, make "Class" a sucontractor for that class

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:42 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 417b5c3e64dea8afac0ff0188b51377b0feec897
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Thu Dec 18 16:58:58 2014 +0100

    Python: hide base classes, make "Class" a sucontractor for that class
---
 lib/Screen.C       |  3 +-
 python/Makefile.in |  2 +-
 python/gyoto.cxx   | 20 ------------
 python/gyoto.i     | 94 +++++++++++++++++++++---------------------------------
 python/setup.py.in |  2 +-
 5 files changed, 41 insertions(+), 80 deletions(-)

diff --git a/lib/Screen.C b/lib/Screen.C
index 5096ed4..4340973 100644
--- a/lib/Screen.C
+++ b/lib/Screen.C
@@ -90,6 +90,7 @@ Screen::Screen() :
     screen2_[ii]=0.;
     screen3_[ii]=0.;
   }
+  std::cerr << "Screen created" << std::endl;
 }
 
 Screen::Screen(const Screen& o) :
@@ -126,7 +127,7 @@ Screen::Screen(const Screen& o) :
 }
 Screen * Screen::clone() const { return new Screen(*this); }
 
-Screen::~Screen(){if (mask_) delete [] mask_;}
+Screen::~Screen(){if (mask_) delete [] mask_; std::cerr << "Screen destroyed" << std::endl;}
 
 std::ostream& Screen::print( std::ostream& o) const {
   o << "distance="    << distance_ << ", " ;
diff --git a/python/Makefile.in b/python/Makefile.in
index 704d736..3fd26b5 100644
--- a/python/Makefile.in
+++ b/python/Makefile.in
@@ -83,7 +83,7 @@ export CC
 
 all: gyoto.py _gyoto$(PYTHON_EXTENSION_SUFFIX)
 
-_gyoto$(PYTHON_EXTENSION_SUFFIX): $(srcdir)/gyoto.cxx gyoto_wrap.cxx
+_gyoto$(PYTHON_EXTENSION_SUFFIX): gyoto_wrap.cxx
 	$(PYTHON) $(srcdir)/setup.py build_ext
 
 gyoto.py gyoto_wrap.cxx: gyoto.i header.py
diff --git a/python/gyoto.cxx b/python/gyoto.cxx
deleted file mode 100644
index 4202e24..0000000
--- a/python/gyoto.cxx
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <Python.h>
-#include <iostream>
-
-#define GYOTO_NO_DEPRECATED
-#include "GyotoConfig.h"
-#include "GyotoFactory.h"
-#include "GyotoMetric.h"
-
-Gyoto::SmartPointer<Gyoto::Metric::Generic> pyGyotoMetric(std::string const&s) {
-  return Gyoto::Metric::getSubcontractor(s.c_str())(NULL);
-}
-Gyoto::SmartPointer<Gyoto::Astrobj::Generic> pyGyotoAstrobj(std::string const&s) {
-  return Gyoto::Astrobj::getSubcontractor(s.c_str())(NULL);
-}
-Gyoto::SmartPointer<Gyoto::Spectrum::Generic> pyGyotoSpectrum(std::string const&s) {
-  return Gyoto::Spectrum::getSubcontractor(s.c_str())(NULL);
-}
-Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> pyGyotoSpectrometer(std::string const&s) {
-  return Gyoto::Spectrometer::getSubcontractor(s.c_str())(NULL);
-}
diff --git a/python/gyoto.i b/python/gyoto.i
index c101ea0..6c50278 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -3,6 +3,35 @@
 %define GYOTO_SWIGIMPORTED
 %enddef
 
+%define GyotoSmPtrClass(klass)
+%ignore Gyoto:: klass ;
+%include Gyoto ## klass ## .h
+%rename(klass) pyGyoto ## klass;
+%inline {
+Gyoto::SmartPointer<Gyoto::klass> pyGyoto ## klass () {
+  return new Gyoto::klass();
+}
+}
+%template(klass ## Ptr) Gyoto::SmartPointer<Gyoto::klass>;
+%enddef
+
+%define GyotoSmPtrClassGeneric(klass)
+%template(klass ## Ptr) Gyoto::SmartPointer<Gyoto::klass::Generic>;
+%rename(klass) klass ## Ptr;
+%ignore Gyoto::klass::Register_;
+%ignore Gyoto::klass::Register;
+%ignore Gyoto::klass::initRegister;
+%ignore Gyoto::klass::getSubcontractor;
+%ignore Gyoto::klass::Generic;
+%include Gyoto ## klass ## .h
+%rename(klass) pyGyoto ## klass;
+%inline {
+Gyoto::SmartPointer<Gyoto::klass::Generic> pyGyoto ## klass (std::string const&s) {
+  return Gyoto::klass::getSubcontractor(s.c_str())(NULL);
+}
+}
+%enddef
+
 %{
 #define SWIG_FILE_WITH_INIT
   //#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -19,10 +48,7 @@
 #include "GyotoPhoton.h"
 #include "GyotoScreen.h"
 using namespace Gyoto;
-Gyoto::SmartPointer<Gyoto::Metric::Generic> pyGyotoMetric(std::string const&);
-Gyoto::SmartPointer<Gyoto::Astrobj::Generic> pyGyotoAstrobj(std::string const&);
-Gyoto::SmartPointer<Gyoto::Spectrum::Generic> pyGyotoSpectrum(std::string const&);
-Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> pyGyotoSpectrometer(std::string const&);
+
 void pyGyotoErrorHandler (const Gyoto::Error e) {
   std::cerr << "GYOTO error: "<<e<<std::endl;
   PyErr_SetString(PyExc_RuntimeError, e);
@@ -31,9 +57,6 @@ void pyGyotoErrorHandler (const Gyoto::Error e) {
 
 %}
 
-
-
-
 %include "std_string.i" 
 %include "std_vector.i"
 %template(vector_double) std::vector<double>;
@@ -50,15 +73,11 @@ void pyGyotoErrorHandler (const Gyoto::Error e) {
   import_array();
  }
 
-%ignore Gyoto::SmartPointee;
 %include "GyotoSmartPointer.h"
 
 %include "GyotoValue.h"
 %include "GyotoObject.h"
 
-%template(ScreenPtr) Gyoto::SmartPointer<Gyoto::Screen>;
-%include "GyotoScreen.h"
-
 %ignore Gyoto::Worldline::IntegState;
 %ignore Gyoto::Worldline::IntegState::Generic;
 %ignore Gyoto::Worldline::IntegState::Boost;
@@ -75,24 +94,17 @@ Gyoto::Worldline * pyGyotoCastToWorldline
 }
 %}
 
-%template(PhotonPtr) Gyoto::SmartPointer<Gyoto::Photon>;
-%include "GyotoPhoton.h"
+GyotoSmPtrClass(Screen)
+GyotoSmPtrClass(Scenery)
+GyotoSmPtrClass(Photon)
+GyotoSmPtrClassGeneric(Astrobj)
 
-%template(AstrobjPtr) Gyoto::SmartPointer<Gyoto::Astrobj::Generic>;
-%ignore Gyoto::Astrobj::Generic;
-%ignore Gyoto::Astrobj::Register_;
-%ignore Gyoto::Astrobj::Register;
-%ignore Gyoto::Astrobj::initRegister;
-%ignore Gyoto::Astrobj::getSubcontractor;
-
-%include "GyotoAstrobj.h"
 
 %define _PAccessor(member, setter)
   void setter(double *IN_ARRAY2, int DIM1, int DIM2) {
     $self->member = IN_ARRAY2;
   }
 %enddef
-
 %extend Gyoto::Astrobj::Properties{
   _PAccessor(intensity, Intensity)
   _PAccessor(binspectrum, BinSpectrum)
@@ -109,38 +121,9 @@ Gyoto::Worldline * pyGyotoCastToWorldline
   _PAccessor(user5, User5)
  };
 
-Gyoto::SmartPointer<Gyoto::Astrobj::Generic> pyGyotoAstrobj(std::string const&);
-
-%template(MetricPtr) Gyoto::SmartPointer<Gyoto::Metric::Generic>;
-%ignore Gyoto::Metric::Generic;
-%ignore Gyoto::Metric::Register_;
-%ignore Gyoto::Metric::Register;
-%ignore Gyoto::Metric::initRegister;
-%ignore Gyoto::Metric::getSubcontractor;
-%include "GyotoMetric.h"
-%rename(Metric) pyGyotoMetric;
-Gyoto::SmartPointer<Gyoto::Metric::Generic> pyGyotoMetric(std::string const&);
-
-%template(SpectrumPtr) Gyoto::SmartPointer<Gyoto::Spectrum::Generic>;
-%ignore Gyoto::Spectrum::Generic;
-%ignore Gyoto::Spectrum::Register_;
-%ignore Gyoto::Spectrum::Register;
-%ignore Gyoto::Spectrum::initRegister;
-%ignore Gyoto::Spectrum::getSubcontractor;
-%include "GyotoSpectrum.h"
-%rename(Spectrum) pyGyotoSpectrum;
-Gyoto::SmartPointer<Gyoto::Spectrum::Generic> pyGyotoSpectrum(std::string const&);
-
-%template(SpectrometerPtr) Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>;
-%ignore Gyoto::Spectrometer::Generic;
-%ignore Gyoto::Spectrometer::Register_;
-%ignore Gyoto::Spectrometer::Register;
-%ignore Gyoto::Spectrometer::initRegister;
-%ignore Gyoto::Spectrometer::getSubcontractor;
-%include "GyotoSpectrometer.h"
-%rename(Spectrometer) pyGyotoSpectrometer;
-Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> pyGyotoSpectrometer(std::string const&);
-
+GyotoSmPtrClassGeneric(Metric)
+GyotoSmPtrClassGeneric(Spectrum)
+GyotoSmPtrClassGeneric(Spectrometer)
 
 %include "GyotoConfig.h"
 %include "GyotoDefs.h"
@@ -280,6 +263,3 @@ public:
   Coord1dSet& operator++();
   double angle() const ;
 };
-
-%template(SceneryPtr) Gyoto::SmartPointer<Gyoto::Scenery>;
-%include "GyotoScenery.h"
diff --git a/python/setup.py.in b/python/setup.py.in
index f2b540b..27651df 100644
--- a/python/setup.py.in
+++ b/python/setup.py.in
@@ -33,7 +33,7 @@ else:
         pass
 
 gyoto_module = Extension('_gyoto',
-                         sources=['gyoto_wrap.cxx', 'gyoto.cxx'],
+                         sources=['gyoto_wrap.cxx'],
                          include_dirs=[numpy_include]
                          )
 

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