[Debian-astro-commits] [gyoto] 193/221: + Gyoto::Value: make operator bool deal with long_t and unsigned_long_t + Python: make %typemap(in) Gyoto::Value target-language-agnostic
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:46 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 42c4e894b6e7ba2d0c5f0f5a97651edab62eae69
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Wed Jan 14 15:52:58 2015 +0100
+ Gyoto::Value: make operator bool deal with long_t and unsigned_long_t
+ Python: make %typemap(in) Gyoto::Value target-language-agnostic
---
lib/Value.C | 16 +++++++++++++++-
python/gyoto.i | 37 +++++++++++++++----------------------
2 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/lib/Value.C b/lib/Value.C
index 47baa68..ee963b6 100644
--- a/lib/Value.C
+++ b/lib/Value.C
@@ -24,6 +24,7 @@ Value::~Value() {}
Value::Value(long val) : type(Property::long_t), Long(val){}
Value::Value(unsigned long val) : type(Property::unsigned_long_t), ULong(val){}
+Value::Value(bool val) : type(Property::bool_t), Bool(val){}
Value::operator long() const {
switch (type) {
case Property::long_t:
@@ -48,8 +49,21 @@ Value::operator unsigned long() const {
return 0;
}
+Value::operator bool() const {
+ switch (type) {
+ case Property::bool_t:
+ return Bool;
+ case Property::long_t:
+ return bool(Long);
+ case Property::unsigned_long_t:
+ return bool(ULong);
+ default:
+ throwError("This Value does not hold an integer");
+ }
+ return 0;
+}
+
___local_stuff(double, double_t, Double)
-___local_stuff(bool, bool_t, Bool)
___local_stuff(std::string, string_t, String)
___local_stuff(std::vector<double>, vector_double_t, VDouble)
___local_stuff(std::vector<unsigned long>, vector_unsigned_long_t, VULong)
diff --git a/python/gyoto.i b/python/gyoto.i
index fad8fea..4b04480 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -244,8 +244,9 @@ GyotoSmPtrTypeMapClassDerived(Worldline, IntegState);
GyotoSmPtrTypeMapClassDerived(Astrobj, Properties);
// Typemaps for Gyoto::Value:
-// In: cast from Python representations for all the supported types.
-// Implementation is specific to Python.
+
+// In: cast from target language representations for all the supported
+// types.
%typemap(in) Gyoto::Value {
int res=0;
void *argp=0;
@@ -317,38 +318,30 @@ GyotoSmPtrTypeMapClassDerived(Astrobj, Properties);
if (SWIG_IsNewObj(res) && temp) delete temp;
}
- /*
- // This would help in making this language-agnostic, but it become
- // difficult to distinguish the various subtypes (long vs bool vs
- // double):
if (!SWIG_IsOK(res)) {
- bool temp=false;
- res = SWIG_AsVal(bool)($input, &temp)
+ long temp=0;
+ res = SWIG_AsVal(long)($input, &temp);
if (SWIG_IsOK(res)) $1 = Gyoto::Value(temp);
}
- */
-
- if (SWIG_IsOK(res)) ; // done
- else if (PyBool_Check($input)) $1 = Gyoto::Value($input == Py_True);
- else if (PyInt_Check($input)) $1 = Gyoto::Value(long(PyInt_AsLong($input)));
- else if (PyLong_Check($input)) $1 = Gyoto::Value(long(PyLong_AsLong($input)));
- else if (PyFloat_Check($input)) $1 = Gyoto::Value(PyFloat_AsDouble($input));
- else {
- SWIG_exception_fail(SWIG_ArgError(res), "argument of type 'Gyoto::Value*'");
+
+ if (!SWIG_IsOK(res)) {
+ double temp=0;
+ res = SWIG_AsVal(double)($input, &temp);
+ if (SWIG_IsOK(res)) $1 = Gyoto::Value(temp);
}
+
+ if (!SWIG_IsOK(res))
+ SWIG_exception_fail(SWIG_ArgError(res), "argument of type 'Gyoto::Value*'");
+
}
// Typecheck: should be debugged, does not seem to filter anything
%typemap(typecheck) Gyoto::Value {
void *vptr = 0;
int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Gyoto__Value, 0);
$1 = res;
- // $1 = res ||
- // PyInt_Check($input) ||
- // PyLong_Check($input)
- // ;
}
// Out: cast from Gyoto::Value to language-specific representation
-// for each sub-type. Probably language-agnostic.
+// for each sub-type.
%typemap(out) Gyoto::Value {
switch ($1.type) {
case Gyoto::Property::unsigned_long_t:
--
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