[Debian-astro-commits] [gyoto] 167/221: Support getting/setting element in Astrobj::Complex, including 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 e45e108aa696ba959b02af937c660437a179d5b0
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Sun Dec 21 16:23:39 2014 +0100

    Support getting/setting element in Astrobj::Complex, including in python
---
 include/GyotoComplexAstrobj.h | 1 +
 lib/ComplexAstrobj.C          | 6 +++++-
 python/gyoto_std.i            | 9 +++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/GyotoComplexAstrobj.h b/include/GyotoComplexAstrobj.h
index d4d9ef3..1a29535 100644
--- a/include/GyotoComplexAstrobj.h
+++ b/include/GyotoComplexAstrobj.h
@@ -117,6 +117,7 @@ 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;
diff --git a/lib/ComplexAstrobj.C b/lib/ComplexAstrobj.C
index c07b56b..59d2e11 100644
--- a/lib/ComplexAstrobj.C
+++ b/lib/ComplexAstrobj.C
@@ -90,7 +90,11 @@ 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)
 {
   if (i > cardinal_)
diff --git a/python/gyoto_std.i b/python/gyoto_std.i
index c7d1c73..7c6ded7 100644
--- a/python/gyoto_std.i
+++ b/python/gyoto_std.i
@@ -42,8 +42,17 @@
 %array_class(double, array_double)
 %array_class(double, array_unsigned_long)
 
+%rename(__getitem__) Gyoto::Astrobj::Complex::operator[];
 %rename(ComplexAstrobjPtr) ComplexPtr;
 GyotoSmPtrClassDerivedPtrHdr(Astrobj, Complex, ComplexAstrobj, GyotoComplexAstrobj.h)
+
+%extend Gyoto::SmartPointer<Gyoto::Astrobj::Complex> {
+  void __setitem__(int i, Gyoto::SmartPointer<Gyoto::Astrobj::Generic> p) {
+    (*$self)->set(i, p);
+  }
+ };
+
+
 GyotoSmPtrClassDerived(Astrobj, Star)
 GyotoSmPtrClassDerived(Astrobj, StarTrace)
 GyotoSmPtrClassDerived(Astrobj, FixedStar)

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