[Debian-astro-commits] [gyoto] 168/221: Fix operator[] to return reference in (Astrobj|Spectrometer)::Complex, use it to implemet r/w item access in Python

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:43 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 6c31bc7424062db02573da7b0f4273f95ccb9eaa
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Sun Dec 21 20:37:50 2014 +0100

    Fix operator[] to return reference in (Astrobj|Spectrometer)::Complex, use it to implemet r/w item access in Python
---
 include/GyotoComplexAstrobj.h      |  5 ++---
 include/GyotoComplexSpectrometer.h |  4 ++--
 lib/ComplexAstrobj.C               | 10 +++-------
 lib/ComplexSpectrometer.C          |  4 ++--
 python/gyoto.i                     |  6 ++++++
 python/gyoto_std.i                 |  2 +-
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/include/GyotoComplexAstrobj.h b/include/GyotoComplexAstrobj.h
index 1a29535..e770442 100644
--- a/include/GyotoComplexAstrobj.h
+++ b/include/GyotoComplexAstrobj.h
@@ -117,7 +117,6 @@ class Gyoto::Astrobj::Complex : public Gyoto::Astrobj::Generic {
    */
   void append(Gyoto::SmartPointer<Gyoto::Astrobj::Generic> element);
   ///< Add element at the end of the array.
-  void set(size_t i, Gyoto::SmartPointer<Gyoto::Astrobj::Generic> element);
   void remove(size_t i);
   ///< Remove i-th element from the array.
   size_t getCardinal() const;
@@ -167,9 +166,9 @@ class Gyoto::Astrobj::Complex : public Gyoto::Astrobj::Generic {
    *   cplx[0] = objB;
    * \endcode
    */
-  Gyoto::SmartPointer<Gyoto::Astrobj::Generic> operator[](size_t i) ;
+  Gyoto::SmartPointer<Gyoto::Astrobj::Generic>& operator[](size_t i) ;
   ///< Retrieve i-th element.
-  Gyoto::SmartPointer<Gyoto::Astrobj::Generic> const operator[](size_t i) const;
+  Gyoto::SmartPointer<Gyoto::Astrobj::Generic> const&operator[](size_t i) const;
   ///< Retrieve a const version of the i-th element.
   
 };
diff --git a/include/GyotoComplexSpectrometer.h b/include/GyotoComplexSpectrometer.h
index 3ef231d..41f1a2f 100644
--- a/include/GyotoComplexSpectrometer.h
+++ b/include/GyotoComplexSpectrometer.h
@@ -164,9 +164,9 @@ class Gyoto::Spectrometer::Complex
   cplx[0] = objB;
 \endcode
    */
-  Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> operator[](size_t i) ;
+  Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> & operator[](size_t i) ;
   ///< Retrieve i-th element.
-  Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> const operator[](size_t i) const;
+  Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> const & operator[](size_t i) const;
   ///< Retrieve a const version of the i-th element.
   
   /**
diff --git a/lib/ComplexAstrobj.C b/lib/ComplexAstrobj.C
index 59d2e11..1fa03db 100644
--- a/lib/ComplexAstrobj.C
+++ b/lib/ComplexAstrobj.C
@@ -90,19 +90,15 @@ void Complex::append(SmartPointer<Generic> e)
   if (debug())
     cerr << "DEBUG: out Complex::append(SmartPointer<Generic> e)" << endl;
 }
-void Complex::set(size_t i, SmartPointer<Generic> e) {
-  if (i > cardinal_)
-    throwError("Complex::set(size_t i, SmartPointer<Generic> e): no such element");
-  elements_[i]=e;
-}
-SmartPointer<Generic> Complex::operator[](size_t i)
+
+SmartPointer<Generic>& Complex::operator[](size_t i)
 {
   if (i > cardinal_)
     throwError("Complex::operator[](size_t i): no such element");
   return elements_[i];
 }
 
-SmartPointer<Generic> const Complex::operator[](size_t i) const
+SmartPointer<Generic> const& Complex::operator[](size_t i) const
 {
   if (i > cardinal_)
     throwError("Complex::operator[](size_t i): no such element");
diff --git a/lib/ComplexSpectrometer.C b/lib/ComplexSpectrometer.C
index 9874e81..7c2a4a7 100644
--- a/lib/ComplexSpectrometer.C
+++ b/lib/ComplexSpectrometer.C
@@ -76,14 +76,14 @@ void Complex::append(SmartPointer<Generic> e)
   tell(this);
 }
 
-SmartPointer<Generic> Complex::operator[](size_t i)
+SmartPointer<Generic> & Complex::operator[](size_t i)
 {
   if (i > cardinal_)
     throwError("Complex::operator[](size_t i): no such element");
   return elements_[i];
 }
 
-SmartPointer<Generic> const Complex::operator[](size_t i) const
+SmartPointer<Generic> const & Complex::operator[](size_t i) const
 {
   if (i > cardinal_)
     throwError("Complex::operator[](size_t i): no such element");
diff --git a/python/gyoto.i b/python/gyoto.i
index d7d0e76..07f51f2 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -177,7 +177,13 @@ GyotoSmPtrClassGeneric(Metric)
 GyotoSmPtrClassGeneric(Spectrum)
 GyotoSmPtrClassGeneric(Spectrometer)
 
+%rename(__getitem__) Gyoto::Spectrometer::Complex::operator[];
 GyotoSmPtrClassDerivedPtrHdr(Spectrometer, Complex, ComplexSpectrometer, GyotoComplexSpectrometer.h)
+%extend Gyoto::SmartPointer<Gyoto::Spectrometer::Complex> {
+  void __setitem__(int i, Gyoto::SmartPointer<Gyoto::Spectrometer::Generic> p) {
+    (*$self)->operator[](i)=p;
+  }
+ };
 GyotoSmPtrClassDerivedPtrHdr(Spectrometer, Uniform, UniformSpectrometer, GyotoUniformSpectrometer.h)
 
 %include "GyotoConfig.h"
diff --git a/python/gyoto_std.i b/python/gyoto_std.i
index 7c6ded7..b0af20e 100644
--- a/python/gyoto_std.i
+++ b/python/gyoto_std.i
@@ -48,7 +48,7 @@ GyotoSmPtrClassDerivedPtrHdr(Astrobj, Complex, ComplexAstrobj, GyotoComplexAstro
 
 %extend Gyoto::SmartPointer<Gyoto::Astrobj::Complex> {
   void __setitem__(int i, Gyoto::SmartPointer<Gyoto::Astrobj::Generic> p) {
-    (*$self)->set(i, p);
+    (*$self)->operator[](i)=p;
   }
  };
 

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