diff options
42 files changed, 3601 insertions, 4187 deletions
diff --git a/Lib/octave/attribute.i b/Lib/octave/attribute.i index 104e4f436..779716cd2 100644 --- a/Lib/octave/attribute.i +++ b/Lib/octave/attribute.i @@ -1,5 +1 @@ -// -// attribute.i - Attribute support -// - %include <typemaps/attribute.swg> diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i index 44868ccac..93b1a896f 100644 --- a/Lib/octave/boost_shared_ptr.i +++ b/Lib/octave/boost_shared_ptr.i @@ -1,7 +1,3 @@ -// -// boost_shared_ptr.i - Boost shared pointer support -// - %include <shared_ptr.i> // Language specific macro implementing all the customisations for handling the smart pointer @@ -14,32 +10,30 @@ // destructor wrapper customisation %feature("unref") TYPE //"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n" - "(void)arg1; delete smartarg1;" + "(void)arg1; delete smartarg1;" -///// Typemap customisations ///// +// Typemap customisations... -// Plain value -%typemap(in) CONST TYPE(void* argp, int res = 0) { +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } if (!argp) { %argument_nullref("$type", $symname, $argnum); } else { $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - } + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); } } %typemap(out) CONST TYPE { - %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(($1_ltype &) $1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } %typemap(varin) CONST TYPE { - void* argp = 0; + void *argp = 0; int newmem = 0; int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -49,22 +43,20 @@ %argument_nullref("$type", $symname, $argnum); } else { $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - } + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); } } %typemap(varout) CONST TYPE { - %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(($1_ltype &) $1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -// Plain pointer +// plain pointer // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance -%typemap(in) CONST TYPE* (void* argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { +%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -75,13 +67,13 @@ $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); } } -%typemap(out, fragment = "SWIG_null_deleter") CONST TYPE* { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1 SWIG_NO_NULL_DELETER_$owner) : 0; +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE* { - void* argp = 0; +%typemap(varin) CONST TYPE * { + void *argp = 0; int newmem = 0; int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -98,21 +90,19 @@ $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); } } -%typemap(varout, fragment = "SWIG_null_deleter") CONST TYPE* { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1 SWIG_NO_NULL_DELETER_0) : 0; +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -// Plain reference -%typemap(in) CONST TYPE& (void* argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +// plain reference +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { - %argument_nullref("$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -121,22 +111,20 @@ $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); } } -%typemap(out, fragment = "SWIG_null_deleter") CONST TYPE& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1 SWIG_NO_NULL_DELETER_$owner); +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE& { - void* argp = 0; +%typemap(varin) CONST TYPE & { + void *argp = 0; int newmem = 0; int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { %variable_fail(res, "$type", "$name"); } SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - if (!argp) { - %argument_nullref("$type", $symname, $argnum); - } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -145,18 +133,18 @@ $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); } } -%typemap(varout, fragment = "SWIG_null_deleter") CONST TYPE& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (&$1 SWIG_NO_NULL_DELETER_0); +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -// Plain pointer by reference +// plain pointer by reference // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance -%typemap(in) TYPE* CONST& (void* argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -167,65 +155,57 @@ } $1 = &temp; } -%typemap(out, fragment = "SWIG_null_deleter") TYPE * CONST& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (*$1 SWIG_NO_NULL_DELETER_$owner); +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) TYPE* CONST& %{ +%typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" %} -%typemap(varout) TYPE* CONST& %{ +%typemap(varout) TYPE *CONST& %{ #error "varout typemap not implemented" %} -// Shared_ptr by value -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void* argp, int res = 0) { +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (argp) { - $1 = *(%reinterpret_cast(argp, $<ype)); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete %reinterpret_cast(argp, $<ype); + %argument_fail(res, "$type", $symname, $argnum); } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); } %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1) : 0; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { int newmem = 0; - void* argp = 0; + void *argp = 0; int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { %variable_fail(res, "$type", "$name"); } $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete %reinterpret_cast(argp, $<ype); - } + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); } %typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1) : 0; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -// Shared_ptr by reference -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void* argp, int res = 0, $*1_ltype tempshared) { +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { - if (argp) { - tempshared = *%reinterpret_cast(argp, $ltype); - } + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); delete %reinterpret_cast(argp, $ltype); $1 = &tempshared; } else { @@ -233,7 +213,7 @@ } } %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (*$1) : 0; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -244,17 +224,15 @@ #error "varout typemap not implemented" %} -// Shared_ptr by pointer -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void* argp, int res = 0, $*1_ltype tempshared) { +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + %argument_fail(res, "$type", $symname, $argnum); } if (newmem & SWIG_CAST_NEW_MEMORY) { - if (argp) { - tempshared = *%reinterpret_cast(argp, $ltype); - } + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); delete %reinterpret_cast(argp, $ltype); $1 = &tempshared; } else { @@ -262,11 +240,9 @@ } } %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (*$1) : 0; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); - if ($owner) { - delete $1; - } + if ($owner) delete $1; } %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ @@ -276,24 +252,20 @@ #error "varout typemap not implemented" %} -// Shared_ptr by pointer reference -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void* argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (argp) { - tempshared = *%reinterpret_cast(argp, $*ltype); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete %reinterpret_cast(argp, $*ltype); + %argument_fail(res, "$type", $symname, $argnum); } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); temp = &tempshared; $1 = &temp; } %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (**$1) : 0; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -305,30 +277,31 @@ %} // Typecheck typemaps -// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. -%typemap(typecheck, precedence = SWIG_TYPECHECK_POINTER, noblock = 1) - TYPE CONST, - TYPE CONST&, - TYPE CONST*, - TYPE * CONST&, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& -{ +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0); $1 = SWIG_CheckState(res); } -// Various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug -%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE(CLASS::*) %{ + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ #error "typemaps for $1_type not available" %} -%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE(CLASS::*) %{ +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ #error "typemaps for $1_type not available" %} %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; %enddef + diff --git a/Lib/octave/carrays.i b/Lib/octave/carrays.i index 6607b7664..014de37ff 100644 --- a/Lib/octave/carrays.i +++ b/Lib/octave/carrays.i @@ -1,9 +1,5 @@ -// -// carrays.i - Manipulate simple pointers as arrays -// - %define %array_class(TYPE,NAME) -%array_class_wrap(TYPE,NAME,__paren__,__paren_asgn__) + %array_class_wrap(TYPE,NAME,__paren__,__paren_asgn__) %enddef %include <typemaps/carrays.swg> diff --git a/Lib/octave/cdata.i b/Lib/octave/cdata.i index d626b5db0..367965990 100644 --- a/Lib/octave/cdata.i +++ b/Lib/octave/cdata.i @@ -1,5 +1 @@ -// -// cdata.i - Manipulate raw C data as strings -// - %include <typemaps/cdata.swg> diff --git a/Lib/octave/cmalloc.i b/Lib/octave/cmalloc.i index e8b5929b7..248f06b96 100644 --- a/Lib/octave/cmalloc.i +++ b/Lib/octave/cmalloc.i @@ -1,5 +1 @@ -// -// cmalloc.i - Object creation using C malloc() -// - %include <typemaps/cmalloc.swg> diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg new file mode 100644 index 000000000..c399a6a89 --- /dev/null +++ b/Lib/octave/director.swg @@ -0,0 +1,132 @@ +/* ----------------------------------------------------------------------------- + * director.swg + * + * This file contains support for director classes so that D proxy + * methods can be called from C++. + * ----------------------------------------------------------------------------- */ + +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG) + +#include <exception> + +namespace Swig { + + class Director { + octave_swig_type *self; + bool swig_disowned; + + Director(const Director &x); + Director &operator=(const Director &rhs); + public: + + Director(void *vptr):self(0), swig_disowned(false) { + set_rtdir(vptr, this); + } + + ~Director() { + swig_director_destroyed(self, this); + if (swig_disowned) + self->decref(); + } + + void swig_set_self(octave_swig_type *new_self) { + assert(!swig_disowned); + self = new_self; + } + + octave_swig_type *swig_get_self() const { + return self; + } + + void swig_disown() { + if (swig_disowned) + return; + swig_disowned = true; + self->incref(); + } + }; + + struct DirectorTypeMismatchException { + static void raise(const char *msg) { + // ... todo + throw(DirectorTypeMismatchException()); + } + + static void raise(const octave_value &ov, const char *msg) { + // ... todo + raise(msg); + } + }; + + struct DirectorPureVirtualException { + static void raise(const char *msg) { + // ... todo + throw(DirectorPureVirtualException()); + } + + static void raise(const octave_value &ov, const char *msg) { + // ... todo + raise(msg); + } + }; + + SWIGINTERN rtdir_map *get_rtdir_map() { + static swig_module_info *module = 0; + if (!module) + module = SWIG_GetModule(0); + if (!module) + return 0; + if (!module->clientdata) + module->clientdata = new rtdir_map; + return (rtdir_map *) module->clientdata; + } + + SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) { + rtdir_map *rm = get_rtdir_map(); + if (rm) + (*rm)[vptr] = d; + } + + SWIGINTERNINLINE void erase_rtdir(void *vptr) { + rtdir_map *rm = get_rtdir_map(); + if (rm) + (*rm).erase(vptr); + } + + SWIGINTERNINLINE Director *get_rtdir(void *vptr) { + rtdir_map *rm = get_rtdir_map(); + if (!rm) + return 0; + rtdir_map::const_iterator pos = rm->find(vptr); + Director *rtdir = (pos != rm->end())? pos->second : 0; + return rtdir; + } + + SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) { + self->director_destroyed(d); + } + + SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d) { + return d->swig_get_self(); + } + + SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) { + d->swig_set_self(self); + } + +} + +SWIGRUNTIME void swig_acquire_ownership(void *vptr) { + // assert(0); + // ... todo +} + +SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) { + // assert(0); + // ... todo +} + +SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) { + // assert(0); + // ... todo +} diff --git a/Lib/octave/exception.i b/Lib/octave/exception.i index 959bba7dd..bb0b15c9d 100644 --- a/Lib/octave/exception.i +++ b/Lib/octave/exception.i @@ -1,9 +1,6 @@ -// -// exception.i - C++ exception support -// - %include <typemaps/exception.swg> + %insert("runtime") { -%define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; )) + %define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; )) } diff --git a/Lib/octave/factory.i b/Lib/octave/factory.i index 029c81004..46a0a8733 100644 --- a/Lib/octave/factory.i +++ b/Lib/octave/factory.i @@ -1,5 +1 @@ -// -// factory.i - Factory method wrapping -// - %include <typemaps/factory.swg> diff --git a/Lib/octave/implicit.i b/Lib/octave/implicit.i index ceb05b7f7..152c2b056 100644 --- a/Lib/octave/implicit.i +++ b/Lib/octave/implicit.i @@ -1,10 +1,7 @@ -// -// implicit.i - %implicit directive -// - %include <std_common.i> %include <typemaps/implicit.swg> #warning "This file provides the %implicit directive, which is an old and fragile" #warning "way to implement the C++ implicit conversion mechanism." #warning "Try using the more robust '%implicitconv Type;' directive instead." + diff --git a/Lib/octave/octave.swg b/Lib/octave/octave.swg index b25931cfd..872054d88 100644 --- a/Lib/octave/octave.swg +++ b/Lib/octave/octave.swg @@ -1,19 +1,8 @@ -// -// octave.swg - Octave configuration module -// - -// Include standard SWIG macros and fragments %include <typemaps/swigmacros.swg> %include <typemaps/fragments.swg> - -// Include Octave runtime code %include <octruntime.swg> - -// Include Octave typemaps +%include <octuserdir.swg> %include <octtypemaps.swg> - -// Include Octave overloaded operator support %include <octopers.swg> -// Include Octave special user directives -%include <octuserdir.swg> +%define %docstring %feature("docstring") %enddef diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index 320dba127..a3e9ebf77 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -1,83 +1,92 @@ -// -// octcomplex.swg - Octave complex number support -// +/* + Defines the As/From conversors for double/float complex, you need to + provide complex Type, the Name you want to use in the conversors, + the complex Constructor method, and the Real and Imag complex + accesor methods. -// Defines the As/From conversors for double/float complex, you need to -// provide complex Type, the Name you want to use in the conversors, -// the complex Constructor method, and the Real and Imag complex accessor -// methods. See the std_complex.i and ccomplex.i for concrete examples. + See the std_complex.i and ccomplex.i for concrete examples. +*/ -// Common 'from' conversor +/* the common from conversor */ %define %swig_fromcplx_conv(Type, OctConstructor, Real, Imag) -%fragment(SWIG_From_frag(Type), "header") + %fragment(SWIG_From_frag(Type),"header") { - SWIGINTERNINLINE octave_value SWIG_From(Type)(const Type & c) { - return octave_value(OctConstructor(Real(c), Imag(c))); - } + SWIGINTERNINLINE octave_value + SWIG_From(Type)(const Type& c) + { + return octave_value(OctConstructor(Real(c), Imag(c))); + } } %enddef -// Double-precision 'as' conversor +// the double case %define %swig_cplxdbl_conv(Type, Constructor, Real, Imag) -%fragment(SWIG_AsVal_frag(Type), "header", fragment = SWIG_AsVal_frag(double)) + %fragment(SWIG_AsVal_frag(Type),"header", + fragment=SWIG_AsVal_frag(double)) { - SWIGINTERN int SWIG_AsVal(Type)(const octave_value & ov, Type * val) { - if (ov.is_complex_scalar()) { - if (val) { - Complex c(ov.complex_value()); - *val = Constructor(c.real(), c.imag()); - } - return SWIG_OK; - } else { - double d; - int res = SWIG_AddCast(SWIG_AsVal(double)(ov, &d)); - if (SWIG_IsOK(res)) { - if (val) { - *val = Constructor(d, 0.0); - } - return res; + SWIGINTERN int + SWIG_AsVal(Type) (const octave_value& ov, Type* val) + { + if (ov.is_complex_scalar()) { + if (val) { + Complex c(ov.complex_value()); + *val=Constructor(c.real(),c.imag()); + } + return SWIG_OK; + } else { + double d; + int res = SWIG_AddCast(SWIG_AsVal(double)(ov, &d)); + if (SWIG_IsOK(res)) { + if (val) + *val = Constructor(d, 0.0); + return res; + } } + return SWIG_TypeError; } - return SWIG_TypeError; - } } %swig_fromcplx_conv(Type, Complex, Real, Imag); %enddef -// Single-precision 'as' conversor +// the float case %define %swig_cplxflt_conv(Type, Constructor, Real, Imag) -%fragment(SWIG_AsVal_frag(Type), "header", fragment = SWIG_AsVal_frag(float)) -{ - SWIGINTERN int SWIG_AsVal(Type)(const octave_value & ov, Type * val) { - if (ov.is_complex_scalar()) { - if (val) { - Complex c(ov.complex_value()); - double re = c.real(); - double im = c.imag(); - if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) { - if (val) - *val = Constructor(%numeric_cast(re, float), %numeric_cast(im, float)); - return SWIG_OK; - } else { - return SWIG_OverflowError; - } - } - } else { - float d; - int res = SWIG_AddCast(SWIG_AsVal(float)(ov, &d)); - if (SWIG_IsOK(res)) { - if (val) { - *val = Constructor(d, 0.0); - } - return res; + %fragment(SWIG_AsVal_frag(Type),"header", + fragment=SWIG_AsVal_frag(float)) { + SWIGINTERN int + SWIG_AsVal(Type) (const octave_value& ov, Type* val) + { + if (ov.is_complex_scalar()) { + if (val) { + Complex c(ov.complex_value()); + double re = c.real(); + double im = c.imag(); + if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) { + if (val) + *val = Constructor(%numeric_cast(re, float), + %numeric_cast(im, float)); + return SWIG_OK; + } else + return SWIG_OverflowError; + } + } else { + float d; + int res = SWIG_AddCast(SWIG_AsVal(float)(ov, &d)); + if (SWIG_IsOK(res)) { + if (val) + *val = Constructor(d, 0.0); + return res; + } } + return SWIG_TypeError; } - return SWIG_TypeError; - } } %swig_fromcplx_conv(Type, FloatComplex, Real, Imag); %enddef -#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) %swig_cplxflt_conv(Type, Constructor, Real, Imag) -#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) %swig_cplxdbl_conv(Type, Constructor, Real, Imag) +#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \ +%swig_cplxflt_conv(Type, Constructor, Real, Imag) + + +#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \ +%swig_cplxdbl_conv(Type, Constructor, Real, Imag) diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index c6e88f7c8..723256ca0 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -1,20 +1,21 @@ -// -// octcontainer.swg - Octave STL container support -// - -// Octave cell <-> C++ container wrapper -// -// This wrapper, and its iterator, allows a general use (and reuse) of -// the mapping between C++ and Octave, thanks to the C++ templates. -// -// Of course, it needs the C++ compiler to support templates, but -// since we will use this wrapper with the STL containers, that should -// be the case. - -%header %{ +/* ----------------------------------------------------------------------------- + * octcontainer.swg + * + * Octave cell <-> C++ container wrapper + * + * This wrapper, and its iterator, allows a general use (and reuse) of + * the mapping between C++ and Octave, thanks to the C++ templates. + * + * Of course, it needs the C++ compiler to support templates, but + * since we will use this wrapper with the STL containers, that should + * be the case. + * ----------------------------------------------------------------------------- */ + +%{ #include <iostream> %} + #if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS) # if !defined(SWIG_EXPORT_ITERATOR_METHODS) # define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS @@ -23,585 +24,599 @@ %include <octiterators.swg> +// The Octave C++ Wrap + %fragment("<stdexcept>"); %include <std_except.i> -%fragment(SWIG_Traits_frag(octave_value), "header", fragment = "StdTraits") +%fragment(SWIG_Traits_frag(octave_value),"header",fragment="StdTraits") { +namespace swig { + template <> struct traits<octave_value > { + typedef value_category category; + static const char* type_name() { return "octave_value"; } + }; + + template <> struct traits_from<octave_value> { + typedef octave_value value_type; + static octave_value from(const value_type& val) { + return val; + } + }; + + template <> + struct traits_check<octave_value, value_category> { + static bool check(const octave_value&) { + return true; + } + }; + + template <> struct traits_asval<octave_value > { + typedef octave_value value_type; + static int asval(const octave_value& obj, value_type *val) { + if (val) *val = obj; + return SWIG_OK; + } + }; +} +} + +%fragment("OctSequence_Base","header",fragment="<stddef.h>") { +%#include <functional> - namespace swig +namespace std { + template <> + struct less <octave_value>: public binary_function<octave_value, octave_value, bool> { + bool + operator()(const octave_value& v, const octave_value& w) const + { + octave_value res = do_binary_op(octave_value::op_le,v,w); + return res.is_true(); + } + }; +} - template <> - struct traits<octave_value > { - typedef value_category category; - static const char* type_name() { - return "octave_value"; - } - }; +namespace swig { + inline size_t + check_index(ptrdiff_t i, size_t size, bool insert = false) { + if ( i < 0 ) { + if ((size_t) (-i) <= size) + return (size_t) (i + size); + } else if ( (size_t) i < size ) { + return (size_t) i; + } else if (insert && ((size_t) i == size)) { + return size; + } + + throw std::out_of_range("index out of range"); + } - template <> - struct traits_from<octave_value> { - typedef octave_value value_type; - static octave_value from(const value_type& val) { - return val; + inline size_t + slice_index(ptrdiff_t i, size_t size) { + if ( i < 0 ) { + if ((size_t) (-i) <= size) { + return (size_t) (i + size); + } else { + throw std::out_of_range("index out of range"); } - }; + } else { + return ( (size_t) i < size ) ? ((size_t) i) : size; + } + } - template <> - struct traits_check<octave_value, value_category> { - static bool check(const octave_value&) { - return true; - } - }; - - template <> - struct traits_asval<octave_value > { - typedef octave_value value_type; - static int asval(const octave_value& obj, value_type* val) { - if (val) { - *val = obj; - } - return SWIG_OK; - } - }; + template <class Sequence, class Difference> + inline typename Sequence::iterator + getpos(Sequence* self, Difference i) { + typename Sequence::iterator pos = self->begin(); + std::advance(pos, check_index(i,self->size())); + return pos; + } + template <class Sequence, class Difference> + inline typename Sequence::const_iterator + cgetpos(const Sequence* self, Difference i) { + typename Sequence::const_iterator pos = self->begin(); + std::advance(pos, check_index(i,self->size())); + return pos; } + template <class Sequence, class Difference> + inline Sequence* + getslice(const Sequence* self, Difference i, Difference j) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size); + typename Sequence::size_type jj = swig::slice_index(j, size); + + if (jj > ii) { + typename Sequence::const_iterator vb = self->begin(); + typename Sequence::const_iterator ve = self->begin(); + std::advance(vb,ii); + std::advance(ve,jj); + return new Sequence(vb, ve); + } else { + return new Sequence(); + } + } + + template <class Sequence, class Difference, class InputSeq> + inline void + setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, true); + typename Sequence::size_type jj = swig::slice_index(j, size); + if (jj < ii) jj = ii; + size_t ssize = jj - ii; + if (ssize <= v.size()) { + typename Sequence::iterator sb = self->begin(); + typename InputSeq::const_iterator vmid = v.begin(); + std::advance(sb,ii); + std::advance(vmid, jj - ii); + self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end()); + } else { + typename Sequence::iterator sb = self->begin(); + typename Sequence::iterator se = self->begin(); + std::advance(sb,ii); + std::advance(se,jj); + self->erase(sb,se); + self->insert(sb, v.begin(), v.end()); + } + } + + template <class Sequence, class Difference> + inline void + delslice(Sequence* self, Difference i, Difference j) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, true); + typename Sequence::size_type jj = swig::slice_index(j, size); + if (jj > ii) { + typename Sequence::iterator sb = self->begin(); + typename Sequence::iterator se = self->begin(); + std::advance(sb,ii); + std::advance(se,jj); + self->erase(sb,se); + } + } +} } -%fragment("OctSequence_Base", "header", fragment = "<stddef.h>") +%fragment("OctSequence_Cont","header", + fragment="StdTraits", + fragment="OctSequence_Base", + fragment="OctSwigIterator_T") { -%#include <functional> - - namespace std +namespace swig +{ + template <class T> + struct OctSequence_Ref // * octave can't support these, because of how assignment works { - - template <> - struct less <octave_value>: public binary_function<octave_value, octave_value, bool> { - bool - operator()(const octave_value& v, const octave_value& w) const { - octave_value res = do_binary_op(octave_value::op_le, v, w); - return res.is_true(); + OctSequence_Ref(const octave_value& seq, int index) + : _seq(seq), _index(index) + { + } + + operator T () const + { + // swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index); + octave_value item; // * todo + try { + return swig::as<T>(item, true); + } catch (std::exception& e) { + char msg[1024]; + sprintf(msg, "in sequence element %d ", _index); + if (!Octave_Error_Occurred()) { + %type_error(swig::type_name<T>()); + } + SWIG_Octave_AddErrorMsg(msg); + SWIG_Octave_AddErrorMsg(e.what()); + throw; } - }; + } - } + OctSequence_Ref& operator=(const T& v) + { + // OctSequence_SetItem(_seq, _index, swig::from<T>(v)); + // * todo + return *this; + } + + private: + octave_value _seq; + int _index; + }; - namespace swig + template <class T> + struct OctSequence_ArrowProxy { + OctSequence_ArrowProxy(const T& x): m_value(x) {} + const T* operator->() const { return &m_value; } + operator const T*() const { return &m_value; } + T m_value; + }; + + template <class T, class Reference > + struct OctSequence_InputIterator + { + typedef OctSequence_InputIterator<T, Reference > self; - inline size_t check_index(ptrdiff_t i, size_t size, bool insert = false) - { - if (i < 0) { - if ((size_t)(-i) <= size) { - return (size_t)(i + size); - } - } else if ((size_t) i < size) { - return (size_t) i; - } else if (insert && ((size_t) i == size)) { - return size; - } + typedef std::random_access_iterator_tag iterator_category; + typedef Reference reference; + typedef T value_type; + typedef T* pointer; + typedef int difference_type; - throw std::out_of_range("index out of range"); + OctSequence_InputIterator() + { } - inline size_t slice_index(ptrdiff_t i, size_t size) + OctSequence_InputIterator(const octave_value& seq, int index) + : _seq(seq), _index(index) { - if (i < 0) { - if ((size_t)(-i) <= size) { - return (size_t)(i + size); - } else { - throw std::out_of_range("index out of range"); - } - } else { - return ((size_t) i < size) ? ((size_t) i) : size; - } } - template <class Sequence, class Difference> - inline typename Sequence::iterator getpos(Sequence* self, Difference i) + reference operator*() const { - typename Sequence::iterator pos = self->begin(); - std::advance(pos, check_index(i, self->size())); - return pos; + return reference(_seq, _index); } - template <class Sequence, class Difference> - inline typename Sequence::const_iterator cgetpos(const Sequence* self, Difference i) - { - typename Sequence::const_iterator pos = self->begin(); - std::advance(pos, check_index(i, self->size())); - return pos; + OctSequence_ArrowProxy<T> + operator->() const { + return OctSequence_ArrowProxy<T>(operator*()); } - template <class Sequence, class Difference> - inline Sequence* getslice(const Sequence* self, Difference i, Difference j) + bool operator==(const self& ri) const { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj > ii) { - typename Sequence::const_iterator vb = self->begin(); - typename Sequence::const_iterator ve = self->begin(); - std::advance(vb, ii); - std::advance(ve, jj); - return new Sequence(vb, ve); - } else { - return new Sequence(); - } + return (_index == ri._index); } - template <class Sequence, class Difference, class InputSeq> - inline void setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) + bool operator!=(const self& ri) const { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj < ii) { - jj = ii; - } - size_t ssize = jj - ii; - if (ssize <= v.size()) { - typename Sequence::iterator sb = self->begin(); - typename InputSeq::const_iterator vmid = v.begin(); - std::advance(sb, ii); - std::advance(vmid, jj - ii); - self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end()); - } else { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb, ii); - std::advance(se, jj); - self->erase(sb, se); - self->insert(sb, v.begin(), v.end()); - } + return !(operator==(ri)); } - template <class Sequence, class Difference> - inline void delslice(Sequence* self, Difference i, Difference j) + self& operator ++ () { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj > ii) { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb, ii); - std::advance(se, jj); - self->erase(sb, se); - } + ++_index; + return *this; } - } - -} - -%fragment("OctSequence_Cont", "header", fragment = "StdTraits", fragment = "OctSequence_Base", fragment = "OctIterator_T") -{ - - namespace swig - { - - template <class T> - struct OctSequence_Ref { // * octave can't support these, because of how assignment works - - OctSequence_Ref(const octave_value& seq, int index) - : _seq(seq), _index(index) { - } - - operator T() const { - octave_value item; // * todo - try { - return swig::as<T> (item, true); - } catch (std::exception& e) { - char msg[1024]; - sprintf(msg, "in sequence element %d ", _index); - if (!SWIG_Octave_ErrorOccurred()) { - %type_error(swig::type_name<T>()); - } - SWIG_Octave_AddErrorMsg(msg); - SWIG_Octave_AddErrorMsg(e.what()); - throw; - } - } - - OctSequence_Ref& operator= (const T& v) { - // * todo - return *this; - } - - private: - - octave_value _seq; - int _index; - - }; - - template <class T> - struct OctSequence_ArrowProxy { - OctSequence_ArrowProxy(const T& x) : m_value(x) {} - const T* operator->() const { - return &m_value; - } - operator const T* () const { - return &m_value; - } - T m_value; - }; - - template <class T, class Reference > - struct OctSequence_InputIterator { - - typedef OctSequence_InputIterator<T, Reference > self; - typedef std::random_access_iterator_tag iterator_category; - typedef Reference reference; - typedef T value_type; - typedef T* pointer; - typedef int difference_type; - - OctSequence_InputIterator() { - } - - OctSequence_InputIterator(const octave_value& seq, int index) - : _seq(seq), _index(index) { - } - - reference operator*() const { - return reference(_seq, _index); - } - - OctSequence_ArrowProxy<T> - operator->() const { - return OctSequence_ArrowProxy<T> (operator*()); - } - - bool operator== (const self& ri) const { - return (_index == ri._index); - } - - bool operator!= (const self& ri) const { - return !(operator== (ri)); - } - - self& operator ++ () { - ++_index; - return *this; - } - - self& operator -- () { - --_index; - return *this; - } + self& operator -- () + { + --_index; + return *this; + } - self& operator += (difference_type n) { - _index += n; - return *this; - } + self& operator += (difference_type n) + { + _index += n; + return *this; + } - self operator + (difference_type n) const { - return self(_seq, _index + n); - } + self operator +(difference_type n) const + { + return self(_seq, _index + n); + } - self& operator -= (difference_type n) { - _index -= n; - return *this; - } + self& operator -= (difference_type n) + { + _index -= n; + return *this; + } - self operator - (difference_type n) const { - return self(_seq, _index - n); - } + self operator -(difference_type n) const + { + return self(_seq, _index - n); + } - difference_type operator - (const self& ri) const { - return _index - ri._index; - } + difference_type operator - (const self& ri) const + { + return _index - ri._index; + } - bool operator < (const self& ri) const { - return _index < ri._index; - } + bool operator < (const self& ri) const + { + return _index < ri._index; + } - reference - operator[](difference_type n) const { - return reference(_seq, _index + n); - } + reference + operator[](difference_type n) const + { + return reference(_seq, _index + n); + } - private: - octave_value _seq; - difference_type _index; - }; - - template <class T> - struct OctSequence_Cont { - typedef OctSequence_Ref<T> reference; - typedef const OctSequence_Ref<T> const_reference; - typedef T value_type; - typedef T* pointer; - typedef int difference_type; - typedef int size_type; - typedef const pointer const_pointer; - typedef OctSequence_InputIterator<T, reference> iterator; - typedef OctSequence_InputIterator<T, const_reference> const_iterator; - - OctSequence_Cont(const octave_value& seq) : _seq(seq) { - } + private: + octave_value _seq; + difference_type _index; + }; - ~OctSequence_Cont() { - } + template <class T> + struct OctSequence_Cont + { + typedef OctSequence_Ref<T> reference; + typedef const OctSequence_Ref<T> const_reference; + typedef T value_type; + typedef T* pointer; + typedef int difference_type; + typedef int size_type; + typedef const pointer const_pointer; + typedef OctSequence_InputIterator<T, reference> iterator; + typedef OctSequence_InputIterator<T, const_reference> const_iterator; + + OctSequence_Cont(const octave_value& seq) : _seq(seq) + { + // * assert that we have map type etc. + /* + if (!OctSequence_Check(seq)) { + throw std::invalid_argument("a sequence is expected"); + } + _seq = seq; + Py_INCREF(_seq); + */ + } - size_type size() const { - return 0; // * todo - } + ~OctSequence_Cont() + { + } - bool empty() const { - return size() == 0; - } + size_type size() const + { + // return static_cast<size_type>(OctSequence_Size(_seq)); + return 0; // * todo + } - iterator begin() { - return iterator(_seq, 0); - } + bool empty() const + { + return size() == 0; + } - const_iterator begin() const { - return const_iterator(_seq, 0); - } + iterator begin() + { + return iterator(_seq, 0); + } - iterator end() { - return iterator(_seq, size()); - } + const_iterator begin() const + { + return const_iterator(_seq, 0); + } - const_iterator end() const { - return const_iterator(_seq, size()); - } + iterator end() + { + return iterator(_seq, size()); + } - reference operator[](difference_type n) { - return reference(_seq, n); - } + const_iterator end() const + { + return const_iterator(_seq, size()); + } - const_reference operator[](difference_type n) const { - return const_reference(_seq, n); - } + reference operator[](difference_type n) + { + return reference(_seq, n); + } - bool check(bool set_err = true) const { - int s = size(); - for (int i = 0; i < s; ++i) { - octave_value item; // * todo - if (!swig::check<value_type> (item)) { - if (set_err) { - char msg[1024]; - sprintf(msg, "in sequence element %d", i); - SWIG_Error(SWIG_RuntimeError, msg); - } - return false; - } - } - return true; - } + const_reference operator[](difference_type n) const + { + return const_reference(_seq, n); + } - private: - octave_value _seq; - }; + bool check(bool set_err = true) const + { + int s = size(); + for (int i = 0; i < s; ++i) { + // swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, i); + octave_value item; // * todo + if (!swig::check<value_type>(item)) { + if (set_err) { + char msg[1024]; + sprintf(msg, "in sequence element %d", i); + SWIG_Error(SWIG_RuntimeError, msg); + } + return false; + } + } + return true; + } - } + private: + octave_value _seq; + }; } +} %define %swig_sequence_iterator(Sequence...) #if defined(SWIG_EXPORT_ITERATOR_METHODS) + class iterator; + class reverse_iterator; + class const_iterator; + class const_reverse_iterator; + + %typemap(out,noblock=1,fragment="OctSequence_Cont") + iterator, reverse_iterator, const_iterator, const_reverse_iterator { + $result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)), + swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN); + } + %typemap(out,fragment="OctSequence_Cont") + std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> { + octave_value_list tmpc; + tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first), + swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN)); + tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second), + swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN)); + $result = Cell(tmpc); + } -class iterator; -class reverse_iterator; -class const_iterator; -class const_reverse_iterator; - -%typemap(out, noblock = 1, fragment = "OctSequence_Cont") iterator, reverse_iterator, const_iterator, const_reverse_iterator { - $result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1, const $type&)), - swig::OctIterator::descriptor(), SWIG_POINTER_OWN); -} -%typemap(out, fragment = "OctSequence_Cont") std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> { - octave_value_list tmpc; - tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1, const $type&).first), swig::OctIterator::descriptor(), SWIG_POINTER_OWN)); - tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1, const $type&).second), swig::OctIterator::descriptor(), SWIG_POINTER_OWN)); - $result = Cell(tmpc); -} - -%fragment("OctPairBoolOutputIterator", "header", fragment = SWIG_From_frag(bool), fragment = "OctSequence_Cont") {} + %fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="OctSequence_Cont") {} -%typemap(out, fragment = "OctPairBoolOutputIterator") std::pair<iterator, bool>, std::pair<const_iterator, bool> { - octave_value_list tmpc; - tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1, const $type&).first), - swig::OctIterator::descriptor(), SWIG_POINTER_OWN)); - tmpc.append(SWIG_From(bool)(%static_cast($1, const $type&).second)); - $result = Cell(tmpc); -} + %typemap(out,fragment="OctPairBoolOutputIterator") + std::pair<iterator, bool>, std::pair<const_iterator, bool> { + octave_value_list tmpc; + tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first), + swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN)); + tmpc.append(SWIG_From(bool)(%static_cast($1,const $type &).second)); + $result = Cell(tmpc); + } -%typemap(in, noblock = 1, fragment = "OctSequence_Cont") - iterator(swig::OctIterator* iter = 0, int res), - reverse_iterator(swig::OctIterator* iter = 0, int res), - const_iterator(swig::OctIterator* iter = 0, int res), - const_reverse_iterator(swig::OctIterator* iter = 0, int res) -{ - res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctIterator::descriptor(), 0); - if (!SWIG_IsOK(res) || !iter) { - %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); - } else { - swig::OctIterator_T < $type > *iter_t = dynamic_cast < swig::OctIterator_T < $type > * >(iter); - if (iter_t) { - $1 = iter_t->get_current(); - } else { + %typemap(in,noblock=1,fragment="OctSequence_Cont") + iterator(swig::OctSwigIterator *iter = 0, int res), + reverse_iterator(swig::OctSwigIterator *iter = 0, int res), + const_iterator(swig::OctSwigIterator *iter = 0, int res), + const_reverse_iterator(swig::OctSwigIterator *iter = 0, int res) { + res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctSwigIterator::descriptor(), 0); + if (!SWIG_IsOK(res) || !iter) { %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); + } else { + swig::OctSwigIterator_T<$type > *iter_t = dynamic_cast<swig::OctSwigIterator_T<$type > *>(iter); + if (iter_t) { + $1 = iter_t->get_current(); + } else { + %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); + } } } -} -%typecheck(%checkcode(ITERATOR), noblock = 1, fragment = "OctSequence_Cont") iterator, reverse_iterator, const_iterator, const_reverse_iterator { - swig::OctIterator* iter = 0; - int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctIterator::descriptor(), 0); - $1 = (SWIG_IsOK(res) && iter && (dynamic_cast < swig::OctIterator_T < $type > * >(iter) != 0)); -} - -%fragment("OctSequence_Cont"); + %typecheck(%checkcode(ITERATOR),noblock=1,fragment="OctSequence_Cont") + iterator, reverse_iterator, const_iterator, const_reverse_iterator { + swig::OctSwigIterator *iter = 0; + int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctSwigIterator::descriptor(), 0); + $1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::OctSwigIterator_T<$type > *>(iter) != 0)); + } + %fragment("OctSequence_Cont"); #endif //SWIG_EXPORT_ITERATOR_METHODS %enddef -// Octave container methods +// The octave container methods %define %swig_container_methods(Container...) %enddef %define %swig_sequence_methods_common(Sequence...) -%swig_sequence_iterator(%arg(Sequence)) -%swig_container_methods(%arg(Sequence)) - -%fragment("OctSequence_Base"); - -%extend { - - value_type pop() throw(std::out_of_range) { - if (self->size() == 0) { - throw std::out_of_range("pop from empty container"); + %swig_sequence_iterator(%arg(Sequence)) + %swig_container_methods(%arg(Sequence)) + + %fragment("OctSequence_Base"); + + %extend { + value_type pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty container"); + Sequence::value_type x = self->back(); + self->pop_back(); + return x; } - Sequence::value_type x = self->back(); - self->pop_back(); - return x; - } - value_type __paren__(difference_type i) throw(std::out_of_range) { - return * (swig::cgetpos(self, i)); - } + value_type __paren__(difference_type i) throw (std::out_of_range) { + return *(swig::cgetpos(self, i)); + } - void __paren_asgn__(difference_type i, value_type x) throw(std::out_of_range) { - * (swig::getpos(self, i)) = x; - } + void __paren_asgn__(difference_type i, value_type x) throw (std::out_of_range) { + *(swig::getpos(self,i)) = x; + } - void append(value_type x) { - self->push_back(x); + void append(value_type x) { + self->push_back(x); + } } -} %enddef %define %swig_sequence_methods(Sequence...) -%swig_sequence_methods_common(%arg(Sequence)) + %swig_sequence_methods_common(%arg(Sequence)) %enddef %define %swig_sequence_methods_val(Sequence...) -%swig_sequence_methods_common(%arg(Sequence)) + %swig_sequence_methods_common(%arg(Sequence)) %enddef +// // Common fragments +// -%fragment("StdSequenceTraits", "header", fragment = "StdTraits", fragment = "OctSequence_Cont") +%fragment("StdSequenceTraits","header", + fragment="StdTraits", + fragment="OctSequence_Cont") { - - namespace swig - { - - template <class OctSeq, class Seq> - inline void - assign(const OctSeq& octseq, Seq* seq) - { +namespace swig { + template <class OctSeq, class Seq> + inline void + assign(const OctSeq& octseq, Seq* seq) { %#ifdef SWIG_STD_NOASSIGN_STL - typedef typename OctSeq::value_type value_type; - typename OctSeq::const_iterator it = octseq.begin(); - for (; it != octseq.end(); ++it) { - seq->insert(seq->end(), (value_type)(*it)); - } + typedef typename OctSeq::value_type value_type; + typename OctSeq::const_iterator it = octseq.begin(); + for (;it != octseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } %#else - seq->assign(octseq.begin(), octseq.end()); + seq->assign(octseq.begin(), octseq.end()); %#endif - } - - template <class Seq, class T = typename Seq::value_type > - struct traits_asptr_stdseq { - - typedef Seq sequence; - typedef T value_type; - - static int asptr(const octave_value& obj, sequence** seq) { - if (!obj.is_defined() || SWIG_Octave_ValueDeref(obj)) { - sequence* p; - if (SWIG_ConvertPtr(obj, (void**) &p, swig::type_info<sequence>(), 0) == SWIG_OK) { - if (seq) { - *seq = p; - } - return SWIG_OLDOBJ; - } - } else if (obj.is_cell()) { - try { - OctSequence_Cont<value_type> octseq(obj); - if (seq) { - sequence* pseq = new sequence(); - assign(octseq, pseq); - *seq = pseq; - return SWIG_NEWOBJ; - } else { - return octseq.check() ? SWIG_OK : SWIG_ERROR; - } - } catch (std::exception& e) { - if (seq && !error_state) { - error("swig type error: %s", e.what()); - } - return SWIG_ERROR; - } - } - return SWIG_ERROR; - } - }; + } - template <class Seq, class T = typename Seq::value_type > - struct traits_from_stdseq { + template <class Seq, class T = typename Seq::value_type > + struct traits_asptr_stdseq { + typedef Seq sequence; + typedef T value_type; + + static int asptr(const octave_value& obj, sequence **seq) { + if (!obj.is_defined() || Swig::swig_value_deref(obj)) { + sequence *p; + if (SWIG_ConvertPtr(obj,(void**)&p, + swig::type_info<sequence>(),0) == SWIG_OK) { + if (seq) *seq = p; + return SWIG_OLDOBJ; + } + } else if (obj.is_cell()) { + try { + OctSequence_Cont<value_type> octseq(obj); + if (seq) { + sequence *pseq = new sequence(); + assign(octseq, pseq); + *seq = pseq; + return SWIG_NEWOBJ; + } else { + return octseq.check() ? SWIG_OK : SWIG_ERROR; + } + } catch (std::exception& e) { + if (seq&&!error_state) + error("swig type error: %s",e.what()); + return SWIG_ERROR; + } + } + return SWIG_ERROR; + } + }; - typedef Seq sequence; - typedef T value_type; - typedef typename Seq::size_type size_type; - typedef typename sequence::const_iterator const_iterator; + template <class Seq, class T = typename Seq::value_type > + struct traits_from_stdseq { + typedef Seq sequence; + typedef T value_type; + typedef typename Seq::size_type size_type; + typedef typename sequence::const_iterator const_iterator; - static octave_value from(const sequence& seq) { + static octave_value from(const sequence& seq) { #ifdef SWIG_OCTAVE_EXTRA_NATIVE_CONTAINERS - swig_type_info* desc = swig::type_info<sequence>(); - if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN); - } + swig_type_info *desc = swig::type_info<sequence>(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN); + } #endif - size_type size = seq.size(); - if (size <= (size_type) INT_MAX) { - Cell c(size, 1); - int i = 0; - for (const_iterator it = seq.begin(); - it != seq.end(); ++it, ++i) { - c(i) = swig::from<value_type> (*it); - } - return c; - } else { - error("swig overflow error: sequence size not valid in octave"); - return octave_value(); - } - return octave_value(); + size_type size = seq.size(); + if (size <= (size_type)INT_MAX) { + Cell c(size,1); + int i = 0; + for (const_iterator it = seq.begin(); + it != seq.end(); ++it, ++i) { + c(i) = swig::from<value_type>(*it); + } + return c; + } else { + error("swig overflow error: sequence size not valid in octave"); + return octave_value(); } - - }; - - } - + return octave_value(); + } + }; +} } + diff --git a/Lib/octave/octfragments.swg b/Lib/octave/octfragments.swg index 2c81e546c..8b1378917 100644 --- a/Lib/octave/octfragments.swg +++ b/Lib/octave/octfragments.swg @@ -1,20 +1 @@ -// -// octfragments.swg - Octave user fragments -// -// Create a file with this name, 'octfragments.swg', in your working -// directory and add all the %fragments you want to take precedence -// over the default ones defined by SWIG. -// -// For example, if you add: -// -// %fragment(SWIG_AsVal_frag(int),"header") { -// SWIGINTERNINLINE int SWIG_AsVal(int)(octave_value& obj, int *val) { -// <your code here>; -// } -// } -// -// this will replace the code used to retrieve an integer value for all -// the typemaps that need it, including: -// -// int, std::vector<int>, std::list<std::pair<int,int> >, etc. diff --git a/Lib/octave/octiterators.swg b/Lib/octave/octiterators.swg index e4b7f4488..79a20f833 100644 --- a/Lib/octave/octiterators.swg +++ b/Lib/octave/octiterators.swg @@ -1,345 +1,357 @@ -// -// octiterators.swg - Octave STL iterator support -// - -// Users can derive form the OctIterator to implement their -// own iterators. As an example (real one since we use it for STL/STD -// containers), the template OctIterator_T does the -// implementation for generic C++ iterators. +/* ----------------------------------------------------------------------------- + * octiterators.swg + * + * Users can derive form the OctSwigIterator to implemet their + * own iterators. As an example (real one since we use it for STL/STD + * containers), the template OctSwigIterator_T does the + * implementation for generic C++ iterators. + * ----------------------------------------------------------------------------- */ %include <std_common.i> -%fragment("OctIterator", "header", fragment = "<stddef.h>") -{ - - namespace swig - { - - struct OctStopIteration { - }; - - struct OctIterator { - - private: - - octave_value _seq; - - protected: - - OctIterator(octave_value seq) : _seq(seq) { - } - - public: - - virtual ~OctIterator() {} - - virtual octave_value value() const = 0; - - virtual OctIterator* incr(size_t n = 1) = 0; - - virtual OctIterator* decr(size_t n = 1) { - throw OctStopIteration(); - } - - virtual ptrdiff_t distance(const OctIterator& x) const { - throw std::invalid_argument("operation not supported"); - } - - virtual bool equal(const OctIterator& x) const { - throw std::invalid_argument("operation not supported"); - } - - virtual OctIterator* copy() const = 0; - - octave_value next() { - octave_value obj = value(); - incr(); - return obj; - } +%fragment("OctSwigIterator","header",fragment="<stddef.h>") { +namespace swig { + struct stop_iteration { + }; - octave_value previous() { - decr(); - return value(); - } + struct OctSwigIterator { + private: + octave_value _seq; - OctIterator* advance(ptrdiff_t n) { - return (n > 0) ? incr(n) : decr(-n); - } + protected: + OctSwigIterator(octave_value seq) : _seq(seq) + { + } + + public: + virtual ~OctSwigIterator() {} - bool operator== (const OctIterator& x) const { - return equal(x); - } + virtual octave_value value() const = 0; - bool operator!= (const OctIterator& x) const { - return ! operator== (x); - } + virtual OctSwigIterator *incr(size_t n = 1) = 0; - OctIterator* operator++ () { - incr(); - return this; - } + virtual OctSwigIterator *decr(size_t n = 1) + { + throw stop_iteration(); + } - OctIterator* operator-- () { - decr(); - return this; - } + virtual ptrdiff_t distance(const OctSwigIterator &x) const + { + throw std::invalid_argument("operation not supported"); + } - OctIterator* operator+ (ptrdiff_t n) const { - return copy()->advance(n); - } + virtual bool equal (const OctSwigIterator &x) const + { + throw std::invalid_argument("operation not supported"); + } + + virtual OctSwigIterator *copy() const = 0; - OctIterator* operator- (ptrdiff_t n) const { - return copy()->advance(-n); - } + octave_value next() + { + octave_value obj = value(); + incr(); + return obj; + } - ptrdiff_t operator- (const OctIterator& x) const { - return x.distance(*this); - } + octave_value previous() + { + decr(); + return value(); + } - static swig_type_info* descriptor() { - static int init = 0; - static swig_type_info* desc = 0; - if (!init) { - desc = SWIG_TypeQuery("swig::OctIterator *"); - init = 1; - } - return desc; - } + OctSwigIterator *advance(ptrdiff_t n) + { + return (n > 0) ? incr(n) : decr(-n); + } + + bool operator == (const OctSwigIterator& x) const + { + return equal(x); + } + + bool operator != (const OctSwigIterator& x) const + { + return ! operator==(x); + } - }; + OctSwigIterator* operator ++ () { + incr(); + return this; + } - } + OctSwigIterator* operator -- () { + decr(); + return this; + } + + OctSwigIterator* operator + (ptrdiff_t n) const + { + return copy()->advance(n); + } + OctSwigIterator* operator - (ptrdiff_t n) const + { + return copy()->advance(-n); + } + + ptrdiff_t operator - (const OctSwigIterator& x) const + { + return x.distance(*this); + } + + static swig_type_info* descriptor() { + static int init = 0; + static swig_type_info* desc = 0; + if (!init) { + desc = SWIG_TypeQuery("swig::OctSwigIterator *"); + init = 1; + } + return desc; + } + }; +} } -%fragment("OctIterator_T", "header", fragment = "<stddef.h>", fragment = "OctIterator", fragment = "StdTraits", fragment = "StdIteratorTraits") -{ - - namespace swig +%fragment("OctSwigIterator_T","header",fragment="<stddef.h>",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") { +namespace swig { + template<typename OutIterator> + class OctSwigIterator_T : public OctSwigIterator { + public: + typedef OutIterator out_iterator; + typedef typename std::iterator_traits<out_iterator>::value_type value_type; + typedef OctSwigIterator_T<out_iterator> self_type; - template<typename OutIterator> - class OctIterator_T : public OctIterator + OctSwigIterator_T(out_iterator curr, octave_value seq) + : OctSwigIterator(seq), current(curr) { + } - public: - - typedef OutIterator out_iterator; - typedef typename std::iterator_traits<out_iterator>::value_type value_type; - typedef OctIterator_T<out_iterator> self_type; - - OctIterator_T(out_iterator curr, octave_value seq) - : OctIterator(seq), current(curr) { - } - - const out_iterator& get_current() const { - return current; - } - - bool equal(const OctIterator& iter) const { - const self_type* iters = dynamic_cast<const self_type*>(&iter); - if (iters) { - return (current == iters->get_current()); - } else { - throw std::invalid_argument("bad iterator type"); - } - } - - ptrdiff_t distance(const OctIterator& iter) const { - const self_type* iters = dynamic_cast<const self_type*>(&iter); - if (iters) { - return std::distance(current, iters->get_current()); - } else { - throw std::invalid_argument("bad iterator type"); - } - } - - protected: - - out_iterator current; - - }; - - template <class ValueType> - struct OctFromOper { - typedef const ValueType& argument_type; - typedef octave_value result_type; - result_type operator()(argument_type v) const { - return swig::from(v); - } - }; - - template < typename OutIterator, typename ValueType = typename std::iterator_traits<OutIterator>::value_type, typename FromOper = OctFromOper<ValueType> > - class OctIteratorOpen_T : public OctIterator_T<OutIterator> + const out_iterator& get_current() const { + return current; + } - public: - - FromOper from; - typedef OutIterator out_iterator; - typedef ValueType value_type; - typedef OctIterator_T<out_iterator> base; - typedef OctIteratorOpen_T<OutIterator, ValueType, FromOper> self_type; - - OctIteratorOpen_T(out_iterator curr, octave_value seq) - : OctIterator_T<OutIterator> (curr, seq) { - } - - octave_value value() const { - return from(static_cast<const value_type&>(* (base::current))); - } - - OctIterator* copy() const { - return new self_type(*this); - } - - OctIterator* incr(size_t n = 1) { - while (n--) { - ++base::current; - } - return this; - } - - OctIterator* decr(size_t n = 1) { - while (n--) { - --base::current; - } - return this; + + bool equal (const OctSwigIterator &iter) const + { + const self_type *iters = dynamic_cast<const self_type *>(&iter); + if (iters) { + return (current == iters->get_current()); + } else { + throw std::invalid_argument("bad iterator type"); } - - }; - - template < typename OutIterator, typename ValueType = typename std::iterator_traits<OutIterator>::value_type, typename FromOper = OctFromOper<ValueType> > - class OctIteratorClosed_T : public OctIterator_T<OutIterator> + } + + ptrdiff_t distance(const OctSwigIterator &iter) const { - - public: - - FromOper from; - typedef OutIterator out_iterator; - typedef ValueType value_type; - typedef OctIterator_T<out_iterator> base; - typedef OctIteratorClosed_T<OutIterator, ValueType, FromOper> self_type; - - OctIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, octave_value seq) - : OctIterator_T<OutIterator> (curr, seq), begin(first), end(last) { + const self_type *iters = dynamic_cast<const self_type *>(&iter); + if (iters) { + return std::distance(current, iters->get_current()); + } else { + throw std::invalid_argument("bad iterator type"); } + } + + protected: + out_iterator current; + }; + + template <class ValueType> + struct from_oper + { + typedef const ValueType& argument_type; + typedef octave_value result_type; + result_type operator()(argument_type v) const + { + return swig::from(v); + } + }; - octave_value value() const { - if (base::current == end) { - throw OctStopIteration(); - } else { - return from(static_cast<const value_type&>(* (base::current))); - } - } + template<typename OutIterator, + typename ValueType = typename std::iterator_traits<OutIterator>::value_type, + typename FromOper = from_oper<ValueType> > + class OctSwigIteratorOpen_T : public OctSwigIterator_T<OutIterator> + { + public: + FromOper from; + typedef OutIterator out_iterator; + typedef ValueType value_type; + typedef OctSwigIterator_T<out_iterator> base; + typedef OctSwigIteratorOpen_T<OutIterator, ValueType, FromOper> self_type; + + OctSwigIteratorOpen_T(out_iterator curr, octave_value seq) + : OctSwigIterator_T<OutIterator>(curr, seq) + { + } + + octave_value value() const { + return from(static_cast<const value_type&>(*(base::current))); + } + + OctSwigIterator *copy() const + { + return new self_type(*this); + } - OctIterator* copy() const { - return new self_type(*this); + OctSwigIterator *incr(size_t n = 1) + { + while (n--) { + ++base::current; } + return this; + } - OctIterator* incr(size_t n = 1) { - while (n--) { - if (base::current == end) { - throw OctStopIteration(); - } else { - ++base::current; - } - } - return this; + OctSwigIterator *decr(size_t n = 1) + { + while (n--) { + --base::current; } + return this; + } + }; - OctIterator* decr(size_t n = 1) { - while (n--) { - if (base::current == begin) { - throw OctStopIteration(); - } else { - --base::current; - } - } - return this; + template<typename OutIterator, + typename ValueType = typename std::iterator_traits<OutIterator>::value_type, + typename FromOper = from_oper<ValueType> > + class OctSwigIteratorClosed_T : public OctSwigIterator_T<OutIterator> + { + public: + FromOper from; + typedef OutIterator out_iterator; + typedef ValueType value_type; + typedef OctSwigIterator_T<out_iterator> base; + typedef OctSwigIteratorClosed_T<OutIterator, ValueType, FromOper> self_type; + + OctSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, octave_value seq) + : OctSwigIterator_T<OutIterator>(curr, seq), begin(first), end(last) + { + } + + octave_value value() const { + if (base::current == end) { + throw stop_iteration(); + } else { + return from(static_cast<const value_type&>(*(base::current))); } + } + + OctSwigIterator *copy() const + { + return new self_type(*this); + } - private: - - out_iterator begin; - out_iterator end; - - }; - - template<typename OutIter> - inline OctIterator* make_output_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = octave_value()) + OctSwigIterator *incr(size_t n = 1) { - return new OctIteratorClosed_T<OutIter> (current, begin, end, seq); + while (n--) { + if (base::current == end) { + throw stop_iteration(); + } else { + ++base::current; + } + } + return this; } - template<typename OutIter> - inline OctIterator* make_output_iterator(const OutIter& current, octave_value seq = octave_value()) + OctSwigIterator *decr(size_t n = 1) { - return new OctIteratorOpen_T<OutIter> (current, seq); + while (n--) { + if (base::current == begin) { + throw stop_iteration(); + } else { + --base::current; + } + } + return this; } + private: + out_iterator begin; + out_iterator end; + }; + + template<typename OutIter> + inline OctSwigIterator* + make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, octave_value seq = octave_value()) + { + return new OctSwigIteratorClosed_T<OutIter>(current, begin, end, seq); } + template<typename OutIter> + inline OctSwigIterator* + make_output_iterator(const OutIter& current, octave_value seq = octave_value()) + { + return new OctSwigIteratorOpen_T<OutIter>(current, seq); + } +} } -%fragment("OctIterator"); -namespace swig +%fragment("OctSwigIterator"); +namespace swig { - - // Throw a StopIteration exception - %ignore OctStopIteration; - struct OctStopIteration {}; - %typemap(throws) OctStopIteration { - error("OctStopIteration exception"); +// Throw a StopIteration exception + %ignore stop_iteration; + struct stop_iteration {}; + + %typemap(throws) stop_iteration { + error("stop_iteration exception"); SWIG_fail; } - // Mark methods that return new objects - %newobject OctIterator::copy; - %newobject OctIterator::operator+ (ptrdiff_t n) const; - %newobject OctIterator::operator- (ptrdiff_t n) const; - - %catches(swig::OctStopIteration) OctIterator::value() const; - %catches(swig::OctStopIteration) OctIterator::incr(size_t n = 1); - %catches(swig::OctStopIteration) OctIterator::decr(size_t n = 1); - %catches(std::invalid_argument) OctIterator::distance(const OctIterator& x) const; - %catches(std::invalid_argument) OctIterator::equal(const OctIterator& x) const; - %catches(swig::OctStopIteration) OctIterator::next(); - %catches(swig::OctStopIteration) OctIterator::previous(); - %catches(swig::OctStopIteration) OctIterator::advance(ptrdiff_t n); - %catches(swig::OctStopIteration) OctIterator::operator+= (ptrdiff_t n); - %catches(swig::OctStopIteration) OctIterator::operator-= (ptrdiff_t n); - %catches(swig::OctStopIteration) OctIterator::operator+ (ptrdiff_t n) const; - %catches(swig::OctStopIteration) OctIterator::operator- (ptrdiff_t n) const; - - %nodirector OctIterator; - struct OctIterator { +// Mark methods that return new objects + %newobject OctSwigIterator::copy; + %newobject OctSwigIterator::operator + (ptrdiff_t n) const; + %newobject OctSwigIterator::operator - (ptrdiff_t n) const; - protected: + %nodirector OctSwigIterator; - OctIterator(octave_value seq); + %catches(swig::stop_iteration) OctSwigIterator::value() const; + %catches(swig::stop_iteration) OctSwigIterator::incr(size_t n = 1); + %catches(swig::stop_iteration) OctSwigIterator::decr(size_t n = 1); + %catches(std::invalid_argument) OctSwigIterator::distance(const OctSwigIterator &x) const; + %catches(std::invalid_argument) OctSwigIterator::equal (const OctSwigIterator &x) const; + %catches(swig::stop_iteration) OctSwigIterator::next(); + %catches(swig::stop_iteration) OctSwigIterator::previous(); + %catches(swig::stop_iteration) OctSwigIterator::advance(ptrdiff_t n); + %catches(swig::stop_iteration) OctSwigIterator::operator += (ptrdiff_t n); + %catches(swig::stop_iteration) OctSwigIterator::operator -= (ptrdiff_t n); + %catches(swig::stop_iteration) OctSwigIterator::operator + (ptrdiff_t n) const; + %catches(swig::stop_iteration) OctSwigIterator::operator - (ptrdiff_t n) const; + + + struct OctSwigIterator + { + protected: + OctSwigIterator(octave_value seq); public: + virtual ~OctSwigIterator(); - virtual ~OctIterator(); virtual octave_value value() const = 0; - virtual OctIterator* incr(size_t n = 1) = 0; - virtual OctIterator* decr(size_t n = 1); - virtual ptrdiff_t distance(const OctIterator& x) const; - virtual bool equal(const OctIterator& x) const; - virtual OctIterator* copy() const = 0; + + virtual OctSwigIterator *incr(size_t n = 1) = 0; + + virtual OctSwigIterator *decr(size_t n = 1); + + virtual ptrdiff_t distance(const OctSwigIterator &x) const; + + virtual bool equal (const OctSwigIterator &x) const; + + virtual OctSwigIterator *copy() const = 0; + octave_value next(); octave_value previous(); - OctIterator* advance(ptrdiff_t n); - bool operator== (const OctIterator& x) const; - bool operator!= (const OctIterator& x) const; - OctIterator* operator++ (); - OctIterator* operator-- (); - OctIterator* operator+ (ptrdiff_t n) const; - OctIterator* operator- (ptrdiff_t n) const; - ptrdiff_t operator- (const OctIterator& x) const; - + OctSwigIterator *advance(ptrdiff_t n); + + bool operator == (const OctSwigIterator& x) const; + bool operator != (const OctSwigIterator& x) const; + OctSwigIterator* operator ++ (); + OctSwigIterator* operator -- (); + OctSwigIterator* operator + (ptrdiff_t n) const; + OctSwigIterator* operator - (ptrdiff_t n) const; + ptrdiff_t operator - (const OctSwigIterator& x) const; }; - } + diff --git a/Lib/octave/octopers.swg b/Lib/octave/octopers.swg index 86e7df88a..c38e64d8c 100644 --- a/Lib/octave/octopers.swg +++ b/Lib/octave/octopers.swg @@ -1,17 +1,17 @@ -// -// octopers.swg - Octave overloaded operator support -// +/* ------------------------------------------------------------ + * Overloaded operator support + * ------------------------------------------------------------ */ #ifdef __cplusplus -// Operators supported in Octave, and the methods they are routed to: -// +// operators supported in Octave, and the methods they are routed to + // __brace__ a{args} // __brace_asgn__ a{args} = rhs // __paren__ a(args) // __paren_asgn__ a(args) = rhs // __str__ generates string rep -// + // __not__ !a // __uplus__ +a // __uminus__ -a @@ -40,7 +40,8 @@ // __el_and__ a & b // __el_or__ a | b -// Operators supported in C++, and the methods that route to them: +// operators supported in C++, and the methods that route to them + %rename(__add__) *::operator+; %rename(__add__) *::operator+(); %rename(__add__) *::operator+() const; @@ -84,4 +85,4 @@ %ignoreoperator(EQ) operator=; %ignoreoperator(ARROWSTAR) operator->*; -#endif // __cplusplus +#endif /* __cplusplus */ diff --git a/Lib/octave/octprimtypes.swg b/Lib/octave/octprimtypes.swg index 7105bda48..6f43f21b0 100644 --- a/Lib/octave/octprimtypes.swg +++ b/Lib/octave/octprimtypes.swg @@ -1,259 +1,232 @@ -// -// octprimtypes.swg - Octave primitive types -// +/* ------------------------------------------------------------ + * Primitive Types + * ------------------------------------------------------------ */ + // boolean -%fragment(SWIG_From_frag(bool), "header") +%fragment(SWIG_From_frag(bool),"header") { +SWIGINTERNINLINE octave_value + SWIG_From_dec(bool)(bool value) { - SWIGINTERNINLINE octave_value - SWIG_From_dec(bool)(bool value) { - return octave_value(value); - } + return octave_value(value); +} } -%fragment(SWIG_AsVal_frag(bool), "header", - fragment = SWIG_AsVal_frag(long)) +%fragment(SWIG_AsVal_frag(bool),"header", + fragment=SWIG_AsVal_frag(long)) { +SWIGINTERN int +SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val) { - SWIGINTERN int - SWIG_AsVal_dec(bool)(const octave_value & ov, bool * val) { - if (!ov.is_bool_type()) { - return SWIG_ERROR; - } - if (val) { - *val = ov.bool_value(); - } - return SWIG_OK; - } + if (!ov.is_bool_type()) + return SWIG_ERROR; + if (val) + *val = ov.bool_value(); + return SWIG_OK; +} } // long -%fragment(SWIG_From_frag(long), "header") -{ - SWIGINTERNINLINE octave_value SWIG_From_dec(long)(long value) { - return octave_value(value); - } +%fragment(SWIG_From_frag(long),"header") { + SWIGINTERNINLINE octave_value SWIG_From_dec(long) (long value) + { + return octave_value(value); + } } -%fragment(SWIG_AsVal_frag(long), "header") -{ - SWIGINTERN int SWIG_AsVal_dec(long)(const octave_value & ov, long * val) { - if (!ov.is_scalar_type()) { - return SWIG_TypeError; - } - if (ov.is_complex_scalar()) { - return SWIG_TypeError; - } - if (ov.is_double_type() || ov.is_single_type()) { - double v = ov.double_value(); - if (v != floor(v)) { - return SWIG_TypeError; +%fragment(SWIG_AsVal_frag(long),"header") { + SWIGINTERN int SWIG_AsVal_dec(long)(const octave_value& ov, long* val) + { + if (!ov.is_scalar_type()) + return SWIG_TypeError; + if (ov.is_complex_scalar()) + return SWIG_TypeError; + if (ov.is_double_type()||ov.is_single_type()) { + double v=ov.double_value(); + if (v!=floor(v)) + return SWIG_TypeError; } + if (val) + *val = ov.long_value(); + return SWIG_OK; } - if (val) { - *val = ov.long_value(); - } - return SWIG_OK; - } } // unsigned long -%fragment(SWIG_From_frag(unsigned long), "header") -{ - SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long)(unsigned long value) { - return octave_value(value); - } +%fragment(SWIG_From_frag(unsigned long),"header") { + SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long) (unsigned long value) + { + return octave_value(value); + } } -%fragment(SWIG_AsVal_frag(unsigned long), "header") -{ - SWIGINTERN int SWIG_AsVal_dec(unsigned long)(const octave_value & ov, unsigned long * val) { - if (!ov.is_scalar_type()) { - return SWIG_TypeError; - } - if (ov.is_complex_scalar()) { - return SWIG_TypeError; - } - if (ov.is_double_type() || ov.is_single_type()) { - double v = ov.double_value(); - if (v < 0) { - return SWIG_OverflowError; +%fragment(SWIG_AsVal_frag(unsigned long),"header") { + SWIGINTERN int SWIG_AsVal_dec(unsigned long)(const octave_value& ov, unsigned long* val) + { + if (!ov.is_scalar_type()) + return SWIG_TypeError; + if (ov.is_complex_scalar()) + return SWIG_TypeError; + if (ov.is_double_type()||ov.is_single_type()) { + double v=ov.double_value(); + if (v<0) + return SWIG_OverflowError; + if (v!=floor(v)) + return SWIG_TypeError; } - if (v != floor(v)) { - return SWIG_TypeError; - } - } - if (ov.is_int8_type() || ov.is_int16_type() || ov.is_int32_type()) { - long v = ov.long_value(); - if (v < 0) { - return SWIG_OverflowError; + if (ov.is_int8_type()||ov.is_int16_type()|| + ov.is_int32_type()) { + long v=ov.long_value(); + if (v<0) + return SWIG_OverflowError; } - } - if (ov.is_int64_type()) { - long long v = ov.int64_scalar_value().value(); - if (v < 0) { - return SWIG_OverflowError; + if (ov.is_int64_type()) { + long long v=ov.int64_scalar_value().value(); + if (v<0) + return SWIG_OverflowError; } + if (val) + *val = ov.ulong_value(); + return SWIG_OK; } - if (val) { - *val = ov.ulong_value(); - } - return SWIG_OK; - } } // long long -%fragment(SWIG_From_frag(long long), "header") -{ - SWIGINTERNINLINE octave_value SWIG_From_dec(long long)(long long value) { - return octave_int64(value); - } +%fragment(SWIG_From_frag(long long),"header") { + SWIGINTERNINLINE octave_value SWIG_From_dec(long long) (long long value) + { + return octave_int64(value); + } } -%fragment(SWIG_AsVal_frag(long long), "header") -{ - SWIGINTERN int SWIG_AsVal_dec(long long)(const octave_value & ov, long long * val) { - if (!ov.is_scalar_type()) { - return SWIG_TypeError; - } - if (ov.is_complex_scalar()) { - return SWIG_TypeError; - } - if (ov.is_double_type() || ov.is_single_type()) { - double v = ov.double_value(); - if (v != floor(v)) { - return SWIG_TypeError; +%fragment(SWIG_AsVal_frag(long long),"header") { + SWIGINTERN int SWIG_AsVal_dec(long long)(const octave_value& ov, long long* val) + { + if (!ov.is_scalar_type()) + return SWIG_TypeError; + if (ov.is_complex_scalar()) + return SWIG_TypeError; + if (ov.is_double_type()||ov.is_single_type()) { + double v=ov.double_value(); + if (v!=floor(v)) + return SWIG_TypeError; } - } - if (val) { - if (ov.is_int64_type()) { - *val = ov.int64_scalar_value().value(); - } else if (ov.is_uint64_type()) { - *val = ov.uint64_scalar_value().value(); - } else { - *val = ov.long_value(); + if (val) { + if (ov.is_int64_type()) + *val = ov.int64_scalar_value().value(); + else if (ov.is_uint64_type()) + *val = ov.uint64_scalar_value().value(); + else + *val = ov.long_value(); } + return SWIG_OK; } - return SWIG_OK; - } } -%fragment(SWIG_From_frag(unsigned long long), "header") -{ - SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long long)(unsigned long long value) { - return octave_uint64(value); - } +%fragment(SWIG_From_frag(unsigned long long),"header") { + SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long long) (unsigned long long value) + { + return octave_uint64(value); + } } -%fragment(SWIG_AsVal_frag(unsigned long long), "header") -{ - SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(const octave_value & ov, unsigned long long * val) { - if (!ov.is_scalar_type()) { - return SWIG_TypeError; - } - if (ov.is_complex_scalar()) { - return SWIG_TypeError; - } - if (ov.is_double_type() || ov.is_single_type()) { - double v = ov.double_value(); - if (v < 0) { - return SWIG_OverflowError; +%fragment(SWIG_AsVal_frag(unsigned long long),"header") { + SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(const octave_value& ov, unsigned long long* val) + { + if (!ov.is_scalar_type()) + return SWIG_TypeError; + if (ov.is_complex_scalar()) + return SWIG_TypeError; + if (ov.is_double_type()||ov.is_single_type()) { + double v=ov.double_value(); + if (v<0) + return SWIG_OverflowError; + if (v!=floor(v)) + return SWIG_TypeError; } - if (v != floor(v)) { - return SWIG_TypeError; + if (ov.is_int8_type()||ov.is_int16_type()|| + ov.is_int32_type()) { + long v=ov.long_value(); + if (v<0) + return SWIG_OverflowError; } - } - if (ov.is_int8_type() || ov.is_int16_type() || - ov.is_int32_type()) { - long v = ov.long_value(); - if (v < 0) { - return SWIG_OverflowError; - } - } - if (ov.is_int64_type()) { - long long v = ov.int64_scalar_value().value(); - if (v < 0) { - return SWIG_OverflowError; - } - } - if (val) { if (ov.is_int64_type()) { - *val = ov.int64_scalar_value().value(); - } else if (ov.is_uint64_type()) { - *val = ov.uint64_scalar_value().value(); - } else { - *val = ov.long_value(); + long long v=ov.int64_scalar_value().value(); + if (v<0) + return SWIG_OverflowError; + } + if (val) { + if (ov.is_int64_type()) + *val = ov.int64_scalar_value().value(); + else if (ov.is_uint64_type()) + *val = ov.uint64_scalar_value().value(); + else + *val = ov.long_value(); } + return SWIG_OK; } - return SWIG_OK; - } } // double -%fragment(SWIG_From_frag(double), "header") -{ - SWIGINTERNINLINE octave_value SWIG_From_dec(double)(double value) { - return octave_value(value); - } +%fragment(SWIG_From_frag(double),"header") { + SWIGINTERNINLINE octave_value SWIG_From_dec(double) (double value) + { + return octave_value(value); + } } -%fragment(SWIG_AsVal_frag(double), "header") -{ - SWIGINTERN int SWIG_AsVal_dec(double)(const octave_value & ov, double * val) { - if (!ov.is_scalar_type()) { - return SWIG_TypeError; - } - if (ov.is_complex_scalar()) { - return SWIG_TypeError; - } - if (val) { - *val = ov.double_value(); +%fragment(SWIG_AsVal_frag(double),"header") { + SWIGINTERN int SWIG_AsVal_dec(double)(const octave_value& ov, double* val) + { + if (!ov.is_scalar_type()) + return SWIG_TypeError; + if (ov.is_complex_scalar()) + return SWIG_TypeError; + if (val) + *val = ov.double_value(); + return SWIG_OK; } - return SWIG_OK; - } } // const char* (strings) -%fragment("SWIG_AsCharPtrAndSize", "header") +%fragment("SWIG_AsCharPtrAndSize","header") { +SWIGINTERN int +SWIG_AsCharPtrAndSize(octave_value ov, char** cptr, size_t* psize, int *alloc) { - SWIGINTERN int - SWIG_AsCharPtrAndSize(octave_value ov, char** cptr, size_t * psize, int * alloc) { - if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) { - ov = ov.cell_value()(0); - } - if (!ov.is_string()) { - return SWIG_TypeError; - } - - std::string str = ov.string_value(); - size_t len = str.size(); - char* cstr = (char*) str.c_str(); - if (alloc) { - *cptr = %new_copy_array(cstr, len + 1, char); - *alloc = SWIG_NEWOBJ; - } else if (cptr) { - *cptr = cstr; - } - if (psize) { - *psize = len + 1; - } - return SWIG_OK; - } + if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) + ov = ov.cell_value()(0); + if (!ov.is_string()) + return SWIG_TypeError; + + std::string str=ov.string_value(); + size_t len=str.size(); + char* cstr=(char*)str.c_str(); + if (alloc) { + *cptr = %new_copy_array(cstr, len + 1, char); + *alloc = SWIG_NEWOBJ; + } else if (cptr) + *cptr = cstr; + if (psize) + *psize = len + 1; + return SWIG_OK; +} } -%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SWIG_pchar_descriptor") +%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") { +SWIGINTERNINLINE octave_value +SWIG_FromCharPtrAndSize(const char* carray, size_t size) { - SWIGINTERNINLINE octave_value - SWIG_FromCharPtrAndSize(const char * carray, size_t size) { - return std::string(carray, carray + size); - } + return std::string(carray,carray+size); } +} + + diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg new file mode 100644 index 000000000..dc9b6b6e6 --- /dev/null +++ b/Lib/octave/octrun.swg @@ -0,0 +1,1389 @@ + +#include <octave/version.h> + +// Macro for enabling features which require Octave version >= major.minor.patch +#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ + ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + OCTAVE_PATCH_VERSION >= ((major)<<16) + ((minor)<<8) + (patch) ) + +// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 +#if !defined(OCTAVE_MAJOR_VERSION) + +# if !defined(OCTAVE_API_VERSION_NUMBER) + +// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet +// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER +# include <octave/ov.h> +# if defined(octave_ov_h) +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 8 +# define OCTAVE_PATCH_VERSION 0 +# else + +// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed +# define ComplexLU __ignore +# include <octave/CmplxLU.h> +# undef ComplexLU +# if defined(octave_Complex_LU_h) + +// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 1 +# define OCTAVE_PATCH_VERSION 99 + +# else + +// OCTAVE_API_VERSION_NUMBER == 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 2 +# define OCTAVE_PATCH_VERSION 0 + +# endif // defined(octave_Complex_LU_h) + +# endif // defined(octave_ov_h) + +// Correlation between Octave API and version numbers extracted from Octave's +// ChangeLogs; version is the *earliest* released Octave with that API number +# elif OCTAVE_API_VERSION_NUMBER >= 48 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 6 +# define OCTAVE_PATCH_VERSION 0 + +# elif OCTAVE_API_VERSION_NUMBER >= 45 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 4 +# define OCTAVE_PATCH_VERSION 1 + +# elif OCTAVE_API_VERSION_NUMBER >= 42 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 54 + +# elif OCTAVE_API_VERSION_NUMBER >= 41 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 53 + +# elif OCTAVE_API_VERSION_NUMBER >= 40 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 52 + +# elif OCTAVE_API_VERSION_NUMBER >= 39 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 51 + +# else // OCTAVE_API_VERSION_NUMBER == 38 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 50 + +# endif // !defined(OCTAVE_API_VERSION_NUMBER) + +#endif // !defined(OCTAVE_MAJOR_VERSION) + +#if !SWIG_OCTAVE_PREREQ(3,2,0) +#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc) +#else +#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc) +#endif + +SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) { + if (num_args > max_args && !varargs) + error("function %s takes at most %i arguments", func_name, max_args); + else if (num_args < min_args) + error("function %s requires at least %i arguments", func_name, min_args); + else + return true; + return false; +} + +SWIGRUNTIME octave_value_list *SWIG_Octave_AppendOutput(octave_value_list *ovl, const octave_value &ov) { + ovl->append(ov); + return ovl; +} + +SWIGRUNTIME octave_value SWIG_ErrorType(int code) { + switch (code) { + case SWIG_MemoryError: + return "SWIG_MemoryError"; + case SWIG_IOError: + return "SWIG_IOError"; + case SWIG_RuntimeError: + return "SWIG_RuntimeError"; + case SWIG_IndexError: + return "SWIG_IndexError"; + case SWIG_TypeError: + return "SWIG_TypeError"; + case SWIG_DivisionByZero: + return "SWIG_DivisionByZero"; + case SWIG_OverflowError: + return "SWIG_OverflowError"; + case SWIG_SyntaxError: + return "SWIG_SyntaxError"; + case SWIG_ValueError: + return "SWIG_ValueError"; + case SWIG_SystemError: + return "SWIG_SystemError"; + case SWIG_AttributeError: + return "SWIG_AttributeError"; + } + return "SWIG unknown error"; +} + +SWIGRUNTIME octave_value SWIG_Error(int code, const char *msg) { + octave_value type(SWIG_ErrorType(code)); + std::string r = msg; + r += " (" + type.string_value() + ")"; + error(r.c_str()); + return octave_value(r); +} + +#define SWIG_fail goto fail + +#define SWIG_Octave_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, 0) +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, own) +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Octave_NewPointerObj(ptr, type, flags) +#define swig_owntype int + +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Octave_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Octave_NewPackedObj(ptr, sz, type) + +#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0) + +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Octave_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Octave_NewPackedObj(ptr, sz, type) + +#define SWIG_GetModule(clientdata) SWIG_Octave_GetModule(clientdata) +#define SWIG_SetModule(clientdata, pointer) SWIG_Octave_SetModule(clientdata,pointer); +#define SWIG_MODULE_CLIENTDATA_TYPE void* + +#define Octave_Error_Occurred() 0 +#define SWIG_Octave_AddErrorMsg(msg) {;} + +SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata); +SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer); + +// For backward compatibility only +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) 0 + +// Runtime API implementation + +#include <map> +#include <vector> +#include <string> + +typedef octave_value_list(*octave_func) (const octave_value_list &, int); +class octave_swig_type; + +namespace Swig { + +#ifdef SWIG_DIRECTORS + + class Director; + + typedef std::map < void *, Director * > rtdir_map; + SWIGINTERN rtdir_map* get_rtdir_map(); + SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d); + SWIGINTERNINLINE void erase_rtdir(void *vptr); + SWIGINTERNINLINE Director *get_rtdir(void *vptr); + + SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d); + SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d); + SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self); + +#endif + + SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost); + SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov); + SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov); +} + +#ifdef SWIG_DIRECTORS +SWIGRUNTIME void swig_acquire_ownership(void *vptr); +SWIGRUNTIME void swig_acquire_ownership_array(void *vptr); +SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); +#endif + + struct swig_octave_member { + const char *name; + octave_func method; + octave_func get_method; + octave_func set_method; + int flags; // 1 static, 2 global + const char *doc; + bool is_static() const { + return flags &1; + } bool is_global() const { + return flags &2; + } + }; + + struct swig_octave_class { + const char *name; + swig_type_info **type; + int director; + octave_func constructor; + const char *constructor_doc; + octave_func destructor; + const swig_octave_member *members; + const char **base_names; + const swig_type_info **base; + }; + + // octave_swig_type plays the role of both the shadow class and the class + // representation within Octave, since there is no support for classes. + // + // These should really be decoupled, with the class support added to Octave + // and the shadow class given by an m-file script. That would dramatically + // reduce the runtime complexity, and be more in line w/ other modules. + + class octave_swig_type:public octave_base_value { + struct cpp_ptr { + void *ptr; + bool destroyed; + cpp_ptr(void *_ptr):ptr(_ptr), destroyed(false) { + }}; + typedef std::pair < const swig_type_info *, cpp_ptr > type_ptr_pair; + + mutable swig_module_info *module; + + const swig_type_info *construct_type; // type of special type object + std::vector < type_ptr_pair > types; // our c++ base classes + int own; // whether we call c++ destructors when we die + + typedef std::pair < const swig_octave_member *, octave_value > member_value_pair; + typedef std::map < std::string, member_value_pair > member_map; + member_map members; + bool always_static; + + const swig_octave_member *find_member(const swig_type_info *type, const std::string &name) { + if (!type->clientdata) + return 0; + swig_octave_class *c = (swig_octave_class *) type->clientdata; + const swig_octave_member *m; + for (m = c->members; m->name; ++m) + if (m->name == name) + return m; + for (int j = 0; c->base_names[j]; ++j) { + if (!c->base[j]) { + if (!module) + module = SWIG_GetModule(0); + assert(module); + c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); + } + if (!c->base[j]) + return 0; + if ((m = find_member(c->base[j], name))) + return m; + } + return 0; + } + + member_value_pair *find_member(const std::string &name, bool insert_if_not_found) { + member_map::iterator it = members.find(name); + if (it != members.end()) + return &it->second; + const swig_octave_member *m; + for (unsigned int j = 0; j < types.size(); ++j) + if ((m = find_member(types[j].first, name))) + return &members.insert(std::make_pair(name, std::make_pair(m, octave_value()))).first->second; + if (!insert_if_not_found) + return 0; + return &members[name]; + } + + const swig_type_info *find_base(const std::string &name, const swig_type_info *base) { + if (!base) { + for (unsigned int j = 0; j < types.size(); ++j) { + assert(types[j].first->clientdata); + swig_octave_class *cj = (swig_octave_class *) types[j].first->clientdata; + if (cj->name == name) + return types[j].first; + } + return 0; + } + assert(base->clientdata); + swig_octave_class *c = (swig_octave_class *) base->clientdata; + for (int j = 0; c->base_names[j]; ++j) { + if (!c->base[j]) { + if (!module) + module = SWIG_GetModule(0); + assert(module); + c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); + } + if (!c->base[j]) + return 0; + assert(c->base[j]->clientdata); + swig_octave_class *cj = (swig_octave_class *) c->base[j]->clientdata; + if (cj->name == name) + return c->base[j]; + } + return 0; + } + + void load_members(const swig_octave_class* c,member_map& out) const { + for (const swig_octave_member *m = c->members; m->name; ++m) { + if (out.find(m->name) == out.end()) + out.insert(std::make_pair(m->name, std::make_pair(m, octave_value()))); + } + for (int j = 0; c->base_names[j]; ++j) { + if (!c->base[j]) { + if (!module) + module = SWIG_GetModule(0); + assert(module); + c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); + } + if (!c->base[j]) + continue; + assert(c->base[j]->clientdata); + const swig_octave_class *cj = + (const swig_octave_class *) c->base[j]->clientdata; + load_members(cj,out); + } + } + + void load_members(member_map& out) const { + out=members; + for (unsigned int j = 0; j < types.size(); ++j) + if (types[j].first->clientdata) + load_members((const swig_octave_class *) types[j].first->clientdata, out); + } + + octave_value_list member_invoke(member_value_pair *m, const octave_value_list &args, int nargout) { + if (m->second.is_defined()) + return m->second.subsref("(", std::list < octave_value_list > (1, args), nargout); + else if (m->first && m->first->method) + return m->first->method(args, nargout); + error("member not defined or not invocable"); + return octave_value_list(); + } + + bool dispatch_unary_op(const std::string &symbol, octave_value &ret) { + member_value_pair *m = find_member(symbol, false); + if (!m || m->first->is_static() || m->first->is_global()) + return false; + octave_value_list args; + args.append(as_value()); + octave_value_list argout(member_invoke(m, args, 1)); + if (argout.length() < 1) + return false; + ret = argout(0); + return true; + } + + bool dispatch_binary_op(const std::string &symbol, const octave_base_value &rhs, octave_value &ret) { + member_value_pair *m = find_member(symbol, false); + if (!m || m->first->is_static() || m->first->is_global()) + return false; + octave_value_list args; + args.append(as_value()); + args.append(make_value_hack(rhs)); + octave_value_list argout(member_invoke(m, args, 1)); + if (argout.length() < 1) + return false; + ret = argout(0); + return true; + } + + bool dispatch_index_op(const std::string &symbol, const octave_value_list &rhs, octave_value_list &ret) { + member_value_pair *m = find_member(symbol, false); + if (!m || m->first->is_static() || m->first->is_global()) + return false; + octave_value_list args; + args.append(as_value()); + args.append(rhs); + octave_value_list argout(member_invoke(m, args, 1)); + if (argout.length() >= 1) + ret = argout(0); + return true; + } + + octave_value_list member_deref(member_value_pair *m, const octave_value_list &args) { + if (m->second.is_defined()) + return m->second; + else if (m->first) { + if (m->first->get_method) + return m->first->get_method(args, 1); + else if (m->first->method) + return octave_value(new octave_builtin(m->first->method)); + } + error("undefined member"); + return octave_value_list(); + } + + static octave_value make_value_hack(const octave_base_value &x) { + ((octave_swig_type &) x).count++; + return octave_value((octave_base_value *) &x); + } + + octave_swig_type(const octave_swig_type &x); + octave_swig_type &operator=(const octave_swig_type &rhs); + public: + + octave_swig_type(void *_ptr = 0, const swig_type_info *_type = 0, int _own = 0, + bool _always_static = false) + : module(0), construct_type(_ptr ? 0 : _type), own(_own), + always_static(_always_static) { + if (_type || _ptr) + types.push_back(std::make_pair(_type, _ptr)); +#ifdef SWIG_DIRECTORS + if (_ptr) { + Swig::Director *d = Swig::get_rtdir(_ptr); + if (d) + Swig::swig_director_set_self(d, this); + } +#endif + } + + ~octave_swig_type() { + if (own) { + ++count; + for (unsigned int j = 0; j < types.size(); ++j) { + if (!types[j].first || !types[j].first->clientdata) + continue; + swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata; + if (c->destructor && !types[j].second.destroyed && types[j].second.ptr) { + c->destructor(as_value(), 0); + } + } + } +#ifdef SWIG_DIRECTORS + for (unsigned int j = 0; j < types.size(); ++j) + Swig::erase_rtdir(types[j].second.ptr); +#endif + } + + dim_vector dims(void) const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + + // Find the __dims__ method of this object + member_value_pair *m = nc_this->find_member("__dims__", false); + + if (!m) return dim_vector(1,1); + + // Call the __dims__ method of this object + octave_value_list inarg; + inarg.append(nc_this->as_value()); + octave_value_list outarg = nc_this->member_invoke(m, inarg, 1); + + // __dims__ should return (at least) one output argument + if (outarg.length() < 1) return dim_vector(1,1); + + octave_value & out = outarg(0); + + // Return value should be cell or matrix of integers + if (out.is_cell()) { + const Cell & c=out.cell_value(); + int ndim = c.rows(); + if (ndim==1 && c.columns()!=1) ndim = c.columns(); + + dim_vector d; + d.resize(ndim < 2 ? 2 : ndim); + d(0) = d(1) = 1; + + // Fill in dim_vector + for (int k=0;k<ndim;k++) { + const octave_value& obj = c(k); + d.elem(k) = obj.int_value(); + + // __dims__ should return a cell filled with integers + if (error_state) return dim_vector(1,1); + } + return d; + } else if (out.is_matrix_type() || out.is_numeric_type() ) { + if (out.rows()==1 || out.columns()==1) { + Array<int> a = out.int_vector_value(); + if (error_state) return dim_vector(1,1); + dim_vector d; + d.resize(a.numel() < 2 ? 2 : a.numel()); + d(0) = d(1) = 1; + for (int k=0;k<a.numel();k++) { + d.elem(k) = a(k); + } + return d; + } else { + return dim_vector(1,1); + } + } else { + return dim_vector(1,1); + } + } + + octave_value as_value() { + ++count; + return Swig::swig_value_ref(this); + } + + void incref() { + ++count; + } + + void decref() { + if (!--count) + delete this; + } + + long swig_this() const { + if (!types.size()) + return (long) this; + return (long) types[0].second.ptr; + } + const char* help_text() const { + if (!types.size()) + return 0; + if (!types[0].first->clientdata) + return 0; + swig_octave_class *c = (swig_octave_class *) types[0].first->clientdata; + return c->constructor_doc; + } + + std::string swig_type_name() const { + // * need some way to manually name subclasses. + // * eg optional first arg to subclass(), or named_subclass() + std::string ret; + for (unsigned int j = 0; j < types.size(); ++j) { + if (j) + ret += "_"; + if (types[j].first->clientdata) { + swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata; + ret += c->name; + } else + ret += types[j].first->name; + } + return ret; + } + + void merge(octave_swig_type &rhs) { + rhs.own = 0; + for (unsigned int j = 0; j < rhs.types.size(); ++j) { + assert(!rhs.types[j].second.destroyed); +#ifdef SWIG_DIRECTORS + Swig::Director *d = Swig::get_rtdir(rhs.types[j].second.ptr); + if (d) + Swig::swig_director_set_self(d, this); +#endif + } + types.insert(types.end(), rhs.types.begin(), rhs.types.end()); + members.insert(rhs.members.begin(), rhs.members.end()); + rhs.types.clear(); + rhs.members.clear(); + } + + typedef member_map::const_iterator swig_member_const_iterator; + swig_member_const_iterator swig_members_begin() { return members.begin(); } + swig_member_const_iterator swig_members_end() { return members.end(); } + + void *cast(swig_type_info *type, int *_own, int flags) { + if (_own) + *_own = own; + if (flags &SWIG_POINTER_DISOWN) + own = 0; + if (!type && types.size()) + return types[0].second.ptr; + for (unsigned int j = 0; j < types.size(); ++j) + if (type == types[j].first) + return types[j].second.ptr; + for (unsigned int j = 0; j < types.size(); ++j) { + swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type); + if (!tc) + continue; + int newmemory = 0; + void *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); + assert(!newmemory); // newmemory handling not yet implemented + return vptr; + } + return 0; + } + + bool is_owned() const { + return own; + } + +#ifdef SWIG_DIRECTORS + void director_destroyed(Swig::Director *d) { + bool found = false; + for (unsigned int j = 0; j < types.size(); ++j) { + Swig::Director *dj = Swig::get_rtdir(types[j].second.ptr); + if (dj == d) { + types[j].second.destroyed = true; + found = true; + } + } + assert(found); + } +#endif + + void assign(const std::string &name, const octave_value &ov) { + members[name] = std::make_pair((const swig_octave_member *) 0, ov); + } + + void assign(const std::string &name, const swig_octave_member *m) { + members[name] = std::make_pair(m, octave_value()); + } + + octave_base_value *clone() const { + // pass-by-value is probably not desired, and is harder; + // requires calling copy constructors of contained types etc. + assert(0); + *(int *) 0 = 0; + return 0; + } + + octave_base_value *empty_clone() const { + return new octave_swig_type(); + } + + bool is_defined() const { + return true; + } + + virtual bool is_map() const { + return true; + } + + virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) { + octave_value_list ovl = subsref(ops, idx, 1); + return ovl.length()? ovl(0) : octave_value(); + } + + virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) { + assert(ops.size() > 0); + assert(ops.size() == idx.size()); + + std::list < octave_value_list >::const_iterator idx_it = idx.begin(); + int skip = 0; + octave_value_list sub_ovl; + + // constructor invocation + if (ops[skip] == '(' && construct_type) { + assert(construct_type->clientdata); + swig_octave_class *c = (swig_octave_class *) construct_type->clientdata; + if (!c->constructor) { + error("cannot create instance"); + return octave_value_list(); + } + octave_value_list args; + if (c->director) + args.append(Swig::swig_value_ref(new octave_swig_type(this, 0, 0))); + args.append(*idx_it++); + ++skip; + sub_ovl = c->constructor(args, nargout); + } + // member dereference or invocation + else if (ops[skip] == '.') { + std::string subname; + const swig_type_info *base = 0; // eg, a.base.base_cpp_mem + for (;;) { + octave_value_list subname_ovl(*idx_it++); + ++skip; + assert(subname_ovl.length() == 1 && subname_ovl(0).is_string()); + subname = subname_ovl(0).string_value(); + + const swig_type_info *next_base = find_base(subname, base); + if (!next_base || skip >= (int) ops.size() || ops[skip] != '.') + break; + base = next_base; + } + + member_value_pair tmp, *m = &tmp; + if (!base || !(m->first = find_member(base, subname))) + m = find_member(subname, false); + if (!m) { + error("member not found"); + return octave_value_list(); + } + + octave_value_list args; + if (!always_static && + (!m->first || (!m->first->is_static() && !m->first->is_global()))) + args.append(as_value()); + if (skip < (int) ops.size() && ops[skip] == '(' && + ((m->first && m->first->method) || m->second.is_function() || + m->second.is_function_handle())) { + args.append(*idx_it++); + ++skip; + sub_ovl = member_invoke(m, args, nargout); + } else { + sub_ovl = member_deref(m, args); + } + } + // index operator + else { + if (ops[skip] == '(' || ops[skip] == '{') { + const char *op_name = ops[skip] == '(' ? "__paren__" : "__brace__"; + octave_value_list args; + args.append(*idx_it++); + ++skip; + if (!dispatch_index_op(op_name, args, sub_ovl)) { + error("error evaluating index operator"); + return octave_value_list(); + } + } else { + error("unsupported subsref"); + return octave_value_list(); + } + } + + if (skip >= (int) ops.size()) + return sub_ovl; + if (sub_ovl.length() < 1) { + error("bad subs ref"); + return octave_value_list(); + } + return sub_ovl(0).next_subsref(nargout, ops, idx, skip); + } + + octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) { + assert(ops.size() > 0); + assert(ops.size() == idx.size()); + + std::list < octave_value_list >::const_iterator idx_it = idx.begin(); + int skip = 0; + + if (ops.size() > 1) { + std::list < octave_value_list >::const_iterator last = idx.end(); + --last; + std::list < octave_value_list > next_idx(idx.begin(), last); + octave_value next_ov = subsref(ops.substr(0, ops.size() - 1), next_idx); + next_ov.subsasgn(ops.substr(ops.size() - 1), std::list < octave_value_list > (1, *last), rhs); + } + + else if (ops[skip] == '(' || ops[skip] == '{') { + const char *op_name = ops[skip] == '(' ? "__paren_asgn__" : "__brace_asgn__"; + member_value_pair *m = find_member(op_name, false); + if (m) { + octave_value_list args; + args.append(as_value()); + args.append(*idx_it); + args.append(rhs); + member_invoke(m, args, 1); + } else + error("%s member not found", op_name); + } + + else if (ops[skip] == '.') { + octave_value_list subname_ovl(*idx_it++); + ++skip; + assert(subname_ovl.length() == 1 &&subname_ovl(0).is_string()); + std::string subname = subname_ovl(0).string_value(); + + member_value_pair *m = find_member(subname, true); + if (!m->first || !m->first->set_method) { + m->first = 0; + m->second = rhs; + } else if (m->first->set_method) { + octave_value_list args; + if (!m->first->is_static() && !m->first->is_global()) + args.append(as_value()); + args.append(rhs); + m->first->set_method(args, 1); + } else + error("member not assignable"); + } else + error("unsupported subsasgn"); + + return as_value(); + } + + virtual bool is_object() const { + return true; + } + + virtual bool is_string() const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + return !!nc_this->find_member("__str__", false); + } + + virtual std::string string_value(bool force = false) const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + member_value_pair *m = nc_this->find_member("__str__", false); + if (!m) { + error("__str__ method not defined"); + return std::string(); + } + octave_value_list outarg = nc_this->member_invoke(m, octave_value_list(nc_this->as_value()), 1); + if (outarg.length() < 1 || !outarg(0).is_string()) { + error("__str__ method did not return a string"); + return std::string(); + } + return outarg(0).string_value(); + } + +#if SWIG_OCTAVE_PREREQ(3,3,52) + virtual octave_map map_value() const { + return octave_map(); + } +#else + virtual Octave_map map_value() const { + return Octave_map(); + } +#endif + + virtual string_vector map_keys() const { + member_map tmp; + load_members(tmp); + + string_vector keys(tmp.size()); + int k = 0; + for (member_map::iterator it = tmp.begin(); it != tmp.end(); ++it) + keys(k++) = it->first; + + return keys; + } + + virtual bool save_ascii (std::ostream& os) { + return true; + } + + virtual bool load_ascii (std::istream& is) { + return true; + } + + virtual bool save_binary (std::ostream& os, bool& save_as_floats) { + return true; + } + + virtual bool load_binary (std::istream& is, bool swap, + oct_mach_info::float_format fmt) { + return true; + } + +#if defined (HAVE_HDF5) + virtual bool + save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { + return true; + } + + virtual bool + load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) { + return true; + } +#endif + + virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const { + return string_value(); + } + + virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const { + return string_value(); + } + + static bool dispatch_global_op(const std::string &symbol, const octave_value_list &args, octave_value &ret) { + // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace + // (rather than any module namespace). + + octave_function *fcn = is_valid_function(symbol, std::string(), false); + if (!fcn) + return false; + ret = fcn->do_multi_index_op(1, args)(0); + return true; + } + + static octave_value dispatch_unary_op(const octave_base_value &x, const char *op_name) { + octave_swig_type *ost = Swig::swig_value_deref(x); + assert(ost); + + octave_value ret; + if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret)) + return ret; + std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name; + octave_value_list args; + args.append(make_value_hack(x)); + if (dispatch_global_op(symbol, args, ret)) + return ret; + + error("could not dispatch unary operator"); + return octave_value(); + } + + static octave_value dispatch_binary_op(const octave_base_value &lhs, const octave_base_value &rhs, const char *op_name) { + octave_swig_type *lhs_ost = Swig::swig_value_deref(lhs); + octave_swig_type *rhs_ost = Swig::swig_value_deref(rhs); + + octave_value ret; + if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret)) + return ret; + if (rhs_ost) { + if (strlen(op_name) == 2 && (op_name[1] == 't' || op_name[1] == 'e')) { + if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret)) + return ret; + if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret)) + return ret; + } + if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret)) + return ret; + } + + std::string symbol; + octave_value_list args; + args.append(make_value_hack(lhs)); + args.append(make_value_hack(rhs)); + + symbol = SWIG_op_prefix; + symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); + symbol += "_"; + symbol += op_name; + symbol += "_"; + symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name(); + if (dispatch_global_op(symbol, args, ret)) + return ret; + + symbol = SWIG_op_prefix; + symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); + symbol += "_"; + symbol += op_name; + symbol += "_"; + symbol += "any"; + if (dispatch_global_op(symbol, args, ret)) + return ret; + + symbol = SWIG_op_prefix; + symbol += "any"; + symbol += "_"; + symbol += op_name; + symbol += "_"; + symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name(); + if (dispatch_global_op(symbol, args, ret)) + return ret; + + error("could not dispatch binary operator"); + return octave_value(); + } + + void print(std::ostream &os, bool pr_as_read_syntax = false) const { + if (is_string()) { + os << string_value(); + return; + } + + member_map tmp; + load_members(tmp); + + indent(os); + os << "{"; newline(os); + increment_indent_level(); + for (unsigned int j = 0; j < types.size(); ++j) { + indent(os); + if (types[j].first->clientdata) { + const swig_octave_class *c = (const swig_octave_class *) types[j].first->clientdata; + os << c->name << ", ptr = " << types[j].second.ptr; newline(os); + } else { + os << types[j].first->name << ", ptr = " << types[j].second.ptr; newline(os); + } + } + for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) { + indent(os); + if (it->second.first) { + const char *objtype = it->second.first->method ? "method" : "variable"; + const char *modifier = (it->second.first->flags &1) ? "static " : (it->second.first->flags &2) ? "global " : ""; + os << it->second.first->name << " (" << modifier << objtype << ")"; newline(os); + assert(it->second.first->name == it->first); + } else { + os << it->first; newline(os); + } + } + decrement_indent_level(); + indent(os); + os << "}"; newline(os); + } + }; + + // Octave tries hard to preserve pass-by-value semantics. Eg, assignments + // will call clone() via make_unique() if there is more than one outstanding + // reference to the lhs, and forces the clone's reference count to 1 + // (so you can't just increment your own count and return this). + // + // One way to fix this (without modifying Octave) is to add a level of + // indirection such that clone copies ref-counted pointer and we keep + // pass-by-ref semantics (which are more natural/expected for C++ bindings). + // + // Supporting both pass-by-{ref,value} and toggling via %feature/option + // might be nice. + + class octave_swig_ref:public octave_base_value { + octave_swig_type *ptr; + public: + octave_swig_ref(octave_swig_type *_ptr = 0) + :ptr(_ptr) { } + + ~octave_swig_ref() + { if (ptr) ptr->decref(); } + + octave_swig_type *get_ptr() const + { return ptr; } + + octave_base_value *clone() const + { if (ptr) ptr->incref(); return new octave_swig_ref(ptr); } + + octave_base_value *empty_clone() const + { return new octave_swig_ref(0); } + + dim_vector dims(void) const + { return ptr->dims(); } + + bool is_defined() const + { return ptr->is_defined(); } + + virtual bool is_map() const + { return ptr->is_map(); } + + virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) + { return ptr->subsref(ops, idx); } + + virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) + { return ptr->subsref(ops, idx, nargout); } + + octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) + { return ptr->subsasgn(ops, idx, rhs); } + + virtual bool is_object() const + { return ptr->is_object(); } + + virtual bool is_string() const + { return ptr->is_string(); } + + virtual std::string string_value(bool force = false) const + { return ptr->string_value(force); } + +#if SWIG_OCTAVE_PREREQ(3,3,52) + virtual octave_map map_value() const + { return ptr->map_value(); } +#else + virtual Octave_map map_value() const + { return ptr->map_value(); } +#endif + + virtual string_vector map_keys() const + { return ptr->map_keys(); } + + virtual bool save_ascii (std::ostream& os) + { return ptr->save_ascii(os); } + + virtual bool load_ascii (std::istream& is) + { return ptr->load_ascii(is); } + + virtual bool save_binary (std::ostream& os, bool& save_as_floats) + { return ptr->save_binary(os, save_as_floats); } + + virtual bool load_binary (std::istream& is, bool swap, + oct_mach_info::float_format fmt) + { return ptr->load_binary(is, swap, fmt); } + +#if defined (HAVE_HDF5) + virtual bool + save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) + { return ptr->save_hdf5(loc_id, name, save_as_floats); } + + virtual bool + load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) + { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); } +#endif + + virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const + { return ptr->convert_to_str(pad, force, type); } + + virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const + { return ptr->convert_to_str_internal(pad, force, type); } + + void print(std::ostream &os, bool pr_as_read_syntax = false) const + { return ptr->print(os, pr_as_read_syntax); } + + private: + DECLARE_OCTAVE_ALLOCATOR; + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; + }; + DEFINE_OCTAVE_ALLOCATOR(octave_swig_ref); + DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_ref, "swig_ref", "swig_ref"); + + class octave_swig_packed:public octave_base_value { + swig_type_info *type; + std::vector < char > buf; + public: + + octave_swig_packed(swig_type_info *_type = 0, const void *_buf = 0, size_t _buf_len = 0) + : type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len) { + } + + bool copy(swig_type_info *outtype, void *ptr, size_t sz) const { + if (outtype && outtype != type) + return false; + assert(sz <= buf.size()); + std::copy(buf.begin(), buf.begin()+sz, (char*)ptr); + return true; + } + + octave_base_value *clone() const { + return new octave_swig_packed(*this); + } + + octave_base_value *empty_clone() const { + return new octave_swig_packed(); + } + + bool is_defined() const { + return true; + } + + void print(std::ostream &os, bool pr_as_read_syntax = false) const { + indent(os); + os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os); + } + + + virtual bool save_ascii (std::ostream& os) { + return true; + } + + virtual bool load_ascii (std::istream& is) { + return true; + } + + virtual bool save_binary (std::ostream& os, bool& save_as_floats) { + return true; + } + + virtual bool load_binary (std::istream& is, bool swap, + oct_mach_info::float_format fmt) { + return true; + } + +#if defined (HAVE_HDF5) + virtual bool + save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { + return true; + } + + virtual bool + load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) { + return true; + } +#endif + + private: + DECLARE_OCTAVE_ALLOCATOR; + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; + }; + DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed); + DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed"); + + SWIGRUNTIME octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) { + error("attempt to set immutable member variable"); + return octave_value_list(); + } + + struct octave_value_ref { + const octave_value_list &ovl; + int j; + + octave_value_ref(const octave_value_list &_ovl, int _j) + :ovl(_ovl), j(_j) { } + + operator octave_value() const { + return ovl(j); + } + + octave_value operator*() const { + return ovl(j); + } + }; + + +namespace Swig { + + SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) { + return new octave_swig_ref(ost); + } + + SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) { + if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) + ov = ov.cell_value()(0); + return swig_value_deref(*ov.internal_rep()); + } + + SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) { + if (ov.type_id() != octave_swig_ref::static_type_id()) + return 0; + const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov); + return osr->get_ptr(); + } + +} + + +#define swig_unary_op(name) \ +SWIGRUNTIME octave_value swig_unary_op_##name(const octave_base_value &x) { \ + return octave_swig_type::dispatch_unary_op(x,#name); \ +} +#define swig_binary_op(name) \ +SWIGRUNTIME octave_value swig_binary_op_##name(const octave_base_value&lhs,const octave_base_value &rhs) { \ + return octave_swig_type::dispatch_binary_op(lhs,rhs,#name); \ +} +#define swigreg_unary_op(name) \ +if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \ +octave_value_typeinfo::register_unary_op(octave_value::op_##name,tid,swig_unary_op_##name); +#define swigreg_binary_op(name) \ +if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \ +octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig_binary_op_##name); + + swig_unary_op(not); + swig_unary_op(uplus); + swig_unary_op(uminus); + swig_unary_op(transpose); + swig_unary_op(hermitian); + swig_unary_op(incr); + swig_unary_op(decr); + + swig_binary_op(add); + swig_binary_op(sub); + swig_binary_op(mul); + swig_binary_op(div); + swig_binary_op(pow); + swig_binary_op(ldiv); + swig_binary_op(lshift); + swig_binary_op(rshift); + swig_binary_op(lt); + swig_binary_op(le); + swig_binary_op(eq); + swig_binary_op(ge); + swig_binary_op(gt); + swig_binary_op(ne); + swig_binary_op(el_mul); + swig_binary_op(el_div); + swig_binary_op(el_pow); + swig_binary_op(el_ldiv); + swig_binary_op(el_and); + swig_binary_op(el_or); + + SWIGRUNTIME void SWIG_InstallUnaryOps(int tid) { + swigreg_unary_op(not); + swigreg_unary_op(uplus); + swigreg_unary_op(uminus); + swigreg_unary_op(transpose); + swigreg_unary_op(hermitian); + swigreg_unary_op(incr); + swigreg_unary_op(decr); + } + SWIGRUNTIME void SWIG_InstallBinaryOps(int tid1, int tid2) { + swigreg_binary_op(add); + swigreg_binary_op(sub); + swigreg_binary_op(mul); + swigreg_binary_op(div); + swigreg_binary_op(pow); + swigreg_binary_op(ldiv); + swigreg_binary_op(lshift); + swigreg_binary_op(rshift); + swigreg_binary_op(lt); + swigreg_binary_op(le); + swigreg_binary_op(eq); + swigreg_binary_op(ge); + swigreg_binary_op(gt); + swigreg_binary_op(ne); + swigreg_binary_op(el_mul); + swigreg_binary_op(el_div); + swigreg_binary_op(el_pow); + swigreg_binary_op(el_ldiv); + swigreg_binary_op(el_and); + swigreg_binary_op(el_or); + } + SWIGRUNTIME void SWIG_InstallOps(int tid) { + // here we assume that tid are conseq integers increasing from zero, and + // that our tid is the last one. might be better to have explicit string + // list of types we should bind to, and use lookup_type to resolve their tid. + + SWIG_InstallUnaryOps(tid); + SWIG_InstallBinaryOps(tid, tid); + for (int j = 0; j < tid; ++j) { + SWIG_InstallBinaryOps(j, tid); + SWIG_InstallBinaryOps(tid, j); + } + } + +SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + +#ifdef SWIG_DIRECTORS + Swig::Director *d = Swig::get_rtdir(ptr); + if (d && Swig::swig_director_get_self(d)) + return Swig::swig_director_get_self(d)->as_value(); +#endif + return Swig::swig_value_ref(new octave_swig_type(ptr, type, own)); +} + +SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) { + if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) + ov = ov.cell_value()(0); + if (!ov.is_defined() || + (ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0) ) { + if (ptr) + *ptr = 0; + return SWIG_OK; + } + if (ov.type_id() != octave_swig_ref::static_type_id()) + return SWIG_ERROR; + octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep()); + octave_swig_type *ost = osr->get_ptr(); + void *vptr = ost->cast(type, own, flags); + if (!vptr) + return SWIG_ERROR; + if (ptr) + *ptr = vptr; + return SWIG_OK; +} + +SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return new octave_swig_packed(type, (char *) ptr, sz); +} + +SWIGRUNTIME int SWIG_Octave_ConvertPacked(const octave_value &ov, void *ptr, size_t sz, swig_type_info *type) { + if (!ov.is_defined()) + return SWIG_ERROR; + if (ov.type_id() != octave_swig_packed::static_type_id()) + return SWIG_ERROR; + octave_swig_packed *ost = static_cast < octave_swig_packed *>(ov.internal_rep()); + return ost->copy(type, (char *) ptr, sz) ? SWIG_OK : SWIG_ERROR; +} + +SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) { + module_ns->assign(name, ov); +} + +SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) { + return get_global_value(name, true); +} + +SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) { + set_global_value(name, value); +} + +SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { +#if !SWIG_OCTAVE_PREREQ(3,2,0) + link_to_global_variable(curr_sym_tab->lookup(name, true)); +#else +#if !SWIG_OCTAVE_PREREQ(3,8,0) + symbol_table::varref(name); +#endif + symbol_table::mark_global(name); +#endif +} + +SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) { + octave_value ov = SWIG_Octave_GetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION); + if (!ov.is_defined() || + ov.type_id() != octave_swig_packed::static_type_id()) + return 0; + const octave_swig_packed* osp = + static_cast < const octave_swig_packed *> (ov.internal_rep()); + swig_module_info *pointer = 0; + osp->copy(0, &pointer, sizeof(swig_module_info *)); + return pointer; +} + +SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) { + octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *)); + SWIG_Octave_SetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, ov); +} diff --git a/Lib/octave/octrunclass.swg b/Lib/octave/octrunclass.swg deleted file mode 100644 index 2310a45b8..000000000 --- a/Lib/octave/octrunclass.swg +++ /dev/null @@ -1,1203 +0,0 @@ -// -// octrunclass.swg - Octave runtime classes -// - -////////// Octave class: SwigOctType ////////// - -const SwigOctMember* SwigOctType::find_member(const swig_type_info* type, const std::string& name) -{ - if (!type->clientdata) { - return 0; - } - SwigOctClass* c = (SwigOctClass*) type->clientdata; - const SwigOctMember* m; - for (m = c->members; m->name; ++m) - if (m->name == name) { - return m; - } - for (int j = 0; c->base_names[j]; ++j) { - if (!c->base[j]) { - if (!module) { - module = SWIG_GetModule(0); - } - assert(module); - c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); - } - if (!c->base[j]) { - return 0; - } - if ((m = find_member(c->base[j], name))) { - return m; - } - } - return 0; -} - -SwigOctType::member_value_pair* SwigOctType::find_member(const std::string& name, bool insert_if_not_found) -{ - member_map::iterator it = members.find(name); - if (it != members.end()) { - return &it->second; - } - const SwigOctMember* m; - for (unsigned int j = 0; j < types.size(); ++j) - if ((m = find_member(types[j].first, name))) { - return &members.insert(std::make_pair(name, std::make_pair(m, octave_value()))).first->second; - } - if (!insert_if_not_found) { - return 0; - } - return &members[name]; -} - -const swig_type_info* SwigOctType::find_base(const std::string& name, const swig_type_info* base) -{ - if (!base) { - for (unsigned int j = 0; j < types.size(); ++j) { - assert(types[j].first->clientdata); - SwigOctClass* cj = (SwigOctClass*) types[j].first->clientdata; - if (cj->name == name) { - return types[j].first; - } - } - return 0; - } - assert(base->clientdata); - SwigOctClass* c = (SwigOctClass*) base->clientdata; - for (int j = 0; c->base_names[j]; ++j) { - if (!c->base[j]) { - if (!module) { - module = SWIG_GetModule(0); - } - assert(module); - c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); - } - if (!c->base[j]) { - return 0; - } - assert(c->base[j]->clientdata); - SwigOctClass* cj = (SwigOctClass*) c->base[j]->clientdata; - if (cj->name == name) { - return c->base[j]; - } - } - return 0; -} - -void SwigOctType::load_members(const SwigOctClass* c, member_map& out) const -{ - for (const SwigOctMember* m = c->members; m->name; ++m) { - if (out.find(m->name) == out.end()) { - out.insert(std::make_pair(m->name, std::make_pair(m, octave_value()))); - } - } - for (int j = 0; c->base_names[j]; ++j) { - if (!c->base[j]) { - if (!module) { - module = SWIG_GetModule(0); - } - assert(module); - c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]); - } - if (!c->base[j]) { - continue; - } - assert(c->base[j]->clientdata); - const SwigOctClass* cj = - (const SwigOctClass*) c->base[j]->clientdata; - load_members(cj, out); - } -} - -void SwigOctType::load_members(member_map& out) const -{ - out = members; - for (unsigned int j = 0; j < types.size(); ++j) - if (types[j].first->clientdata) { - load_members((const SwigOctClass*) types[j].first->clientdata, out); - } -} - -octave_value_list SwigOctType::member_invoke(member_value_pair* m, const octave_value_list& args, int nargout) -{ - if (m->second.is_defined()) { - return m->second.subsref("(", std::list < octave_value_list > (1, args), nargout); - } else if (m->first && m->first->method) { - return m->first->method(args, nargout); - } - error("member not defined or not invocable"); - return octave_value_list(); -} - -bool SwigOctType::dispatch_unary_op(const std::string& symbol, octave_value& ret) -{ - member_value_pair* m = find_member(symbol, false); - if (!m || m->first->is_static() || m->first->is_global()) { - return false; - } - octave_value_list args; - args.append(as_value()); - octave_value_list argout(member_invoke(m, args, 1)); - if (argout.length() < 1) { - return false; - } - ret = argout(0); - return true; -} - -bool SwigOctType::dispatch_binary_op(const std::string& symbol, const octave_base_value& rhs, octave_value& ret) -{ - member_value_pair* m = find_member(symbol, false); - if (!m || m->first->is_static() || m->first->is_global()) { - return false; - } - octave_value_list args; - args.append(as_value()); - args.append(make_value_hack(rhs)); - octave_value_list argout(member_invoke(m, args, 1)); - if (argout.length() < 1) { - return false; - } - ret = argout(0); - return true; -} - -bool SwigOctType::dispatch_index_op(const std::string& symbol, const octave_value_list& rhs, octave_value_list& ret) -{ - member_value_pair* m = find_member(symbol, false); - if (!m || m->first->is_static() || m->first->is_global()) { - return false; - } - octave_value_list args; - args.append(as_value()); - args.append(rhs); - octave_value_list argout(member_invoke(m, args, 1)); - if (argout.length() >= 1) { - ret = argout(0); - } - return true; -} - -octave_value_list SwigOctType::member_deref(member_value_pair* m, const octave_value_list& args) -{ - if (m->second.is_defined()) { - return m->second; - } else if (m->first) { - if (m->first->get_method) { - return m->first->get_method(args, 1); - } else if (m->first->method) { - return octave_value(new octave_builtin(m->first->method)); - } - } - error("undefined member"); - return octave_value_list(); -} - -octave_value SwigOctType::make_value_hack(const octave_base_value& x) -{ - ((SwigOctType&) x).count++; - return octave_value((octave_base_value*) &x); -} - -SwigOctType::SwigOctType(void* _ptr, const swig_type_info* _type, int _own, bool _always_static) - : module(0), construct_type(_ptr ? 0 : _type), own(_own), always_static(_always_static) -{ - if (_type || _ptr) { - types.push_back(std::make_pair(_type, _ptr)); - } -#ifdef SWIG_DIRECTORS - if (_ptr) { - Swig::Director* d = Swig::get_rtdir(_ptr); - if (d) { - Swig::swig_director_set_self(d, this); - } - } -#endif -} - -SwigOctType::~SwigOctType() -{ - if (own) { - ++count; - for (unsigned int j = 0; j < types.size(); ++j) { - if (!types[j].first || !types[j].first->clientdata) { - continue; - } - SwigOctClass* c = (SwigOctClass*) types[j].first->clientdata; - if (c->destructor && !types[j].second.destroyed && types[j].second.ptr) { - c->destructor(as_value(), 0); - } - } - } -#ifdef SWIG_DIRECTORS - for (unsigned int j = 0; j < types.size(); ++j) { - Swig::erase_rtdir(types[j].second.ptr); - } -#endif -} - -dim_vector SwigOctType::dims(void) const -{ - SwigOctType* nc_this = const_cast < SwigOctType*>(this); - - // Find the __dims__ method of this object - member_value_pair* m = nc_this->find_member("__dims__", false); - - if (!m) { - return dim_vector(1, 1); - } - - // Call the __dims__ method of this object - octave_value_list inarg; - inarg.append(nc_this->as_value()); - octave_value_list outarg = nc_this->member_invoke(m, inarg, 1); - - // __dims__ should return (at least) one output argument - if (outarg.length() < 1) { - return dim_vector(1, 1); - } - - octave_value& out = outarg(0); - - // Return value should be cell or matrix of integers - if (out.is_cell()) { - const Cell& c = out.cell_value(); - int ndim = c.rows(); - if (ndim == 1 && c.columns() != 1) { - ndim = c.columns(); - } - - dim_vector d; - d.resize(ndim < 2 ? 2 : ndim); - d(0) = d(1) = 1; - - // Fill in dim_vector - for (int k = 0; k < ndim; k++) { - const octave_value& obj = c(k); - d.elem(k) = obj.int_value(); - - // __dims__ should return a cell filled with integers - if (error_state) { - return dim_vector(1, 1); - } - } - return d; - } else if (out.is_matrix_type() || out.is_numeric_type()) { - if (out.rows() == 1 || out.columns() == 1) { - Array<int> a = out.int_vector_value(); - if (error_state) { - return dim_vector(1, 1); - } - dim_vector d; - d.resize(a.numel() < 2 ? 2 : a.numel()); - d(0) = d(1) = 1; - for (int k = 0; k < a.numel(); k++) { - d.elem(k) = a(k); - } - return d; - } else { - return dim_vector(1, 1); - } - } else { - return dim_vector(1, 1); - } -} - -octave_value SwigOctType::as_value() -{ - ++count; - return SWIG_Octave_ValueRef(this); -} - -void SwigOctType::incref() -{ - ++count; -} - -void SwigOctType::decref() -{ - if (!--count) { - delete this; - } -} - -long SwigOctType::swig_this() const -{ - if (!types.size()) { - return (long) this; - } - return (long) types[0].second.ptr; -} - -const char* SwigOctType::help_text() const -{ - if (!types.size()) { - return 0; - } - if (!types[0].first->clientdata) { - return 0; - } - SwigOctClass* c = (SwigOctClass*) types[0].first->clientdata; - return c->constructor_doc; -} - -std::string SwigOctType::swig_type_name() const -{ - // * need some way to manually name subclasses. - // * eg optional first arg to subclass(), or named_subclass() - std::string ret; - for (unsigned int j = 0; j < types.size(); ++j) { - if (j) { - ret += "_"; - } - if (types[j].first->clientdata) { - SwigOctClass* c = (SwigOctClass*) types[j].first->clientdata; - ret += c->name; - } else { - ret += types[j].first->name; - } - } - return ret; -} - -void SwigOctType::merge(SwigOctType& rhs) -{ - rhs.own = 0; - for (unsigned int j = 0; j < rhs.types.size(); ++j) { - assert(!rhs.types[j].second.destroyed); -#ifdef SWIG_DIRECTORS - Swig::Director* d = Swig::get_rtdir(rhs.types[j].second.ptr); - if (d) { - Swig::swig_director_set_self(d, this); - } -#endif - } - types.insert(types.end(), rhs.types.begin(), rhs.types.end()); - members.insert(rhs.members.begin(), rhs.members.end()); - rhs.types.clear(); - rhs.members.clear(); -} - -SwigOctType::swig_member_const_iterator SwigOctType::swig_members_begin() -{ - return members.begin(); -} - -SwigOctType::swig_member_const_iterator SwigOctType::swig_members_end() -{ - return members.end(); -} - -void* SwigOctType::cast(swig_type_info* type, int* _own, int flags) -{ - if (_own) { - *_own = own; - } - if (flags & SWIG_POINTER_DISOWN) { - own = 0; - } - if (!type && types.size()) { - return types[0].second.ptr; - } - for (unsigned int j = 0; j < types.size(); ++j) - if (type == types[j].first) { - return types[j].second.ptr; - } - for (unsigned int j = 0; j < types.size(); ++j) { - swig_cast_info* tc = SWIG_TypeCheck(types[j].first->name, type); - if (!tc) { - continue; - } - int newmemory = 0; - void* vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); - assert(!newmemory); // newmemory handling not yet implemented - return vptr; - } - return 0; -} - -bool SwigOctType::is_owned() const -{ - return own; -} - -#ifdef SWIG_DIRECTORS -void SwigOctType::director_destroyed(Swig::Director* d) -{ - bool found = false; - for (unsigned int j = 0; j < types.size(); ++j) { - Swig::Director* dj = Swig::get_rtdir(types[j].second.ptr); - if (dj == d) { - types[j].second.destroyed = true; - found = true; - } - } - assert(found); -} -#endif - -void SwigOctType::assign(const std::string& name, const octave_value& ov) -{ - members[name] = std::make_pair((const SwigOctMember*) 0, ov); -} - -void SwigOctType::assign(const std::string& name, const SwigOctMember* m) -{ - members[name] = std::make_pair(m, octave_value()); -} - -octave_base_value* SwigOctType::clone() const -{ - // pass-by-value is probably not desired, and is harder; - // requires calling copy constructors of contained types etc. - assert(0); - * (int*) 0 = 0; - return 0; -} - -octave_base_value* SwigOctType::empty_clone() const -{ - return new SwigOctType(); -} - -bool SwigOctType::is_defined() const -{ - return true; -} - -bool SwigOctType::is_map() const -{ - return true; -} - -octave_value SwigOctType::subsref(const std::string& ops, const std::list < octave_value_list > &idx) -{ - octave_value_list ovl = subsref(ops, idx, 1); - return ovl.length() ? ovl(0) : octave_value(); -} - -octave_value_list SwigOctType::subsref(const std::string& ops, const std::list < octave_value_list > &idx, int nargout) -{ - assert(ops.size() > 0); - assert(ops.size() == idx.size()); - - std::list < octave_value_list >::const_iterator idx_it = idx.begin(); - int skip = 0; - octave_value_list sub_ovl; - - // constructor invocation - if (ops[skip] == '(' && construct_type) { - assert(construct_type->clientdata); - SwigOctClass* c = (SwigOctClass*) construct_type->clientdata; - if (!c->constructor) { - error("cannot create instance"); - return octave_value_list(); - } - octave_value_list args; - if (c->director) { - args.append(SWIG_Octave_ValueRef(new SwigOctType(this, 0, 0))); - } - args.append(*idx_it++); - ++skip; - sub_ovl = c->constructor(args, nargout); - } - // member dereference or invocation - else if (ops[skip] == '.') { - std::string subname; - const swig_type_info* base = 0; // eg, a.base.base_cpp_mem - for (;;) { - octave_value_list subname_ovl(*idx_it++); - ++skip; - assert(subname_ovl.length() == 1 && subname_ovl(0).is_string()); - subname = subname_ovl(0).string_value(); - - const swig_type_info* next_base = find_base(subname, base); - if (!next_base || skip >= (int) ops.size() || ops[skip] != '.') { - break; - } - base = next_base; - } - - member_value_pair tmp, *m = &tmp; - if (!base || !(m->first = find_member(base, subname))) { - m = find_member(subname, false); - } - if (!m) { - error("member not found"); - return octave_value_list(); - } - - octave_value_list args; - if (!always_static && - (!m->first || (!m->first->is_static() && !m->first->is_global()))) { - args.append(as_value()); - } - if (skip < (int) ops.size() && ops[skip] == '(' && - ((m->first && m->first->method) || m->second.is_function() || - m->second.is_function_handle())) { - args.append(*idx_it++); - ++skip; - sub_ovl = member_invoke(m, args, nargout); - } else { - sub_ovl = member_deref(m, args); - } - } - // index operator - else { - if (ops[skip] == '(' || ops[skip] == '{') { - const char* op_name = ops[skip] == '(' ? "__paren__" : "__brace__"; - octave_value_list args; - args.append(*idx_it++); - ++skip; - if (!dispatch_index_op(op_name, args, sub_ovl)) { - error("error evaluating index operator"); - return octave_value_list(); - } - } else { - error("unsupported subsref"); - return octave_value_list(); - } - } - - if (skip >= (int) ops.size()) { - return sub_ovl; - } - if (sub_ovl.length() < 1) { - error("bad subs ref"); - return octave_value_list(); - } - return sub_ovl(0).next_subsref(nargout, ops, idx, skip); -} - -octave_value SwigOctType::subsasgn(const std::string& ops, const std::list < octave_value_list > &idx, const octave_value& rhs) -{ - assert(ops.size() > 0); - assert(ops.size() == idx.size()); - - std::list < octave_value_list >::const_iterator idx_it = idx.begin(); - int skip = 0; - - if (ops.size() > 1) { - std::list < octave_value_list >::const_iterator last = idx.end(); - --last; - std::list < octave_value_list > next_idx(idx.begin(), last); - octave_value next_ov = subsref(ops.substr(0, ops.size() - 1), next_idx); - next_ov.subsasgn(ops.substr(ops.size() - 1), std::list < octave_value_list > (1, *last), rhs); - } - - else if (ops[skip] == '(' || ops[skip] == '{') { - const char* op_name = ops[skip] == '(' ? "__paren_asgn__" : "__brace_asgn__"; - member_value_pair* m = find_member(op_name, false); - if (m) { - octave_value_list args; - args.append(as_value()); - args.append(*idx_it); - args.append(rhs); - member_invoke(m, args, 1); - } else { - error("%s member not found", op_name); - } - } - - else if (ops[skip] == '.') { - octave_value_list subname_ovl(*idx_it++); - ++skip; - assert(subname_ovl.length() == 1 && subname_ovl(0).is_string()); - std::string subname = subname_ovl(0).string_value(); - - member_value_pair* m = find_member(subname, true); - if (!m->first || !m->first->set_method) { - m->first = 0; - m->second = rhs; - } else if (m->first->set_method) { - octave_value_list args; - if (!m->first->is_static() && !m->first->is_global()) { - args.append(as_value()); - } - args.append(rhs); - m->first->set_method(args, 1); - } else { - error("member not assignable"); - } - } else { - error("unsupported subsasgn"); - } - - return as_value(); -} - -bool SwigOctType::is_object() const -{ - return true; -} - -bool SwigOctType::is_string() const -{ - SwigOctType* nc_this = const_cast < SwigOctType*>(this); - return !!nc_this->find_member("__str__", false); -} - -std::string SwigOctType::string_value(bool force) const -{ - SwigOctType* nc_this = const_cast < SwigOctType*>(this); - member_value_pair* m = nc_this->find_member("__str__", false); - if (!m) { - error("__str__ method not defined"); - return std::string(); - } - octave_value_list outarg = nc_this->member_invoke(m, octave_value_list(nc_this->as_value()), 1); - if (outarg.length() < 1 || !outarg(0).is_string()) { - error("__str__ method did not return a string"); - return std::string(); - } - return outarg(0).string_value(); -} - -octave_map SwigOctType::map_value() const -{ - return octave_map(); -} - -string_vector SwigOctType::map_keys() const -{ - member_map tmp; - load_members(tmp); - - string_vector keys(tmp.size()); - int k = 0; - for (member_map::iterator it = tmp.begin(); it != tmp.end(); ++it) { - keys(k++) = it->first; - } - - return keys; -} - -bool SwigOctType::save_ascii(std::ostream& os) -{ - return true; -} - -bool SwigOctType::load_ascii(std::istream& is) -{ - return true; -} - -bool SwigOctType::save_binary(std::ostream& os, bool& save_as_floats) -{ - return true; -} - -bool SwigOctType::load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt) -{ - return true; -} - -#ifdef HAVE_HDF5 -bool SwigOctType::save_hdf5(hid_t loc_id, const char* name, bool save_as_floats) -{ - return true; -} - -bool SwigOctType::load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug) -{ - return true; -} -#endif - -octave_value SwigOctType::convert_to_str(bool pad, bool force, char type) const -{ - return string_value(); -} - -octave_value SwigOctType::convert_to_str_internal(bool pad, bool force, char type) const -{ - return string_value(); -} - -bool SwigOctType::dispatch_global_op(const std::string& symbol, const octave_value_list& args, octave_value& ret) -{ - // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace - // (rather than any module namespace). - - octave_function* fcn = is_valid_function(symbol, std::string(), false); - if (!fcn) { - return false; - } - ret = fcn->do_multi_index_op(1, args)(0); - return true; -} - -octave_value SwigOctType::dispatch_unary_op(const octave_base_value& x, const char* op_name) -{ - SwigOctType* ost = SWIG_Octave_ValueDeref(x); - assert(ost); - - octave_value ret; - if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret)) { - return ret; - } - std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name; - octave_value_list args; - args.append(make_value_hack(x)); - if (dispatch_global_op(symbol, args, ret)) { - return ret; - } - - error("could not dispatch unary operator"); - return octave_value(); -} - -octave_value SwigOctType::dispatch_binary_op(const octave_base_value& lhs, const octave_base_value& rhs, const char* op_name) -{ - SwigOctType* lhs_ost = SWIG_Octave_ValueDeref(lhs); - SwigOctType* rhs_ost = SWIG_Octave_ValueDeref(rhs); - - octave_value ret; - if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret)) { - return ret; - } - if (rhs_ost) { - if (strlen(op_name) == 2 && (op_name[1] == 't' || op_name[1] == 'e')) { - if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret)) { - return ret; - } - if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret)) { - return ret; - } - } - if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret)) { - return ret; - } - } - - std::string symbol; - octave_value_list args; - args.append(make_value_hack(lhs)); - args.append(make_value_hack(rhs)); - - symbol = SWIG_op_prefix; - symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); - symbol += "_"; - symbol += op_name; - symbol += "_"; - symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name(); - if (dispatch_global_op(symbol, args, ret)) { - return ret; - } - - symbol = SWIG_op_prefix; - symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); - symbol += "_"; - symbol += op_name; - symbol += "_"; - symbol += "any"; - if (dispatch_global_op(symbol, args, ret)) { - return ret; - } - - symbol = SWIG_op_prefix; - symbol += "any"; - symbol += "_"; - symbol += op_name; - symbol += "_"; - symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name(); - if (dispatch_global_op(symbol, args, ret)) { - return ret; - } - - error("could not dispatch binary operator"); - return octave_value(); -} - -void SwigOctType::print(std::ostream& os, bool pr_as_read_syntax) const -{ - if (is_string()) { - os << string_value(); - return; - } - - member_map tmp; - load_members(tmp); - - indent(os); - os << "{"; - newline(os); - increment_indent_level(); - for (unsigned int j = 0; j < types.size(); ++j) { - indent(os); - if (types[j].first->clientdata) { - const SwigOctClass* c = (const SwigOctClass*) types[j].first->clientdata; - os << c->name << ", ptr = " << types[j].second.ptr; - newline(os); - } else { - os << types[j].first->name << ", ptr = " << types[j].second.ptr; - newline(os); - } - } - for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) { - indent(os); - if (it->second.first) { - const char* objtype = it->second.first->method ? "method" : "variable"; - const char* modifier = (it->second.first->flags & 1) ? "static " : (it->second.first->flags & 2) ? "global " : ""; - os << it->second.first->name << " (" << modifier << objtype << ")"; - newline(os); - assert(it->second.first->name == it->first); - } else { - os << it->first; - newline(os); - } - } - decrement_indent_level(); - indent(os); - os << "}"; - newline(os); -} - -////////// Octave class: SwigOctRef ////////// - -DEFINE_OCTAVE_ALLOCATOR(SwigOctRef); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(SwigOctRef, "swig_ref", "swig_ref"); - -SwigOctRef::SwigOctRef(SwigOctType* _ptr) - : ptr(_ptr) -{ } - -SwigOctRef::~SwigOctRef() -{ - if (ptr) { - ptr->decref(); - } -} - -SwigOctType* SwigOctRef::get_ptr() const -{ - return ptr; -} - -octave_base_value* SwigOctRef::clone() const -{ - if (ptr) { - ptr->incref(); - } - return new SwigOctRef(ptr); -} - -octave_base_value* SwigOctRef::empty_clone() const -{ - return new SwigOctRef(0); -} - -dim_vector SwigOctRef::dims(void) const -{ - return ptr->dims(); -} - -bool SwigOctRef::is_defined() const -{ - return ptr->is_defined(); -} - -bool SwigOctRef::is_map() const -{ - return ptr->is_map(); -} - -octave_value SwigOctRef::subsref(const std::string& ops, const std::list < octave_value_list > &idx) -{ - return ptr->subsref(ops, idx); -} - -octave_value_list SwigOctRef::subsref(const std::string& ops, const std::list < octave_value_list > &idx, int nargout) -{ - return ptr->subsref(ops, idx, nargout); -} - -octave_value SwigOctRef::subsasgn(const std::string& ops, const std::list < octave_value_list > &idx, const octave_value& rhs) -{ - return ptr->subsasgn(ops, idx, rhs); -} - -bool SwigOctRef::is_object() const -{ - return ptr->is_object(); -} - -bool SwigOctRef::is_string() const -{ - return ptr->is_string(); -} - -std::string SwigOctRef::string_value(bool force) const -{ - return ptr->string_value(force); -} - -octave_map SwigOctRef::map_value() const -{ - return ptr->map_value(); -} - -string_vector SwigOctRef::map_keys() const -{ - return ptr->map_keys(); -} - -bool SwigOctRef::save_ascii(std::ostream& os) -{ - return ptr->save_ascii(os); -} - -bool SwigOctRef::load_ascii(std::istream& is) -{ - return ptr->load_ascii(is); -} - -bool SwigOctRef::save_binary(std::ostream& os, bool& save_as_floats) -{ - return ptr->save_binary(os, save_as_floats); -} - -bool SwigOctRef::load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt) -{ - return ptr->load_binary(is, swap, fmt); -} - -#ifdef HAVE_HDF5 -bool SwigOctRef::save_hdf5(hid_t loc_id, const char* name, bool save_as_floats) -{ - return ptr->save_hdf5(loc_id, name, save_as_floats); -} - -bool SwigOctRef::load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug) -{ - return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); -} -#endif - -octave_value SwigOctRef::convert_to_str(bool pad, bool force, char type) const -{ - return ptr->convert_to_str(pad, force, type); -} - -octave_value SwigOctRef::convert_to_str_internal(bool pad, bool force, char type) const -{ - return ptr->convert_to_str_internal(pad, force, type); -} - -void SwigOctRef::print(std::ostream& os, bool pr_as_read_syntax) const -{ - return ptr->print(os, pr_as_read_syntax); -} - -////////// Octave class: SwigOctPacked ////////// - -DEFINE_OCTAVE_ALLOCATOR(SwigOctPacked); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(SwigOctPacked, "swig_packed", "swig_packed"); - -SwigOctPacked::SwigOctPacked(swig_type_info* _type, const void* _buf, size_t _buf_len) - : type(_type), buf((const char*) _buf, (const char*) _buf + _buf_len) -{ } - -bool SwigOctPacked::copy(swig_type_info* outtype, void* ptr, size_t sz) const -{ - if (outtype && outtype != type) { - return false; - } - assert(sz <= buf.size()); - std::copy(buf.begin(), buf.begin() + sz, (char*) ptr); - return true; -} - -octave_base_value* SwigOctPacked::clone() const -{ - return new SwigOctPacked(*this); -} - -octave_base_value* SwigOctPacked::empty_clone() const -{ - return new SwigOctPacked(); -} - -bool SwigOctPacked::is_defined() const -{ - return true; -} - -void SwigOctPacked::print(std::ostream& os, bool pr_as_read_syntax) const -{ - indent(os); - os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); - newline(os); -} - -bool SwigOctPacked::save_ascii(std::ostream& os) -{ - return true; -} - -bool SwigOctPacked::load_ascii(std::istream& is) -{ - return true; -} - -bool SwigOctPacked::save_binary(std::ostream& os, bool& save_as_floats) -{ - return true; -} - -bool SwigOctPacked::load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt) -{ - return true; -} - -#ifdef HAVE_HDF5 -bool SwigOctPacked::save_hdf5(hid_t loc_id, const char* name, bool save_as_floats) -{ - return true; -} - -bool SwigOctPacked::load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug) -{ - return true; -} -#endif - -////////// Octave class: Swig::Director and related classes ////////// - -#ifdef SWIG_DIRECTORS - -#include <exception> - -Swig::Director::Director(void* vptr) : self(0), swig_disowned(false) -{ - set_rtdir(vptr, this); -} - -Swig::Director::~Director() -{ - swig_director_destroyed(self, this); - if (swig_disowned) { - self->decref(); - } -} - -void Swig::Director::swig_set_self(SwigOctType* new_self) -{ - assert(!swig_disowned); - self = new_self; -} - -SwigOctType* Swig::Director::swig_get_self() const -{ - return self; -} - -void Swig::Director::swig_disown() -{ - if (swig_disowned) { - return; - } - swig_disowned = true; - self->incref(); -} - -void Swig::DirectorTypeMismatchException::raise(const char* msg) -{ - // ... todo - throw(DirectorTypeMismatchException()); -} - -void Swig::DirectorTypeMismatchException::raise(const octave_value& ov, const char* msg) -{ - // ... todo - raise(msg); -} - -void Swig::DirectorPureVirtualException::raise(const char* msg) -{ - // ... todo - throw(DirectorPureVirtualException()); -} - -void Swig::DirectorPureVirtualException::raise(const octave_value& ov, const char* msg) -{ - // ... todo - raise(msg); -} - -SWIGOCTRT Swig::rtdir_map* Swig::get_rtdir_map() -{ - static swig_module_info* module = 0; - if (!module) { - module = SWIG_GetModule(0); - } - if (!module) { - return 0; - } - if (!module->clientdata) { - module->clientdata = new rtdir_map; - } - return (rtdir_map*) module->clientdata; -} - -SWIGOCTRTINLINE void Swig::set_rtdir(void* vptr, Director* d) -{ - rtdir_map* rm = get_rtdir_map(); - if (rm) { - (*rm) [vptr] = d; - } -} - -SWIGOCTRTINLINE void Swig::erase_rtdir(void* vptr) -{ - rtdir_map* rm = get_rtdir_map(); - if (rm) { - (*rm).erase(vptr); - } -} - -SWIGOCTRTINLINE Swig::Director* Swig::get_rtdir(void* vptr) -{ - rtdir_map* rm = get_rtdir_map(); - if (!rm) { - return 0; - } - rtdir_map::const_iterator pos = rm->find(vptr); - Director* rtdir = (pos != rm->end()) ? pos->second : 0; - return rtdir; -} - -SWIGOCTRT void Swig::swig_director_destroyed(SwigOctType* self, Director* d) -{ - self->director_destroyed(d); -} - -SWIGOCTRT SwigOctType* Swig::swig_director_get_self(Director* d) -{ - return d->swig_get_self(); -} - -SWIGOCTRT void Swig::swig_director_set_self(Director* d, SwigOctType* self) -{ - d->swig_set_self(self); -} - -SWIGOCTRT void swig_acquire_ownership(void* vptr) -{ - // assert(0); - // ... todo -} - -SWIGOCTRT void swig_acquire_ownership_array(void* vptr) -{ - // assert(0); - // ... todo -} - -SWIGOCTRT void swig_acquire_ownership_obj(void* vptr, int own) -{ - // assert(0); - // ... todo -} - -#endif // SWIG_DIRECTORS diff --git a/Lib/octave/octrundecl.swg b/Lib/octave/octrundecl.swg deleted file mode 100644 index f71895abb..000000000 --- a/Lib/octave/octrundecl.swg +++ /dev/null @@ -1,479 +0,0 @@ -// -// octrundecl.swg - Declarations of Octave runtime code -// - -#include <cstdlib> -#include <iostream> -#include <string> -#include <vector> -#include <map> -#include <octave/oct.h> -#include <octave/Cell.h> -#include <octave/dynamic-ld.h> -#include <octave/oct-env.h> -#include <octave/oct-map.h> -#include <octave/ov-fcn-handle.h> -#include <octave/parse.h> -#include <octave/toplev.h> -#include <octave/unwind-prot.h> -#include <octave/version.h> - -////////// Determine Octave version ////////// - -// Macro for enabling features which require Octave version >= major.minor.patch -#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ - ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + OCTAVE_PATCH_VERSION >= ((major)<<16) + ((minor)<<8) + (patch) ) - -// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 -#if !defined(OCTAVE_MAJOR_VERSION) - -# if !defined(OCTAVE_API_VERSION_NUMBER) - -// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet -// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER -# include <octave/ov.h> -# if defined(octave_ov_h) -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 8 -# define OCTAVE_PATCH_VERSION 0 -# else - -// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed -# define ComplexLU __ignore -# include <octave/CmplxLU.h> -# undef ComplexLU -# if defined(octave_Complex_LU_h) - -// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 1 -# define OCTAVE_PATCH_VERSION 99 - -# else - -// OCTAVE_API_VERSION_NUMBER == 37 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 2 -# define OCTAVE_PATCH_VERSION 0 - -# endif // defined(octave_Complex_LU_h) - -# endif // defined(octave_ov_h) - -// Correlation between Octave API and version numbers extracted from Octave's -// ChangeLogs; version is the *earliest* released Octave with that API number -# elif OCTAVE_API_VERSION_NUMBER >= 48 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 6 -# define OCTAVE_PATCH_VERSION 0 - -# elif OCTAVE_API_VERSION_NUMBER >= 45 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 4 -# define OCTAVE_PATCH_VERSION 1 - -# elif OCTAVE_API_VERSION_NUMBER >= 42 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 54 - -# elif OCTAVE_API_VERSION_NUMBER >= 41 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 53 - -# elif OCTAVE_API_VERSION_NUMBER >= 40 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 52 - -# elif OCTAVE_API_VERSION_NUMBER >= 39 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 51 - -# else // OCTAVE_API_VERSION_NUMBER == 38 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 50 - -# endif // !defined(OCTAVE_API_VERSION_NUMBER) - -#endif // !defined(OCTAVE_MAJOR_VERSION) - -// Octave_map was renamed to octave_map in v3.3.52 -#if !SWIG_OCTAVE_PREREQ(3,3,52) -#define octave_map Octave_map -#endif - -////////// Declare/define SWIG interface function loadable by Octave ////////// - -#if !SWIG_OCTAVE_PREREQ(3,2,0) -#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc) -#else -#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc) -#endif - -////////// Define visibility of Octave runtime functions ////////// - -#define SWIGOCTRT SWIGRUNTIME -#define SWIGOCTRTINLINE SWIGOCTRT SWIGINLINE - -////////// Octave implementations of SWIG runtime functions ////////// - -#define SWIG_fail goto fail -#define swig_owntype int -#define SWIG_MODULE_CLIENTDATA_TYPE void* - -#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0) -#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Octave_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Octave_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtr(obj, pptr, type, flags) -#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtr(obj, pptr, type, flags) -#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, own) -#define SWIG_GetModule(clientdata) SWIG_Octave_GetModule(clientdata) -#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0) -#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Octave_NewPackedObj(ptr, sz, type) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Octave_NewPackedObj(ptr, sz, type) -#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Octave_NewPointerObj(ptr, type, flags) -#define SWIG_Octave_AddErrorMsg(msg) {;} -#define SWIG_Octave_ConvertPtr(obj, pptr, type, flags) SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, 0) -#define SWIG_Octave_ErrorOccurred() 0 -#define SWIG_SetModule(clientdata, pointer) SWIG_Octave_SetModule(clientdata,pointer); - -#define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG) - -// For backward compatibility only -#define SWIG_POINTER_EXCEPTION 0 -#define SWIG_arg_fail(arg) 0 - -////////// Forward declarations of Octave runtime classes and types ////////// - -class SwigOctPacked; -class SwigOctRef; -class SwigOctType; -struct SwigOctClass; -struct SwigOctMember; -struct SwigOctValueRef; -typedef octave_value_list(*SwigOctFuncPtr)(const octave_value_list&, int); - -#ifdef SWIG_DIRECTORS -namespace Swig -{ - class Director; - typedef std::map < void* , Director* > rtdir_map; -} -#endif - -////////// Declarations of Octave runtime functions ////////// - -SWIGOCTRT octave_value SWIG_Error(int code, const char* msg); -SWIGOCTRT octave_value SWIG_ErrorType(int code); -SWIGOCTRT octave_value_list* SWIG_Octave_AppendOutput(octave_value_list* ovl, const octave_value& ov); -SWIGOCTRT bool SWIG_Octave_CheckNumArgs(const char* func_name, int num_args, int max_args, int min_args, int varargs); -SWIGOCTRT int SWIG_Octave_ConvertPacked(const octave_value& ov, void* ptr, size_t sz, swig_type_info* type); -SWIGOCTRT int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void** ptr, swig_type_info* type, int flags, int* own); -SWIGOCTRTINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name); -SWIGOCTRT swig_module_info* SWIG_Octave_GetModule(void* clientdata); -SWIGOCTRT swig_module_info* SWIG_Octave_GetModule(void* clientdata); -SWIGOCTRT void SWIG_Octave_LinkGlobalValue(std::string name); -SWIGOCTRT octave_value SWIG_Octave_NewPackedObj(void* ptr, size_t sz, swig_type_info* type); -SWIGOCTRT octave_value SWIG_Octave_NewPointerObj(void* ptr, swig_type_info* type, int flags); -SWIGOCTRTINLINE void SWIG_Octave_SetConstant(SwigOctType* module_ns, const std::string& name, const octave_value& ov); -SWIGOCTRT void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value); -SWIGOCTRT octave_value_list SWIG_Octave_SetImmutable(const octave_value_list& args, int nargout); -SWIGOCTRT void SWIG_Octave_SetModule(void* clientdata, swig_module_info* pointer); -SWIGOCTRT void SWIG_Octave_SetModule(void* clientdata, swig_module_info* pointer); -SWIGOCTRT SwigOctType* SWIG_Octave_ValueDeref(const octave_base_value& ov); -SWIGOCTRT SwigOctType* SWIG_Octave_ValueDeref(octave_value ov); -SWIGOCTRT octave_base_value* SWIG_Octave_ValueRef(SwigOctType* ost); - -#ifdef SWIG_DIRECTORS -namespace Swig -{ - SWIGOCTRTINLINE void erase_rtdir(void* vptr); - SWIGOCTRTINLINE Director* get_rtdir(void* vptr); - SWIGOCTRT rtdir_map* get_rtdir_map(); - SWIGOCTRTINLINE void set_rtdir(void* vptr, Director* d); - SWIGOCTRT void swig_director_destroyed(SwigOctType* self, Director* d); - SWIGOCTRT SwigOctType* swig_director_get_self(Director* d); - SWIGOCTRT void swig_director_set_self(Director* d, SwigOctType* self); -} -SWIGOCTRT void swig_acquire_ownership(void* vptr); -SWIGOCTRT void swig_acquire_ownership_array(void* vptr); -SWIGOCTRT void swig_acquire_ownership_obj(void* vptr, int own); -#endif - -////////// Declare Octave class: SwigOctMember ////////// - -struct SwigOctMember { - const char* name; - SwigOctFuncPtr method; - SwigOctFuncPtr get_method; - SwigOctFuncPtr set_method; - int flags; // 1=static, 2=global - const char* doc; - bool is_static() const { - return flags & 1; - } - bool is_global() const { - return flags & 2; - } -}; - -////////// Declare Octave class: SwigOctClass ////////// - -struct SwigOctClass { - const char* name; - swig_type_info** type; - int director; - SwigOctFuncPtr constructor; - const char* constructor_doc; - SwigOctFuncPtr destructor; - const SwigOctMember* members; - const char** base_names; - const swig_type_info** base; -}; - -////////// Declare Octave class: SwigOctValueRef ////////// - -struct SwigOctValueRef { - const octave_value_list& ovl; - int j; - SwigOctValueRef(const octave_value_list& _ovl, int _j) - : ovl(_ovl), j(_j) { - } - operator octave_value() const { - return ovl(j); - } - octave_value operator*() const { - return ovl(j); - } -}; - -////////// Declare Octave class: SwigOctType ////////// - -// SwigOctType plays the role of both the shadow class and the class -// representation within Octave, since there is no support for classes. -// -// These should really be decoupled, with the class support added to Octave -// and the shadow class given by an m-file script. That would dramatically -// reduce the runtime complexity, and be more in line w/ other modules. - -class SwigOctType: public octave_base_value -{ - - struct cpp_ptr { - void* ptr; - bool destroyed; - cpp_ptr(void* _ptr) : ptr(_ptr), destroyed(false) { - } - }; - - typedef std::pair < const swig_type_info* , cpp_ptr > type_ptr_pair; - typedef std::pair < const SwigOctMember* , octave_value > member_value_pair; - typedef std::map < std::string, member_value_pair > member_map; - - mutable swig_module_info* module; - const swig_type_info* construct_type; // type of special type object - std::vector < type_ptr_pair > types; // our c++ base classes - int own; // whether we call c++ destructors when we die - member_map members; - bool always_static; - - SwigOctType(const SwigOctType& x); - SwigOctType& operator= (const SwigOctType& rhs); - - bool dispatch_binary_op(const std::string& symbol, const octave_base_value& rhs, octave_value& ret); - bool dispatch_index_op(const std::string& symbol, const octave_value_list& rhs, octave_value_list& ret); - bool dispatch_unary_op(const std::string& symbol, octave_value& ret); - const swig_type_info* find_base(const std::string& name, const swig_type_info* base); - member_value_pair* find_member(const std::string& name, bool insert_if_not_found); - const SwigOctMember* find_member(const swig_type_info* type, const std::string& name); - void load_members(const SwigOctClass* c, member_map& out) const; - void load_members(member_map& out) const; - static octave_value make_value_hack(const octave_base_value& x); - octave_value_list member_deref(member_value_pair* m, const octave_value_list& args); - octave_value_list member_invoke(member_value_pair* m, const octave_value_list& args, int nargout); - -public: - - typedef member_map::const_iterator swig_member_const_iterator; - - SwigOctType(void* _ptr = 0, const swig_type_info* _type = 0, int _own = 0, bool _always_static = false); - ~SwigOctType(); - - octave_value as_value(); - void assign(const std::string& name, const octave_value& ov); - void assign(const std::string& name, const SwigOctMember* m); - void* cast(swig_type_info* type, int* _own, int flags); - octave_base_value* clone() const; - virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const; - virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const; - void decref(); - dim_vector dims(void) const; - static octave_value dispatch_binary_op(const octave_base_value& lhs, const octave_base_value& rhs, const char* op_name); - static bool dispatch_global_op(const std::string& symbol, const octave_value_list& args, octave_value& ret); - static octave_value dispatch_unary_op(const octave_base_value& x, const char* op_name); - octave_base_value* empty_clone() const; - const char* help_text() const; - void incref(); - bool is_defined() const; - virtual bool is_map() const; - virtual bool is_object() const; - bool is_owned() const; - virtual bool is_string() const; - virtual bool load_ascii(std::istream& is); - virtual bool load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt); - virtual string_vector map_keys() const; - virtual octave_map map_value() const; - void merge(SwigOctType& rhs); - void print(std::ostream& os, bool pr_as_read_syntax = false) const; - virtual bool save_ascii(std::ostream& os); - virtual bool save_binary(std::ostream& os, bool& save_as_floats); - virtual std::string string_value(bool force = false) const; - octave_value subsasgn(const std::string& ops, const std::list < octave_value_list > &idx, const octave_value& rhs); - virtual octave_value subsref(const std::string& ops, const std::list < octave_value_list > &idx); - virtual octave_value_list subsref(const std::string& ops, const std::list < octave_value_list > &idx, int nargout); - swig_member_const_iterator swig_members_begin(); - swig_member_const_iterator swig_members_end(); - long swig_this() const; - std::string swig_type_name() const; - -#ifdef HAVE_HDF5 - virtual bool load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug); - virtual bool save_hdf5(hid_t loc_id, const char* name, bool save_as_floats); -#endif - -#ifdef SWIG_DIRECTORS - void director_destroyed(Swig::Director* d); -#endif - -}; - -////////// Declare Octave class: SwigOctType ////////// - -// Octave tries hard to preserve pass-by-value semantics. Eg, assignments -// will call clone() via make_unique() if there is more than one outstanding -// reference to the lhs, and forces the clone's reference count to 1 -// (so you can't just increment your own count and return this). -// -// One way to fix this (without modifying Octave) is to add a level of -// indirection such that clone copies ref-counted pointer and we keep -// pass-by-ref semantics (which are more natural/expected for C++ bindings). -// -// Supporting both pass-by-{ref,value} and toggling via %feature/option -// might be nice. - -class SwigOctRef: public octave_base_value -{ - - DECLARE_OCTAVE_ALLOCATOR; - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; - - SwigOctType* ptr; - -public: - - SwigOctRef(SwigOctType* _ptr = 0); - ~SwigOctRef(); - - octave_base_value* clone() const; - virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const; - virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const; - dim_vector dims(void) const; - octave_base_value* empty_clone() const; - SwigOctType* get_ptr() const; - bool is_defined() const; - virtual bool is_map() const; - virtual bool is_object() const; - virtual bool is_string() const; - virtual bool load_ascii(std::istream& is); - virtual bool load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt); - virtual string_vector map_keys() const; - virtual octave_map map_value() const; - void print(std::ostream& os, bool pr_as_read_syntax = false) const; - virtual bool save_ascii(std::ostream& os); - virtual bool save_binary(std::ostream& os, bool& save_as_floats); - virtual std::string string_value(bool force = false) const; - octave_value subsasgn(const std::string& ops, const std::list < octave_value_list > &idx, const octave_value& rhs); - virtual octave_value subsref(const std::string& ops, const std::list < octave_value_list > &idx); - virtual octave_value_list subsref(const std::string& ops, const std::list < octave_value_list > &idx, int nargout); - -#ifdef HAVE_HDF5 - virtual bool load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug); - virtual bool save_hdf5(hid_t loc_id, const char* name, bool save_as_floats); -#endif - -}; - -////////// Declare Octave class: SwigOctPacked ////////// - -class SwigOctPacked: public octave_base_value -{ - - DECLARE_OCTAVE_ALLOCATOR; - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; - - swig_type_info* type; - std::vector < char > buf; - -public: - - SwigOctPacked(swig_type_info* _type = 0, const void* _buf = 0, size_t _buf_len = 0); - - octave_base_value* clone() const; - bool copy(swig_type_info* outtype, void* ptr, size_t sz) const; - octave_base_value* empty_clone() const; - bool is_defined() const; - virtual bool load_ascii(std::istream& is); - virtual bool load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt); - void print(std::ostream& os, bool pr_as_read_syntax = false) const; - virtual bool save_ascii(std::ostream& os); - virtual bool save_binary(std::ostream& os, bool& save_as_floats); - -#ifdef HAVE_HDF5 - virtual bool load_hdf5(hid_t loc_id, const char* name, bool have_h5giterate_bug); - virtual bool save_hdf5(hid_t loc_id, const char* name, bool save_as_floats); -#endif - -}; - -////////// Declare Octave class: Swig::Director and related classes ////////// - -#ifdef SWIG_DIRECTORS -namespace Swig -{ - - class Director - { - - SwigOctType* self; - bool swig_disowned; - - Director(const Director& x); - Director& operator= (const Director& rhs); - - public: - - Director(void* vptr); - ~Director(); - - void swig_disown(); - SwigOctType* swig_get_self() const; - void swig_set_self(SwigOctType* new_self); - - }; - - struct DirectorTypeMismatchException { - static void raise(const char* msg); - static void raise(const octave_value& ov, const char* msg); - }; - - struct DirectorPureVirtualException { - static void raise(const char* msg); - static void raise(const octave_value& ov, const char* msg); - }; - -} -#endif diff --git a/Lib/octave/octrunfunc.swg b/Lib/octave/octrunfunc.swg deleted file mode 100644 index 6773373b8..000000000 --- a/Lib/octave/octrunfunc.swg +++ /dev/null @@ -1,187 +0,0 @@ -// -// octrunfunc.swg - Octave runtime functions -// - -SWIGOCTRT bool SWIG_Octave_CheckNumArgs(const char* func_name, int num_args, int max_args, int min_args, int varargs) -{ - if (num_args > max_args && !varargs) { - error("function %s takes at most %i arguments", func_name, max_args); - } else if (num_args < min_args) { - error("function %s requires at least %i arguments", func_name, min_args); - } else { - return true; - } - return false; -} - -SWIGOCTRT octave_value_list* SWIG_Octave_AppendOutput(octave_value_list* ovl, const octave_value& ov) -{ - ovl->append(ov); - return ovl; -} - -SWIGOCTRT octave_value SWIG_ErrorType(int code) -{ - switch (code) { - case SWIG_MemoryError: - return "SWIG_MemoryError"; - case SWIG_IOError: - return "SWIG_IOError"; - case SWIG_RuntimeError: - return "SWIG_RuntimeError"; - case SWIG_IndexError: - return "SWIG_IndexError"; - case SWIG_TypeError: - return "SWIG_TypeError"; - case SWIG_DivisionByZero: - return "SWIG_DivisionByZero"; - case SWIG_OverflowError: - return "SWIG_OverflowError"; - case SWIG_SyntaxError: - return "SWIG_SyntaxError"; - case SWIG_ValueError: - return "SWIG_ValueError"; - case SWIG_SystemError: - return "SWIG_SystemError"; - case SWIG_AttributeError: - return "SWIG_AttributeError"; - } - return "SWIG unknown error"; -} - -SWIGOCTRT octave_value SWIG_Error(int code, const char* msg) -{ - octave_value type(SWIG_ErrorType(code)); - std::string r = msg; - r += " (" + type.string_value() + ")"; - error(r.c_str()); - return octave_value(r); -} - -SWIGOCTRT octave_value SWIG_Octave_NewPointerObj(void* ptr, swig_type_info* type, int flags) -{ - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; -#ifdef SWIG_DIRECTORS - Swig::Director* d = Swig::get_rtdir(ptr); - if (d && Swig::swig_director_get_self(d)) { - return Swig::swig_director_get_self(d)->as_value(); - } -#endif - return SWIG_Octave_ValueRef(new SwigOctType(ptr, type, own)); -} - -SWIGOCTRT int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void** ptr, swig_type_info* type, int flags, int* own) -{ - if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) { - ov = ov.cell_value()(0); - } - if (!ov.is_defined() || (ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0)) { - if (ptr) { - *ptr = 0; - } - return SWIG_OK; - } - if (ov.type_id() != SwigOctRef::static_type_id()) { - return SWIG_ERROR; - } - SwigOctRef* osr = static_cast < SwigOctRef*>(ov.internal_rep()); - SwigOctType* ost = osr->get_ptr(); - void* vptr = ost->cast(type, own, flags); - if (!vptr) { - return SWIG_ERROR; - } - if (ptr) { - *ptr = vptr; - } - return SWIG_OK; -} - -SWIGOCTRT octave_value SWIG_Octave_NewPackedObj(void* ptr, size_t sz, swig_type_info* type) -{ - return new SwigOctPacked(type, (char*) ptr, sz); -} - -SWIGOCTRT int SWIG_Octave_ConvertPacked(const octave_value& ov, void* ptr, size_t sz, swig_type_info* type) -{ - if (!ov.is_defined()) { - return SWIG_ERROR; - } - if (ov.type_id() != SwigOctPacked::static_type_id()) { - return SWIG_ERROR; - } - SwigOctPacked* ost = static_cast < SwigOctPacked*>(ov.internal_rep()); - return ost->copy(type, (char*) ptr, sz) ? SWIG_OK : SWIG_ERROR; -} - -SWIGOCTRTINLINE void SWIG_Octave_SetConstant(SwigOctType* module_ns, const std::string& name, const octave_value& ov) -{ - module_ns->assign(name, ov); -} - -SWIGOCTRTINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) -{ - return get_global_value(name, true); -} - -SWIGOCTRT void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) -{ - set_global_value(name, value); -} - -SWIGOCTRT void SWIG_Octave_LinkGlobalValue(std::string name) -{ -#if !SWIG_OCTAVE_PREREQ(3,2,0) - link_to_global_variable(curr_sym_tab->lookup(name, true)); -#else -#if !SWIG_OCTAVE_PREREQ(3,8,0) - symbol_table::varref(name); -#endif - symbol_table::mark_global(name); -#endif -} - -SWIGOCTRT swig_module_info* SWIG_Octave_GetModule(void* clientdata) -{ - octave_value ov = SWIG_Octave_GetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION); - if (!ov.is_defined() || ov.type_id() != SwigOctPacked::static_type_id()) { - return 0; - } - const SwigOctPacked* osp = static_cast < const SwigOctPacked*>(ov.internal_rep()); - swig_module_info* pointer = 0; - osp->copy(0, &pointer, sizeof(swig_module_info*)); - return pointer; -} - -SWIGOCTRT void SWIG_Octave_SetModule(void* clientdata, swig_module_info* pointer) -{ - octave_value ov = new SwigOctPacked(0, &pointer, sizeof(swig_module_info*)); - SWIG_Octave_SetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, ov); -} - -SWIGOCTRT octave_base_value* SWIG_Octave_ValueRef(SwigOctType* ost) -{ - return new SwigOctRef(ost); -} - -SWIGOCTRT SwigOctType* SWIG_Octave_ValueDeref(octave_value ov) -{ - if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) { - ov = ov.cell_value()(0); - } - return SWIG_Octave_ValueDeref(*ov.internal_rep()); -} - -SWIGOCTRT SwigOctType* SWIG_Octave_ValueDeref(const octave_base_value& ov) -{ - if (ov.type_id() != SwigOctRef::static_type_id()) { - return 0; - } - const SwigOctRef* osr = static_cast < const SwigOctRef*>(&ov); - return osr->get_ptr(); -} - -SWIGOCTRT octave_value_list SWIG_Octave_SetImmutable(const octave_value_list& args, int nargout) -{ - error("attempt to set immutable member variable"); - return octave_value_list(); -} diff --git a/Lib/octave/octruninit.swg b/Lib/octave/octruninit.swg deleted file mode 100644 index 86d033af2..000000000 --- a/Lib/octave/octruninit.swg +++ /dev/null @@ -1,422 +0,0 @@ -// -// octruninit.swg - Octave runtime initialisation code -// - -// Forward declaration of module initialisation function -SWIGINTERN bool SWIG_Octave_InitUser(SwigOctType* module_ns); - -////////// Define, register, and install unary and binary operator dispatch functions ////////// - -#define SWIG_Octave_UnaryOp(name) \ - SWIGINTERN octave_value SWIG_Octave_UnaryOp_##name(const octave_base_value &x) { \ - return SwigOctType::dispatch_unary_op(x,#name); \ - } -#define SWIG_Octave_BinaryOp(name) \ - SWIGINTERN octave_value SWIG_Octave_BinaryOp_##name(const octave_base_value&lhs,const octave_base_value &rhs) { \ - return SwigOctType::dispatch_binary_op(lhs,rhs,#name); \ - } - -SWIG_Octave_UnaryOp(not); -SWIG_Octave_UnaryOp(uplus); -SWIG_Octave_UnaryOp(uminus); -SWIG_Octave_UnaryOp(transpose); -SWIG_Octave_UnaryOp(hermitian); -SWIG_Octave_UnaryOp(incr); -SWIG_Octave_UnaryOp(decr); - -SWIG_Octave_BinaryOp(add); -SWIG_Octave_BinaryOp(sub); -SWIG_Octave_BinaryOp(mul); -SWIG_Octave_BinaryOp(div); -SWIG_Octave_BinaryOp(pow); -SWIG_Octave_BinaryOp(ldiv); -SWIG_Octave_BinaryOp(lshift); -SWIG_Octave_BinaryOp(rshift); -SWIG_Octave_BinaryOp(lt); -SWIG_Octave_BinaryOp(le); -SWIG_Octave_BinaryOp(eq); -SWIG_Octave_BinaryOp(ge); -SWIG_Octave_BinaryOp(gt); -SWIG_Octave_BinaryOp(ne); -SWIG_Octave_BinaryOp(el_mul); -SWIG_Octave_BinaryOp(el_div); -SWIG_Octave_BinaryOp(el_pow); -SWIG_Octave_BinaryOp(el_ldiv); -SWIG_Octave_BinaryOp(el_and); -SWIG_Octave_BinaryOp(el_or); - -#define SWIG_Octave_RegisterUnaryOp(name) \ - if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \ - octave_value_typeinfo::register_unary_op(octave_value::op_##name,tid,SWIG_Octave_UnaryOp_##name); -#define SWIG_Octave_RegisterBinaryOp(name) \ - if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \ - octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,SWIG_Octave_BinaryOp_##name); - -SWIGINTERN void SWIG_Octave_InstallUnaryOps(int tid) -{ - SWIG_Octave_RegisterUnaryOp(not); - SWIG_Octave_RegisterUnaryOp(uplus); - SWIG_Octave_RegisterUnaryOp(uminus); - SWIG_Octave_RegisterUnaryOp(transpose); - SWIG_Octave_RegisterUnaryOp(hermitian); - SWIG_Octave_RegisterUnaryOp(incr); - SWIG_Octave_RegisterUnaryOp(decr); -} - -SWIGINTERN void SWIG_Octave_InstallBinaryOps(int tid1, int tid2) -{ - SWIG_Octave_RegisterBinaryOp(add); - SWIG_Octave_RegisterBinaryOp(sub); - SWIG_Octave_RegisterBinaryOp(mul); - SWIG_Octave_RegisterBinaryOp(div); - SWIG_Octave_RegisterBinaryOp(pow); - SWIG_Octave_RegisterBinaryOp(ldiv); - SWIG_Octave_RegisterBinaryOp(lshift); - SWIG_Octave_RegisterBinaryOp(rshift); - SWIG_Octave_RegisterBinaryOp(lt); - SWIG_Octave_RegisterBinaryOp(le); - SWIG_Octave_RegisterBinaryOp(eq); - SWIG_Octave_RegisterBinaryOp(ge); - SWIG_Octave_RegisterBinaryOp(gt); - SWIG_Octave_RegisterBinaryOp(ne); - SWIG_Octave_RegisterBinaryOp(el_mul); - SWIG_Octave_RegisterBinaryOp(el_div); - SWIG_Octave_RegisterBinaryOp(el_pow); - SWIG_Octave_RegisterBinaryOp(el_ldiv); - SWIG_Octave_RegisterBinaryOp(el_and); - SWIG_Octave_RegisterBinaryOp(el_or); -} - -SWIGINTERN void SWIG_Octave_InstallOps(int tid) -{ - // here we assume that tid are conseq integers increasing from zero, and - // that our tid is the last one. might be better to have explicit string - // list of types we should bind to, and use lookup_type to resolve their tid. - SWIG_Octave_InstallUnaryOps(tid); - SWIG_Octave_InstallBinaryOps(tid, tid); - for (int j = 0; j < tid; ++j) { - SWIG_Octave_InstallBinaryOps(j, tid); - SWIG_Octave_InstallBinaryOps(tid, j); - } -} - -////////// Internal functions for loading/installing modules ////////// - -SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) -{ - bool retn; - { -#if !SWIG_OCTAVE_PREREQ(3,3,50) - unwind_protect::begin_frame("SWIG_Octave_LoadModule"); - unwind_protect_int(error_state); - unwind_protect_int(warning_state); - unwind_protect_bool(discard_error_messages); - unwind_protect_bool(discard_warning_messages); -#else - unwind_protect frame; - frame.protect_var(error_state); - frame.protect_var(warning_state); - frame.protect_var(discard_error_messages); - frame.protect_var(discard_warning_messages); -#endif - error_state = 0; - warning_state = 0; - discard_error_messages = true; - discard_warning_messages = true; - feval(name, octave_value_list(), 0); - retn = (error_state == 0); -#if !SWIG_OCTAVE_PREREQ(3,3,50) - unwind_protect::run_frame("SWIG_Octave_LoadModule"); -#endif - } - if (!retn) { - error(SWIG_name_d ": could not load module `%s'", name.c_str()); - } - return retn; -} - -SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function* octloadfcn, std::string name) -{ - bool retn; - { -#if !SWIG_OCTAVE_PREREQ(3,3,50) - unwind_protect::begin_frame("SWIG_Octave_InstallFunction"); - unwind_protect_int(error_state); - unwind_protect_int(warning_state); - unwind_protect_bool(discard_error_messages); - unwind_protect_bool(discard_warning_messages); -#else - unwind_protect frame; - frame.protect_var(error_state); - frame.protect_var(warning_state); - frame.protect_var(discard_error_messages); - frame.protect_var(discard_warning_messages); -#endif - error_state = 0; - warning_state = 0; - discard_error_messages = true; - discard_warning_messages = true; - octave_value_list args; - args.append(name); - args.append(octloadfcn->fcn_file_name()); - error_state = 0; - feval("autoload", args, 0); - retn = (error_state == 0); -#if !SWIG_OCTAVE_PREREQ(3,3,50) - unwind_protect::run_frame("SWIG_Octave_InstallFunction"); -#endif - } - if (!retn) { - error(SWIG_name_d ": could not load function `%s'", name.c_str()); - } - return retn; -} - -////////// Public module function: swig_type() ////////// - -static const char* const swig_type_usage = "-*- texinfo -*- \n\ -@deftypefn {Loadable Function} {} swig_type(@var{swigref})\n\ -Return the underlying C/C++ type name of a SWIG-wrapped object.\n\ -@end deftypefn"; - -DEFUN_DLD(swig_type, args, nargout, swig_type_usage) -{ - if (args.length() != 1) { - error("swig_type: must be called with only a single object"); - return octave_value_list(); - } - SwigOctType* ost = SWIG_Octave_ValueDeref(args(0)); - if (!ost) { - error("swig_type: object is not a swig_ref"); - return octave_value_list(); - } - return octave_value(ost->swig_type_name()); -} - -////////// Public module function: swig_typequery() ////////// - -static const char* const swig_typequery_usage = "-*- texinfo -*- \n\ -@deftypefn {Loadable Function} {} swig_typequery(@var{string})\n\ -Return @var{string} if it is a recognised SWIG-wrapped C/C++ type name;\n\ -otherwise return `<unknown>'.\n\ -@end deftypefn"; - -DEFUN_DLD(swig_typequery, args, nargout, swig_typequery_usage) -{ - if (args.length() != 1 || !args(0).is_string()) { - error("swig_typequery: must be called with single string argument"); - return octave_value_list(); - } - swig_module_info* module = SWIG_GetModule(0); - swig_type_info* type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str()); - if (!type) { - return octave_value("<unknown>"); - } - return octave_value(type->name); -} - -////////// Public module function: swig_this() ////////// - -static const char* const swig_this_usage = "-*- texinfo -*- \n\ -@deftypefn {Loadable Function} {} swig_this(@var{swigref})\n\ -Return the underlying C/C++ pointer of a SWIG-wrapped object.\n\ -@end deftypefn"; - -DEFUN_DLD(swig_this, args, nargout, swig_this_usage) -{ - if (args.length() != 1) { - error("swig_this: must be called with only a single object"); - return octave_value_list(); - } - if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0) { - return octave_value(octave_uint64(0)); - } - SwigOctType* ost = SWIG_Octave_ValueDeref(args(0)); - if (!ost) { - error("swig_this: object is not a swig_ref"); - return octave_value_list(); - } - return octave_value(octave_uint64((unsigned long long) ost->swig_this())); -} - -////////// Public module function: subclass() ////////// - -static const char* const subclass_usage = "-*- texinfo -*- \n\ -@deftypefn {Loadable Function} {} subclass()\n\ -@deftypefnx{Loadable Function} {} subclass(@var{swigclass}, @var{name}, @var{fcn}, @dots{})\n\ -Subclass a C++ class from within Octave, and provide implementations of its virtual methods.\n\ -\n\ -See the SWIG manual for usage examples.\n\ -@end deftypefn"; - -DEFUN_DLD(subclass, args, nargout, subclass_usage) -{ - SwigOctType* top = new SwigOctType; - for (int j = 0; j < args.length(); ++j) { - if (args(j).type_id() == SwigOctRef::static_type_id()) { - SwigOctRef* osr = static_cast < SwigOctRef*>(args(j).internal_rep()); - SwigOctType* ost = osr->get_ptr(); - if (!ost->is_owned()) { - error("subclass: cannot subclass object not constructed on octave side"); - return octave_value_list(); - } - top->merge(*ost); - } else if (args(j).is_function_handle()) { - top->assign(args(j).fcn_handle_value()->fcn_name(), args(j)); - } else if (args(j).is_string()) { - if (j + 1 >= args.length()) { - error("subclass: member assignments must be of string,value form"); - return octave_value_list(); - } - top->assign(args(j).string_value(), args(j + 1)); - ++j; - } else { - error("subclass: invalid arguments to subclass()"); - return octave_value_list(); - } - } - return octave_value(SWIG_Octave_ValueRef(top)); -} - -////////// Public function which loads the Octave module ////////// - -static const char* const SWIG_name_usage = "-*- texinfo -*- \n\ -@deftypefn {Loadable Module} {} " SWIG_name_d "\n\ -Loads the SWIG-generated module `" SWIG_name_d "'.\n\ -@end deftypefn"; - -DEFUN_DLD(SWIG_name, args, nargout, SWIG_name_usage) -{ - - static SwigOctType* module_ns = 0; - - // workaround to prevent octave seg-faulting on exit: set Octave exit function - // octave_exit to _Exit, which exits immediately without trying to cleanup memory. - // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in - // version 3.4.* and above. can be turned off with macro definition. -#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if SWIG_OCTAVE_PREREQ(3,2,0) && !SWIG_OCTAVE_PREREQ(3,4,1) - octave_exit = ::_Exit; -#endif -#endif - - // check for no input and output args - if (args.length() != 0 || nargout != 0) { - print_usage(); - return octave_value_list(); - } - - // create module on first function call - if (!module_ns) { - - // workaround bug in octave where installing global variable of custom type and then - // exiting without explicitly clearing the variable causes octave to segfault. -#if SWIG_OCTAVE_PREREQ(3,2,0) - octave_value_list eval_args; - eval_args.append("base"); - eval_args.append("function __swig_atexit__; " - " if mislocked() " - " clear -all; " - " else " - " mlock(); " - " endif; " - "endfunction; " - "__swig_atexit__; " - "atexit(\"__swig_atexit__\", false); " - "atexit(\"__swig_atexit__\")"); - feval("evalin", eval_args, 0); -#endif - - SwigOctRef::register_type(); - SwigOctPacked::register_type(); - SWIG_InitializeModule(0); - SWIG_PropagateClientData(); - - octave_function* me = octave_call_stack::current(); - - if (!SWIG_Octave_InstallFunction(me, "swig_type")) { - return octave_value_list(); - } - if (!SWIG_Octave_InstallFunction(me, "swig_typequery")) { - return octave_value_list(); - } - if (!SWIG_Octave_InstallFunction(me, "swig_this")) { - return octave_value_list(); - } - if (!SWIG_Octave_InstallFunction(me, "subclass")) { - return octave_value_list(); - } - - SwigOctType* cvar_ns = 0; - if (std::string(SWIG_global_name) != ".") { - cvar_ns = new SwigOctType; - for (int j = 0; swig_globals[j].name; ++j) - if (swig_globals[j].get_method) { - cvar_ns->assign(swig_globals[j].name, &swig_globals[j]); - } - } - - module_ns = new SwigOctType(0, 0, 0, true); - if (std::string(SWIG_global_name) != ".") { - module_ns->assign(SWIG_global_name, SWIG_Octave_ValueRef(cvar_ns)); - } else { - for (int j = 0; swig_globals[j].name; ++j) - if (swig_globals[j].get_method) { - module_ns->assign(swig_globals[j].name, &swig_globals[j]); - } - } - for (int j = 0; swig_globals[j].name; ++j) - if (swig_globals[j].method) { - module_ns->assign(swig_globals[j].name, &swig_globals[j]); - } - - // * need better solution here; swig_type -> octave_class mapping is - // * really n-to-1, in some cases such as template partial spec, etc. - // * see failing tests. - for (int j = 0; swig_types[j]; ++j) - if (swig_types[j]->clientdata) { - SwigOctClass* c = (SwigOctClass*) swig_types[j]->clientdata; - module_ns->assign(c->name, - SWIG_Octave_ValueRef - (new SwigOctType(0, swig_types[j]))); - } - - if (!SWIG_Octave_InitUser(module_ns)) { - delete module_ns; - module_ns = 0; - return octave_value_list(); - } - - SWIG_Octave_InstallOps(SwigOctRef::static_type_id()); - - SwigOctType::swig_member_const_iterator mb; - for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { - if (mb->second.first && mb->second.first->method) { - if (!SWIG_Octave_InstallFunction(me, mb->first)) { - return octave_value_list(); - } - } - } - -#if !SWIG_OCTAVE_PREREQ(3,2,0) - mlock(me->name()); -#else - mlock(); -#endif - - } - - SwigOctType::swig_member_const_iterator mb; - for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { - if (mb->second.second.is_defined()) { - SWIG_Octave_SetGlobalValue(mb->first, mb->second.second); - SWIG_Octave_LinkGlobalValue(mb->first); - } - } - - SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value()); - SWIG_Octave_LinkGlobalValue(SWIG_name_d); - - return octave_value_list(); - -} diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index cdcb66c30..fbf2007f6 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,20 +1,323 @@ -// -// octruntime.swg - Octave runtime code -// +%insert(runtime) %{ +#include <cstdlib> +#include <iostream> +#include <octave/oct.h> +#include <octave/Cell.h> +#include <octave/dynamic-ld.h> +#include <octave/oct-env.h> +#include <octave/oct-map.h> +#include <octave/ov-fcn-handle.h> +#include <octave/parse.h> +#include <octave/toplev.h> +#include <octave/unwind-prot.h> +%} -// Insert standard SWIG runtime code -%insert("runtime") "swigrun.swg"; -%insert("runtime") "swigerrors.swg"; -%insert("initbeforefunc") "swiginit.swg" +%insert(runtime) "swigrun.swg"; +%insert(runtime) "swigerrors.swg"; +%insert(runtime) "octrun.swg"; -// Declarations of Octave runtime code -%insert("runtime") "octrundecl.swg"; +%insert(initbeforefunc) "swiginit.swg" -// Octave runtime functions -%insert("runtime") "octrunfunc.swg" +%insert(initbeforefunc) %{ -// Octave runtime classes -%insert("runtime") "octrunclass.swg" +static bool SWIG_init_user(octave_swig_type* module_ns); -// Octave runtime initialisation code -%insert("initbeforefunc") "octruninit.swg" +SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { + bool retn; + { +#if !SWIG_OCTAVE_PREREQ(3,3,50) + unwind_protect::begin_frame("SWIG_Octave_LoadModule"); + unwind_protect_int(error_state); + unwind_protect_int(warning_state); + unwind_protect_bool(discard_error_messages); + unwind_protect_bool(discard_warning_messages); +#else + unwind_protect frame; + frame.protect_var(error_state); + frame.protect_var(warning_state); + frame.protect_var(discard_error_messages); + frame.protect_var(discard_warning_messages); +#endif + error_state = 0; + warning_state = 0; + discard_error_messages = true; + discard_warning_messages = true; + feval(name, octave_value_list(), 0); + retn = (error_state == 0); +#if !SWIG_OCTAVE_PREREQ(3,3,50) + unwind_protect::run_frame("SWIG_Octave_LoadModule"); +#endif + } + if (!retn) { + error(SWIG_name_d ": could not load module `%s'", name.c_str()); + } + return retn; +} + +SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { + bool retn; + { +#if !SWIG_OCTAVE_PREREQ(3,3,50) + unwind_protect::begin_frame("SWIG_Octave_InstallFunction"); + unwind_protect_int(error_state); + unwind_protect_int(warning_state); + unwind_protect_bool(discard_error_messages); + unwind_protect_bool(discard_warning_messages); +#else + unwind_protect frame; + frame.protect_var(error_state); + frame.protect_var(warning_state); + frame.protect_var(discard_error_messages); + frame.protect_var(discard_warning_messages); +#endif + error_state = 0; + warning_state = 0; + discard_error_messages = true; + discard_warning_messages = true; + octave_value_list args; + args.append(name); + args.append(octloadfcn->fcn_file_name()); + error_state = 0; + feval("autoload", args, 0); + retn = (error_state == 0); +#if !SWIG_OCTAVE_PREREQ(3,3,50) + unwind_protect::run_frame("SWIG_Octave_InstallFunction"); +#endif + } + if (!retn) { + error(SWIG_name_d ": could not load function `%s'", name.c_str()); + } + return retn; +} + +static const char *const subclass_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} subclass()\n\ +@deftypefnx{Loadable Function} {} subclass(@var{swigclass}, @var{name}, @var{fcn}, @dots{})\n\ +Subclass a C++ class from within Octave, and provide implementations of its virtual methods.\n\ +\n\ +See the SWIG manual for usage examples.\n\ +@end deftypefn"; + +DEFUN_DLD( subclass, args, nargout, subclass_usage ) { + octave_swig_type *top = new octave_swig_type; + for (int j = 0; j < args.length(); ++j) { + if (args(j).type_id() == octave_swig_ref::static_type_id()) { + octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep()); + octave_swig_type *ost = osr->get_ptr(); + if (!ost->is_owned()) { + error("subclass: cannot subclass object not constructed on octave side"); + return octave_value_list(); + } + top->merge(*ost); + } else if (args(j).is_function_handle()) { + top->assign(args(j).fcn_handle_value()->fcn_name(), args(j)); + } else if (args(j).is_string()) { + if (j + 1 >= args.length()) { + error("subclass: member assignments must be of string,value form"); + return octave_value_list(); + } + top->assign(args(j).string_value(), args(j + 1)); + ++j; + } else { + error("subclass: invalid arguments to subclass()"); + return octave_value_list(); + } + } + return octave_value(Swig::swig_value_ref(top)); +} + +static const char *const swig_type_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_type(@var{swigref})\n\ +Return the underlying C/C++ type name of a SWIG-wrapped object.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_type, args, nargout, swig_type_usage ) { + if (args.length() != 1) { + error("swig_type: must be called with only a single object"); + return octave_value_list(); + } + octave_swig_type *ost = Swig::swig_value_deref(args(0)); + if (!ost) { + error("swig_type: object is not a swig_ref"); + return octave_value_list(); + } + return octave_value(ost->swig_type_name()); +} + +static const char *const swig_typequery_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_typequery(@var{string})\n\ +Return @var{string} if it is a recognised SWIG-wrapped C/C++ type name;\n\ +otherwise return `<unknown>'.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_typequery, args, nargout, swig_typequery_usage ) { + if (args.length() != 1 || !args(0).is_string()) { + error("swig_typequery: must be called with single string argument"); + return octave_value_list(); + } + swig_module_info *module = SWIG_GetModule(0); + swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str()); + if (!type) + return octave_value("<unknown>"); + return octave_value(type->name); +} + +static const char *const swig_this_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_this(@var{swigref})\n\ +Return the underlying C/C++ pointer of a SWIG-wrapped object.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { + if (args.length() != 1) { + error("swig_this: must be called with only a single object"); + return octave_value_list(); + } + if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0) + return octave_value(octave_uint64(0)); + octave_swig_type *ost = Swig::swig_value_deref(args(0)); + if (!ost) { + error("swig_this: object is not a swig_ref"); + return octave_value_list(); + } + return octave_value(octave_uint64((unsigned long long) ost->swig_this())); +} + +static const char *const SWIG_name_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Module} {} " SWIG_name_d "\n\ +Loads the SWIG-generated module `" SWIG_name_d "'.\n\ +@end deftypefn"; + +DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { + + static octave_swig_type* module_ns = 0; + + // workaround to prevent octave seg-faulting on exit: set Octave exit function + // octave_exit to _Exit, which exits immediately without trying to cleanup memory. + // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in + // version 3.4.* and above. can be turned off with macro definition. +#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK +#if SWIG_OCTAVE_PREREQ(3,2,0) && !SWIG_OCTAVE_PREREQ(3,4,1) + octave_exit = ::_Exit; +#endif +#endif + + // check for no input and output args + if (args.length() != 0 || nargout != 0) { + print_usage(); + return octave_value_list(); + } + + // create module on first function call + if (!module_ns) { + + // workaround bug in octave where installing global variable of custom type and then + // exiting without explicitly clearing the variable causes octave to segfault. +#if SWIG_OCTAVE_PREREQ(3,2,0) + octave_value_list eval_args; + eval_args.append("base"); + eval_args.append("function __swig_atexit__; " + " if mislocked() " + " clear -all; " + " else " + " mlock(); " + " endif; " + "endfunction; " + "__swig_atexit__; " + "atexit(\"__swig_atexit__\", false); " + "atexit(\"__swig_atexit__\")"); + feval("evalin", eval_args, 0); +#endif + + octave_swig_ref::register_type(); + octave_swig_packed::register_type(); + SWIG_InitializeModule(0); + SWIG_PropagateClientData(); + + octave_function *me = octave_call_stack::current(); + + if (!SWIG_Octave_InstallFunction(me, "swig_type")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "swig_typequery")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "swig_this")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "subclass")) { + return octave_value_list(); + } + + octave_swig_type* cvar_ns=0; + if (std::string(SWIG_global_name) != ".") { + cvar_ns=new octave_swig_type; + for (int j=0;swig_globals[j].name;++j) + if (swig_globals[j].get_method) + cvar_ns->assign(swig_globals[j].name,&swig_globals[j]); + } + + module_ns=new octave_swig_type(0, 0, 0, true); + if (std::string(SWIG_global_name) != ".") { + module_ns->assign(SWIG_global_name,Swig::swig_value_ref(cvar_ns)); + } + else { + for (int j=0;swig_globals[j].name;++j) + if (swig_globals[j].get_method) + module_ns->assign(swig_globals[j].name,&swig_globals[j]); + } + for (int j=0;swig_globals[j].name;++j) + if (swig_globals[j].method) + module_ns->assign(swig_globals[j].name,&swig_globals[j]); + + // * need better solution here; swig_type -> octave_class mapping is + // * really n-to-1, in some cases such as template partial spec, etc. + // * see failing tests. + for (int j=0;swig_types[j];++j) + if (swig_types[j]->clientdata) { + swig_octave_class* c=(swig_octave_class*)swig_types[j]->clientdata; + module_ns->assign(c->name, + Swig::swig_value_ref + (new octave_swig_type(0,swig_types[j]))); + } + + if (!SWIG_init_user(module_ns)) { + delete module_ns; + module_ns=0; + return octave_value_list(); + } + + SWIG_InstallOps(octave_swig_ref::static_type_id()); + + octave_swig_type::swig_member_const_iterator mb; + for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { + if (mb->second.first && mb->second.first->method) { + if (!SWIG_Octave_InstallFunction(me, mb->first)) { + return octave_value_list(); + } + } + } + +#if !SWIG_OCTAVE_PREREQ(3,2,0) + mlock(me->name()); +#else + mlock(); +#endif + + } + + octave_swig_type::swig_member_const_iterator mb; + for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { + if (mb->second.second.is_defined()) { + SWIG_Octave_SetGlobalValue(mb->first, mb->second.second); + SWIG_Octave_LinkGlobalValue(mb->first); + } + } + + SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value()); + SWIG_Octave_LinkGlobalValue(SWIG_name_d); + + return octave_value_list(); + +} + +%} diff --git a/Lib/octave/octstdcommon.swg b/Lib/octave/octstdcommon.swg index 56379ed73..96923f40a 100644 --- a/Lib/octave/octstdcommon.swg +++ b/Lib/octave/octstdcommon.swg @@ -1,258 +1,226 @@ -// -// octstdcommon.swg - Octave common STL code -// - -%fragment("StdTraits", "header", fragment = "StdTraitsCommon") +%fragment("StdTraits","header",fragment="StdTraitsCommon") { +namespace swig { +// Traits that provides the from method + template <class Type> struct traits_from_ptr { + static octave_value from(Type *val, int owner = 0) { + return SWIG_NewPointerObj(val, type_info<Type>(), owner); + } + }; - namespace swig - { - - // Traits that provides the from method - template <class Type> struct traits_from_ptr { - static octave_value from(Type* val, int owner = 0) { - return SWIG_NewPointerObj(val, type_info<Type>(), owner); - } - }; - - template <class Type> struct traits_from { - static octave_value from(const Type& val) { - return traits_from_ptr<Type>::from(new Type(val), 1); - } - }; + template <class Type> struct traits_from { + static octave_value from(const Type& val) { + return traits_from_ptr<Type>::from(new Type(val), 1); + } + }; - template <class Type> struct traits_from<Type*> { - static octave_value from(Type* val) { - return traits_from_ptr<Type>::from(val, 0); - } - }; + template <class Type> struct traits_from<Type *> { + static octave_value from(Type* val) { + return traits_from_ptr<Type>::from(val, 0); + } + }; - template <class Type> struct traits_from<const Type*> { - static octave_value from(const Type* val) { - return traits_from_ptr<Type>::from(const_cast<Type*>(val), 0); - } - }; + template <class Type> struct traits_from<const Type *> { + static octave_value from(const Type* val) { + return traits_from_ptr<Type>::from(const_cast<Type*>(val), 0); + } + }; - template <class Type> - inline octave_value from(const Type& val) - { - return traits_from<Type>::from(val); - } + template <class Type> + inline octave_value from(const Type& val) { + return traits_from<Type>::from(val); + } - template <class Type> - inline octave_value from_ptr(Type* val, int owner) - { - return traits_from_ptr<Type>::from(val, owner); - } + template <class Type> + inline octave_value from_ptr(Type* val, int owner) { + return traits_from_ptr<Type>::from(val, owner); + } // Traits that provides the asval/as/check method - template <class Type> - struct traits_asptr { - static int asptr(const octave_value& obj, Type** val) { - Type* p; - int res = SWIG_ConvertPtr(obj, (void**) &p, type_info<Type>(), 0); - if (SWIG_IsOK(res)) { - if (val) { - *val = p; - } - } - return res; + template <class Type> + struct traits_asptr { + static int asptr(const octave_value& obj, Type **val) { + Type *p; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; } - }; - - template <class Type> - inline int asptr(const octave_value& obj, Type** vptr) - { - return traits_asptr<Type>::asptr(obj, vptr); + return res; } + }; - template <class Type> - struct traits_asval { - static int asval(const octave_value& obj, Type* val) { - if (val) { - Type* p = 0; - int res = traits_asptr<Type>::asptr(obj, &p); - if (!SWIG_IsOK(res)) { - return res; - } - if (p) { - typedef typename noconst_traits<Type>::noconst_type noconst_type; - * (const_cast<noconst_type*>(val)) = *p; - if (SWIG_IsNewObj(res)) { - %delete(p); - res = SWIG_DelNewMask(res); - } - return res; - } else { - return SWIG_ERROR; - } - } else { - return traits_asptr<Type>::asptr(obj, (Type**)(0)); - } - } - }; + template <class Type> + inline int asptr(const octave_value& obj, Type **vptr) { + return traits_asptr<Type>::asptr(obj, vptr); + } - template <class Type> struct traits_asval<Type*> { - static int asval(const octave_value& obj, Type** val) { - if (val) { - typedef typename noconst_traits<Type>::noconst_type noconst_type; - noconst_type* p = 0; - int res = traits_asptr<noconst_type>::asptr(obj, &p); - if (SWIG_IsOK(res)) { - * (const_cast<noconst_type**>(val)) = p; - } - return res; - } else { - return traits_asptr<Type>::asptr(obj, (Type**)(0)); - } + template <class Type> + struct traits_asval { + static int asval(const octave_value& obj, Type *val) { + if (val) { + Type *p = 0; + int res = traits_asptr<Type>::asptr(obj, &p); + if (!SWIG_IsOK(res)) return res; + if (p) { + typedef typename noconst_traits<Type>::noconst_type noconst_type; + *(const_cast<noconst_type*>(val)) = *p; + if (SWIG_IsNewObj(res)){ + %delete(p); + res = SWIG_DelNewMask(res); + } + return res; + } else { + return SWIG_ERROR; + } + } else { + return traits_asptr<Type>::asptr(obj, (Type **)(0)); } - }; - - template <class Type> - inline int asval(const octave_value& obj, Type* val) - { - return traits_asval<Type>::asval(obj, val); } - - template <class Type> - struct traits_as<Type, value_category> { - static Type as(const octave_value& obj, bool throw_error) { - Type v; - int res = asval(obj, &v); - if (!obj.is_defined() || !SWIG_IsOK(res)) { - if (!SWIG_Octave_ErrorOccurred()) { - %type_error(swig::type_name<Type>()); - } - if (throw_error) { - throw std::invalid_argument("bad type"); - } - } - return v; + }; + + template <class Type> struct traits_asval<Type*> { + static int asval(const octave_value& obj, Type **val) { + if (val) { + typedef typename noconst_traits<Type>::noconst_type noconst_type; + noconst_type *p = 0; + int res = traits_asptr<noconst_type>::asptr(obj, &p); + if (SWIG_IsOK(res)) { + *(const_cast<noconst_type**>(val)) = p; + } + return res; + } else { + return traits_asptr<Type>::asptr(obj, (Type **)(0)); } - }; + } + }; + + template <class Type> + inline int asval(const octave_value& obj, Type *val) { + return traits_asval<Type>::asval(obj, val); + } - template <class Type> - struct traits_as<Type, pointer_category> { - static Type as(const octave_value& obj, bool throw_error) { - Type* v = 0; - int res = traits_asptr<Type>::asptr(obj, &v); - if (SWIG_IsOK(res) && v) { - if (SWIG_IsNewObj(res)) { - Type r(*v); - %delete(v); - return r; - } else { - return *v; - } - } else { - // Uninitialized return value, no Type() constructor required. - static Type* v_def = (Type*) malloc(sizeof(Type)); - if (!SWIG_Octave_ErrorOccurred()) { - %type_error(swig::type_name<Type>()); - } - if (throw_error) { - throw std::invalid_argument("bad type"); - } - memset(v_def, 0, sizeof(Type)); - return *v_def; - } + template <class Type> + struct traits_as<Type, value_category> { + static Type as(const octave_value& obj, bool throw_error) { + Type v; + int res = asval(obj, &v); + if (!obj.is_defined() || !SWIG_IsOK(res)) { + if (!Octave_Error_Occurred()) { + %type_error(swig::type_name<Type>()); + } + if (throw_error) throw std::invalid_argument("bad type"); } - }; - - template <class Type> - struct traits_as<Type*, pointer_category> { - static Type* as(const octave_value& obj, bool throw_error) { - Type* v = 0; - int res = traits_asptr<Type>::asptr(obj, &v); - if (SWIG_IsOK(res)) { - return v; - } else { - if (!SWIG_Octave_ErrorOccurred()) { - %type_error(swig::type_name<Type>()); - } - if (throw_error) { - throw std::invalid_argument("bad type"); - } - return 0; - } + return v; + } + }; + + template <class Type> + struct traits_as<Type, pointer_category> { + static Type as(const octave_value& obj, bool throw_error) { + Type *v = 0; + int res = traits_asptr<Type>::asptr(obj, &v); + if (SWIG_IsOK(res) && v) { + if (SWIG_IsNewObj(res)) { + Type r(*v); + %delete(v); + return r; + } else { + return *v; + } + } else { + // Uninitialized return value, no Type() constructor required. + static Type *v_def = (Type*) malloc(sizeof(Type)); + if (!Octave_Error_Occurred()) { + %type_error(swig::type_name<Type>()); + } + if (throw_error) throw std::invalid_argument("bad type"); + memset(v_def,0,sizeof(Type)); + return *v_def; } - }; - - template <class Type> - inline Type as(const octave_value& obj, bool te = false) - { - return traits_as<Type, typename traits<Type>::category>::as(obj, te); } - - template <class Type> - struct traits_check<Type, value_category> { - static bool check(const octave_value& obj) { - int res = asval(obj, (Type*)(0)); - return SWIG_IsOK(res) ? true : false; + }; + + template <class Type> + struct traits_as<Type*, pointer_category> { + static Type* as(const octave_value& obj, bool throw_error) { + Type *v = 0; + int res = traits_asptr<Type>::asptr(obj, &v); + if (SWIG_IsOK(res)) { + return v; + } else { + if (!Octave_Error_Occurred()) { + %type_error(swig::type_name<Type>()); + } + if (throw_error) throw std::invalid_argument("bad type"); + return 0; } - }; + } + }; + + template <class Type> + inline Type as(const octave_value& obj, bool te = false) { + return traits_as<Type, typename traits<Type>::category>::as(obj, te); + } - template <class Type> - struct traits_check<Type, pointer_category> { - static bool check(const octave_value& obj) { - int res = asptr(obj, (Type**)(0)); - return SWIG_IsOK(res) ? true : false; - } - }; + template <class Type> + struct traits_check<Type, value_category> { + static bool check(const octave_value& obj) { + int res = asval(obj, (Type *)(0)); + return SWIG_IsOK(res) ? true : false; + } + }; - template <class Type> - inline bool check(const octave_value& obj) - { - return traits_check<Type, typename traits<Type>::category>::check(obj); + template <class Type> + struct traits_check<Type, pointer_category> { + static bool check(const octave_value& obj) { + int res = asptr(obj, (Type **)(0)); + return SWIG_IsOK(res) ? true : false; } + }; + template <class Type> + inline bool check(const octave_value& obj) { + return traits_check<Type, typename traits<Type>::category>::check(obj); } - +} } -%define %specialize_std_container(Type, Check, As, From) -%header %{ - - namespace swig { - - template <> - struct traits_asval<Type > { - typedef Type value_type; - static int asval(const octave_value& obj, value_type* val) { - if (Check(obj)) { - if (val) { - *val = As(obj); - } - return SWIG_OK; - } - return SWIG_ERROR; - } - }; - - template <> - struct traits_from<Type > { - typedef Type value_type; - static octave_value from(const value_type& val) { - return From(val); - } - }; - - template <> - struct traits_check<Type, value_category> { - static int check(const octave_value& obj) { - int res = Check(obj); - return obj && res ? res : 0; +%define %specialize_std_container(Type,Check,As,From) +%{ +namespace swig { + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(const octave_value& obj, value_type *val) { + if (Check(obj)) { + if (val) *val = As(obj); + return SWIG_OK; } - }; - - } + return SWIG_ERROR; + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static octave_value from(const value_type& val) { + return From(val); + } + }; + template <> + struct traits_check<Type, value_category> { + static int check(const octave_value& obj) { + int res = Check(obj); + return obj && res ? res : 0; + } + }; +} %} %enddef + #define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) + diff --git a/Lib/octave/octtypemaps.swg b/Lib/octave/octtypemaps.swg index b241ad400..4acf8e076 100644 --- a/Lib/octave/octtypemaps.swg +++ b/Lib/octave/octtypemaps.swg @@ -1,45 +1,46 @@ -// -// octtypemaps.swg - Octave typemaps -// // Include fundamental fragment definitions %include <typemaps/fragments.swg> -// Look for user fragments file +// Look for user fragments file. %include <octfragments.swg> // Octave fragments for primitive types %include <octprimtypes.swg> +// Octave fragments for char* strings +//%include <octstrings.swg> + + #ifndef SWIG_DIRECTOR_TYPEMAPS #define SWIG_DIRECTOR_TYPEMAPS #endif // Octave types -#define SWIG_Object octave_value -#define VOID_Object octave_value() +#define SWIG_Object octave_value +#define VOID_Object octave_value() +/* // Octave allows implicit conversion -//#define %implicitconv_flag $implicitconv +#define %implicitconv_flag $implicitconv +*/ -// Append output -#define SWIG_AppendOutput(result, obj) SWIG_Octave_AppendOutput(result, obj) +// append output +#define SWIG_AppendOutput(result, obj) SWIG_Octave_AppendOutput(result, obj) -// Set constant -#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj) +// set constant +#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj) -// Raise errors -#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE) -#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc) +// raise +#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE) +#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc) // Include the unified typemap library %include <typemaps/swigtypemaps.swg> -// Typechecks for Octave types %typecheck(SWIG_TYPECHECK_SWIGOBJECT) SWIG_Object "$1 = (*$input).is_defined();"; %typecheck(SWIG_TYPECHECK_SWIGOBJECT) octave_value_list "$1 = true;"; -// Typemaps for Octave types %typemap(in) (octave_value_list varargs,...) { for (int j=$argnum-1;j<args.length();++j) $1.append(args(j)); @@ -47,6 +48,7 @@ %typecheck(2000) (octave_value_list varargs,...) { $1=1; } + %typemap(in) (const octave_value_list& varargs,...) (octave_value_list tmp) { for (int j=$argnum-1;j<args.length();++j) tmp.append(args(j)); @@ -55,6 +57,7 @@ %typecheck(2000) (const octave_value_list& varargs,...) { $1=1; } + %typemap(out) octave_value_list { _outp->append($1); } @@ -67,3 +70,23 @@ %typemap(out,noblock=1) Cell { $result=$1; } + +/* +// Smart Pointers +%typemap(out,noblock=1) const SWIGTYPE & SMARTPOINTER { + $result = SWIG_NewPointerObj(%new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags); +} + +%typemap(ret) const SWIGTYPE & SMARTPOINTER, SWIGTYPE SMARTPOINTER { + octave_swig_type* lobj=Swig::swig_value_deref($result); + if (lobj) { + std::list<octave_value_list> idx; + idx.push_back(octave_value("__deref__")); + idx.push_back(octave_value_list()); + octave_value_list ovl(lobj->subsref(".(",idx)); + octave_swig_type* robj=ovl.length()>=1?Swig::swig_value_deref(ovl(0)):0; + if (robj && !error_state) + lobj->append(robj); + } +} +*/ diff --git a/Lib/octave/octuserdir.swg b/Lib/octave/octuserdir.swg index 164e08a36..ebb11b3a5 100644 --- a/Lib/octave/octuserdir.swg +++ b/Lib/octave/octuserdir.swg @@ -1,65 +1,70 @@ -// -// octuserdir.swg - Octave special user directives -// +/* ------------------------------------------------------------------------- + * Special user directives + * ------------------------------------------------------------------------- */ -// Document string directive -#define %docstring %feature("docstring") +/* ------------------------------------------------------------------------- */ +/* + Implicit Conversion using the C++ constructor mechanism +*/ -// Implicit conversion using the C++ constructor mechanism -#define %implicitconv %feature("implicitconv") +#define %implicitconv %feature("implicitconv") #define %noimplicitconv %feature("implicitconv", "0") #define %clearimplicitconv %feature("implicitconv", "") -// %extend_smart_pointer: extend the smart pointer support. -// -// For example, if you have a smart pointer as: -// -// template <class Type> class RCPtr { -// public: -// ... -// RCPtr(Type *p); -// Type * operator->() const; -// ... -// }; -// -// you use the %extend_smart_pointer directive as: -// -// %extend_smart_pointer(RCPtr<A>); -// %template(RCPtr_A) RCPtr<A>; -// -// then, if you have something like: -// -// RCPtr<A> make_ptr(); -// int foo(A *); -// -// you can do the following: -// -// a = make_ptr(); -// b = foo(a); -// -// ie, swig will accept a RCPtr<A> object where a 'A *' is -// expected. -// -// Also, when using vectors -// -// %extend_smart_pointer(RCPtr<A>); -// %template(RCPtr_A) RCPtr<A>; -// %template(vector_A) std::vector<RCPtr<A> >; -// -// you can type -// -// a = A(); -// v = vector_A(2) -// v[0] = a -// -// ie, an 'A *' object is accepted, via implicit conversion, -// where a RCPtr<A> object is expected. Additionally -// -// x = v[0] -// -// returns (and sets 'x' as) a copy of v[0], making reference -// counting possible and consistent. -// + +/* ------------------------------------------------------------------------- */ +/* + %extend_smart_pointer extend the smart pointer support. + + For example, if you have a smart pointer as: + + template <class Type> class RCPtr { + public: + ... + RCPtr(Type *p); + Type * operator->() const; + ... + }; + + you use the %extend_smart_pointer directive as: + + %extend_smart_pointer(RCPtr<A>); + %template(RCPtr_A) RCPtr<A>; + + then, if you have something like: + + RCPtr<A> make_ptr(); + int foo(A *); + + you can do the following: + + a = make_ptr(); + b = foo(a); + + ie, swig will accept a RCPtr<A> object where a 'A *' is + expected. + + Also, when using vectors + + %extend_smart_pointer(RCPtr<A>); + %template(RCPtr_A) RCPtr<A>; + %template(vector_A) std::vector<RCPtr<A> >; + + you can type + + a = A(); + v = vector_A(2) + v[0] = a + + ie, an 'A *' object is accepted, via implicit conversion, + where a RCPtr<A> object is expected. Additionally + + x = v[0] + + returns (and sets 'x' as) a copy of v[0], making reference + counting possible and consistent. +*/ + %define %extend_smart_pointer(Type...) %implicitconv Type; %apply const SWIGTYPE& SMARTPOINTER { const Type& }; diff --git a/Lib/octave/std_alloc.i b/Lib/octave/std_alloc.i index 1013e6829..35dc051be 100644 --- a/Lib/octave/std_alloc.i +++ b/Lib/octave/std_alloc.i @@ -1,5 +1 @@ -// -// std_alloc.i - STL allocator support -// - %include <std/std_alloc.i> diff --git a/Lib/octave/std_basic_string.i b/Lib/octave/std_basic_string.i index 113e10826..19712e8d0 100644 --- a/Lib/octave/std_basic_string.i +++ b/Lib/octave/std_basic_string.i @@ -1,8 +1,4 @@ -// -// std_basic_string.i - STL string support -// - -#if !defined(SWIG_STD_STRING) +#if !defined(SWIG_STD_STRING) #define SWIG_STD_BASIC_STRING #define SWIG_STD_MODERN_STL @@ -10,25 +6,28 @@ #define %swig_basic_string(Type...) %swig_sequence_methods_val(Type) -%fragment(SWIG_AsPtr_frag(std::basic_string<char>), "header", fragment = "SWIG_AsCharPtrAndSize") + +%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header", + fragment="SWIG_AsCharPtrAndSize") { +SWIGINTERN int +SWIG_AsPtr(std::basic_string<char>)(octave_value obj, std::string **val) { - SWIGINTERN int SWIG_AsPtr(std::basic_string<char>)(octave_value obj, std::string** val) { - if (obj.is_string()) { - if (val) { - *val = new std::string(obj.string_value()); - } - return SWIG_NEWOBJ; - } - if (val) { - error("a string is expected"); - } - return 0; + if (obj.is_string()) { + if (val) + *val = new std::string(obj.string_value()); + return SWIG_NEWOBJ; } + if (val) + error("a string is expected"); + return 0; +} } -%fragment(SWIG_From_frag(std::basic_string<char>), "header", fragment = "SWIG_FromCharPtrAndSize") -{ - SWIGINTERNINLINE octave_value SWIG_From(std::basic_string<char>)(const std::string & s) { +%fragment(SWIG_From_frag(std::basic_string<char>),"header", + fragment="SWIG_FromCharPtrAndSize") { +SWIGINTERNINLINE octave_value + SWIG_From(std::basic_string<char>)(const std::string& s) + { return SWIG_FromCharPtrAndSize(s.data(), s.size()); } } @@ -36,54 +35,51 @@ %ignore std::basic_string::operator +=; %include <std/std_basic_string.i> - %typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>); #endif + #if !defined(SWIG_STD_WSTRING) -%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>), "header", fragment = "SWIG_AsWCharPtrAndSize") -{ - SWIGINTERN int SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject * obj, std::wstring** val) { - static swig_type_info* string_info = SWIG_TypeQuery("std::basic_string<wchar_t> *"); - std::wstring* vptr; - if (SWIG_ConvertPtr(obj, (void**) &vptr, string_info, 0) == SWIG_OK) { - if (val) { - *val = vptr; - } +%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header", + fragment="SWIG_AsWCharPtrAndSize") { +SWIGINTERN int + SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val) + { + static swig_type_info* string_info = + SWIG_TypeQuery("std::basic_string<wchar_t> *"); + std::wstring *vptr; + if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) { + if (val) *val = vptr; return SWIG_OLDOBJ; } else { PyErr_Clear(); - wchar_t* buf = 0 ; - size_t size = 0; - int alloc = 0; + wchar_t *buf = 0 ; size_t size = 0; int alloc = 0; if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) { - if (buf) { - if (val) { - *val = new std::wstring(buf, size - 1); - } - if (alloc == SWIG_NEWOBJ) { - %delete_array(buf); - } - return SWIG_NEWOBJ; - } + if (buf) { + if (val) *val = new std::wstring(buf, size - 1); + if (alloc == SWIG_NEWOBJ) %delete_array(buf); + return SWIG_NEWOBJ; + } } else { - PyErr_Clear(); - } + PyErr_Clear(); + } if (val) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_TypeError, "a wstring is expected"); - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_TypeError,"a wstring is expected"); + SWIG_PYTHON_THREAD_END_BLOCK; } return 0; } } } -%fragment(SWIG_From_frag(std::basic_string<wchar_t>), "header", fragment = "SWIG_FromWCharPtrAndSize") -{ - SWIGINTERNINLINE PyObject* SWIG_From(std::basic_string<wchar_t>)(const std::wstring & s) { +%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header", + fragment="SWIG_FromWCharPtrAndSize") { +SWIGINTERNINLINE PyObject* + SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s) + { return SWIG_FromWCharPtrAndSize(s.data(), s.size()); } } diff --git a/Lib/octave/std_carray.i b/Lib/octave/std_carray.i index dcf317e80..e69de29bb 100644 --- a/Lib/octave/std_carray.i +++ b/Lib/octave/std_carray.i @@ -1,3 +0,0 @@ -// -// std_carray.i -// diff --git a/Lib/octave/std_char_traits.i b/Lib/octave/std_char_traits.i index d05f7b42c..bf4e6c47d 100644 --- a/Lib/octave/std_char_traits.i +++ b/Lib/octave/std_char_traits.i @@ -1,5 +1 @@ -// -// std_char_traits.i - STL character traits -// - %include <std/std_char_traits.i> diff --git a/Lib/octave/std_common.i b/Lib/octave/std_common.i index ebefc5942..9aebf7f45 100644 --- a/Lib/octave/std_common.i +++ b/Lib/octave/std_common.i @@ -1,82 +1,72 @@ -// -// std_common.i - Common STL support code -// - %include <std/std_except.i> %include <octstdcommon.swg> + // Generate the traits for a 'primitive' type, such as 'double', // for which the SWIG_AsVal and SWIG_From methods are already defined. -%define %traits_ptypen(Type...) -%fragment(SWIG_Traits_frag(Type), "header", fragment = SWIG_AsVal_frag(Type), fragment = SWIG_From_frag(Type), fragment = "StdTraits") -{ - - namespace swig - { - - template <> struct traits<Type > { - typedef value_category category; - static const char* type_name() { - return #Type; } - }; - - template <> struct traits_asval<Type > { - typedef Type value_type; - static int asval(octave_value obj, value_type* val) { - return SWIG_AsVal(Type)(obj, val); - } - }; - - template <> struct traits_from<Type > { - typedef Type value_type; - static octave_value from(const value_type& val) { - return SWIG_From(Type)(val); - } - }; - - } +%define %traits_ptypen(Type...) + %fragment(SWIG_Traits_frag(Type),"header", + fragment=SWIG_AsVal_frag(Type), + fragment=SWIG_From_frag(Type), + fragment="StdTraits") { +namespace swig { + template <> struct traits<Type > { + typedef value_category category; + static const char* type_name() { return #Type; } + }; + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(octave_value obj, value_type *val) { + return SWIG_AsVal(Type)(obj, val); + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static octave_value from(const value_type& val) { + return SWIG_From(Type)(val); + } + }; +} } %enddef -// Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums -// is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit -// instantiations required using %template). The STL containers define the 'front' method and the typemap -// below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the -// standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from -// required in the generated code for enums. +/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums + is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit + instantiations required using %template). The STL containers define the 'front' method and the typemap + below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the + standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from + required in the generated code for enums. */ %define %traits_enum(Type...) -%fragment("SWIG_Traits_enum_" {Type}, "header", fragment = SWIG_AsVal_frag(int), fragment = SWIG_From_frag(int), fragment = "StdTraits") { - - namespace swig - { - - template <> struct traits_asval<Type > { - typedef Type value_type; - static int asval(octave_value obj, value_type* val) { - return SWIG_AsVal(int)(obj, (int*) val); - } - }; - - template <> struct traits_from<Type > { - typedef Type value_type; - static octave_value from(const value_type& val) { - return SWIG_From(int)((int) val); - } - }; - - } - + %fragment("SWIG_Traits_enum_"{Type},"header", + fragment=SWIG_AsVal_frag(int), + fragment=SWIG_From_frag(int), + fragment="StdTraits") { +namespace swig { + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(octave_value obj, value_type *val) { + return SWIG_AsVal(int)(obj, (int *)val); + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static octave_value from(const value_type& val) { + return SWIG_From(int)((int)val); + } + }; } - -%typemap(out, fragment = "SWIG_Traits_enum_" {Type}) const enum SWIGTYPE& front %{ - $typemap(out, const enum SWIGTYPE&) -%} - +} +%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%} %enddef + %include <std/std_common.i> -// Generates the traits for all the known primitive C++ types (int, double, ...) +// +// Generates the traits for all the known primitive +// C++ types (int, double, ...) +// %apply_cpptypes(%traits_ptypen); + diff --git a/Lib/octave/std_complex.i b/Lib/octave/std_complex.i index 0b4627078..771728b9d 100644 --- a/Lib/octave/std_complex.i +++ b/Lib/octave/std_complex.i @@ -1,17 +1,22 @@ -// -// std_complex.i - STL complex typemaps -// +/* + * STD C++ complex typemaps + */ %include <octcomplex.swg> -%header %{ -#include <complex> +%{ +#include <complex> %} -// Define the complex as/from converters +/* defining the complex as/from converters */ + %swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag) %swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag) -// Define the typemaps +/* defining the typemaps */ + %typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>); %typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>); + + + diff --git a/Lib/octave/std_container.i b/Lib/octave/std_container.i index 80abeb768..cab76452b 100644 --- a/Lib/octave/std_container.i +++ b/Lib/octave/std_container.i @@ -1,6 +1,2 @@ -// -// std_container.i - STL container support -// - %include <octcontainer.swg> %include <std/std_container.i> diff --git a/Lib/octave/std_deque.i b/Lib/octave/std_deque.i index d5eb67db8..6866a610f 100644 --- a/Lib/octave/std_deque.i +++ b/Lib/octave/std_deque.i @@ -1,29 +1,22 @@ -// -// std_deque.i - STL deque support -// +// Deques -%fragment("StdDequeTraits", "header", fragment = "StdSequenceTraits") +%fragment("StdDequeTraits","header",fragment="StdSequenceTraits") %{ - - namespace swig - { - + namespace swig { template <class T> struct traits_asptr<std::deque<T> > { - static int asptr(octave_value obj, std::deque<T> **vec) { - return traits_asptr_stdseq<std::deque<T> >::asptr(obj, vec); + static int asptr(octave_value obj, std::deque<T> **vec) { + return traits_asptr_stdseq<std::deque<T> >::asptr(obj, vec); } }; template <class T> struct traits_from<std::deque<T> > { static octave_value from(const std::deque<T> & vec) { - return traits_from_stdseq<std::deque<T> >::from(vec); + return traits_from_stdseq<std::deque<T> >::from(vec); } }; - } - %} #define %swig_deque_methods(Type...) %swig_sequence_methods(Type) diff --git a/Lib/octave/std_except.i b/Lib/octave/std_except.i index 1f2987004..af98428f6 100644 --- a/Lib/octave/std_except.i +++ b/Lib/octave/std_except.i @@ -1,5 +1 @@ -// -// std_except.i - STL exception support -// - %include <typemaps/std_except.swg> diff --git a/Lib/octave/std_list.i b/Lib/octave/std_list.i index 580d7d312..1421efaee 100644 --- a/Lib/octave/std_list.i +++ b/Lib/octave/std_list.i @@ -1,32 +1,26 @@ -// -// std_list.i - STL list support -// +// Lists -%fragment("StdListTraits", "header", fragment = "StdSequenceTraits") +%fragment("StdListTraits","header",fragment="StdSequenceTraits") %{ - - namespace swig - { - + namespace swig { template <class T > struct traits_asptr<std::list<T> > { static int asptr(const octave_value& obj, std::list<T> **lis) { - return traits_asptr_stdseq<std::list<T> >::asptr(obj, lis); + return traits_asptr_stdseq<std::list<T> >::asptr(obj, lis); } }; template <class T> struct traits_from<std::list<T> > { - static octave_value* from(const std::list<T> & vec) { - return traits_from_stdseq<std::list<T> >::from(vec); + static octave_value *from(const std::list<T> & vec) { + return traits_from_stdseq<std::list<T> >::from(vec); } }; - } - %} #define %swig_list_methods(Type...) %swig_sequence_methods(Type) #define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); %include <std/std_list.i> + diff --git a/Lib/octave/std_map.i b/Lib/octave/std_map.i index 259bdaec3..7b85a548e 100644 --- a/Lib/octave/std_map.i +++ b/Lib/octave/std_map.i @@ -1,125 +1,156 @@ -// -// std_map.i - STL map support -// +// Maps %include <octcontainer.swg> -%fragment("StdMapCommonTraits", "header", fragment = "StdSequenceTraits") +%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits") { - - namespace swig - { - + namespace swig { template <class ValueType> - struct from_key_oper { + struct from_key_oper + { typedef const ValueType& argument_type; typedef octave_value result_type; - result_type operator()(argument_type v) const { - return swig::from(v.first); + result_type operator()(argument_type v) const + { + return swig::from(v.first); } }; template <class ValueType> - struct from_value_oper { + struct from_value_oper + { typedef const ValueType& argument_type; typedef octave_value result_type; - result_type operator()(argument_type v) const { - return swig::from(v.second); + result_type operator()(argument_type v) const + { + return swig::from(v.second); } }; template<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type> - struct OctMapIterator_T : OctIteratorClosed_T<OutIterator, ValueType, FromOper> { + struct OctMapIterator_T : OctSwigIteratorClosed_T<OutIterator, ValueType, FromOper> + { OctMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq) - : OctIteratorClosed_T<OutIterator, ValueType, FromOper> (curr, first, last, seq) { + : OctSwigIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq) + { } }; - template < class OutIterator, class FromOper = from_key_oper<typename OutIterator::value_type> > - struct OctMapKeyIterator_T : OctMapIterator_T<OutIterator, FromOper> { + template<class OutIterator, + class FromOper = from_key_oper<typename OutIterator::value_type> > + struct OctMapKeyIterator_T : OctMapIterator_T<OutIterator, FromOper> + { OctMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq) - : OctMapIterator_T<OutIterator, FromOper> (curr, first, last, seq) { + : OctMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) + { } }; template<typename OutIter> - inline OctIterator* make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = octave_value()) + inline OctSwigIterator* + make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = octave_value()) { - return new OctMapKeyIterator_T<OutIter> (current, begin, end, seq); + return new OctMapKeyIterator_T<OutIter>(current, begin, end, seq); } - template < class OutIterator, class FromOper = from_value_oper<typename OutIterator::value_type> > - struct OctMapValueIterator_T : OctMapIterator_T<OutIterator, FromOper> { + template<class OutIterator, + class FromOper = from_value_oper<typename OutIterator::value_type> > + struct OctMapValueIterator_T : OctMapIterator_T<OutIterator, FromOper> + { OctMapValueIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq) - : OctMapIterator_T<OutIterator, FromOper> (curr, first, last, seq) { + : OctMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) + { } }; - + template<typename OutIter> - inline OctIterator* + inline OctSwigIterator* make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = 0) { - return new OctMapValueIterator_T<OutIter> (current, begin, end, seq); + return new OctMapValueIterator_T<OutIter>(current, begin, end, seq); } - } - } -%fragment("StdMapTraits", "header", fragment = "StdMapCommonTraits") +%fragment("StdMapTraits","header",fragment="StdMapCommonTraits") { - - namespace swig - { - + namespace swig { template <class OctSeq, class K, class T > inline void - assign(const OctSeq& octseq, std::map<K, T > *map) - { - typedef typename std::map<K, T>::value_type value_type; + assign(const OctSeq& octseq, std::map<K,T > *map) { + typedef typename std::map<K,T>::value_type value_type; typename OctSeq::const_iterator it = octseq.begin(); - for (; it != octseq.end(); ++it) { - map->insert(value_type(it->first, it->second)); + for (;it != octseq.end(); ++it) { + map->insert(value_type(it->first, it->second)); } } template <class K, class T> - struct traits_asptr<std::map<K, T> > { - - typedef std::map<K, T> map_type; - static int asptr(octave_value obj, map_type** val) { - // * todo - return SWIG_ERROR; - } - + struct traits_asptr<std::map<K,T> > { + typedef std::map<K,T> map_type; + static int asptr(octave_value obj, map_type **val) { + /* + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); + res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val); + } else { + map_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + */ + return SWIG_ERROR; + } }; - + template <class K, class T > - struct traits_from<std::map<K, T> > { - typedef std::map<K, T> map_type; + struct traits_from<std::map<K,T> > { + typedef std::map<K,T> map_type; typedef typename map_type::const_iterator const_iterator; typedef typename map_type::size_type size_type; - + static octave_value from(const map_type& map) { - // * todo - return octave_value(); + /* + swig_type_info *desc = swig::type_info<map_type>(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); + } else { + size_type size = map.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= map.begin(); i!= map.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + */ + return octave_value(); } - }; - } - } %define %swig_map_common(Map...) -%swig_sequence_iterator(Map); -%swig_container_methods(Map); + %swig_sequence_iterator(Map); + %swig_container_methods(Map); %enddef %define %swig_map_methods(Map...) -%swig_map_common(Map) + %swig_map_common(Map) %enddef + %include <std/std_map.i> diff --git a/Lib/octave/std_pair.i b/Lib/octave/std_pair.i index ac2384714..ab028d144 100644 --- a/Lib/octave/std_pair.i +++ b/Lib/octave/std_pair.i @@ -1,145 +1,129 @@ -// -// std_pair.i - STL pair support -// +// Pairs %include <octstdcommon.swg> //#define SWIG_STD_PAIR_ASVAL -%fragment("StdPairTraits", "header", fragment = "StdTraits") -{ - namespace swig - { - +%fragment("StdPairTraits","header",fragment="StdTraits") { + namespace swig { #ifdef SWIG_STD_PAIR_ASVAL - template <class T, class U > - struct traits_asval<std::pair<T, U> > { - - typedef std::pair<T, U> value_type; - - static int get_pair(const octave_value& first, octave_value second, std::pair<T, U> *val) { - if (val) { - T* pfirst = & (val->first); - int res1 = swig::asval(first, pfirst); - if (!SWIG_IsOK(res1)) { - return res1; - } - U* psecond = & (val->second); - int res2 = swig::asval(second, psecond); - if (!SWIG_IsOK(res2)) { - return res2; - } - return res1 > res2 ? res1 : res2; - } else { - T* pfirst = 0; - int res1 = swig::asval(first, pfirst); - if (!SWIG_IsOK(res1)) { - return res1; - } - U* psecond = 0; - int res2 = swig::asval((PyObject*) second, psecond); - if (!SWIG_IsOK(res2)) { - return res2; - } - return res1 > res2 ? res1 : res2; - } + struct traits_asval<std::pair<T,U> > { + typedef std::pair<T,U> value_type; + + static int get_pair(const octave_value& first, octave_value second, + std::pair<T,U> *val) + { + if (val) { + T *pfirst = &(val->first); + int res1 = swig::asval(first, pfirst); + if (!SWIG_IsOK(res1)) + return res1; + U *psecond = &(val->second); + int res2 = swig::asval(second, psecond); + if (!SWIG_IsOK(res2)) + return res2; + return res1 > res2 ? res1 : res2; + } else { + T *pfirst = 0; + int res1 = swig::asval(first, pfirst); + if (!SWIG_IsOK(res1)) + return res1; + U *psecond = 0; + int res2 = swig::asval((PyObject*)second, psecond); + if (!SWIG_IsOK(res2)) + return res2; + return res1 > res2 ? res1 : res2; + } } - static int asval(const octave_value& obj, std::pair<T, U> *val) { - if (obj.is_cell()) { - Cell c = obj.cell_value(); - if (c.numel() < 2) { - error("pair from Cell array requires at least two elements"); - return SWIG_ERROR; - } - return get_pair(c(0), c(1), val); - } else { - value_type* p; - int res = SWIG_ConvertPtr(obj, (void**) &p, swig::type_info<value_type>(), 0); - if (SWIG_IsOK(res) && val) { - *val = *p; - } - return res; - } - return SWIG_ERROR; + static int asval(const octave_value& obj, std::pair<T,U> *val) { + if (obj.is_cell()) { + Cell c=obj.cell_value(); + if (c.numel()<2) { + error("pair from Cell array requires at least two elements"); + return SWIG_ERROR; + } + return get_pair(c(0),c(1),val); + } else { + value_type *p; + int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0); + if (SWIG_IsOK(res) && val) + *val = *p; + return res; + } + return SWIG_ERROR; } }; #else - template <class T, class U > - struct traits_asptr<std::pair<T, U> > { - typedef std::pair<T, U> value_type; - - static int get_pair(const octave_value& first, octave_value second, std::pair<T, U> **val) { - if (val) { - value_type* vp = %new_instance(std::pair<T, U>); - T* pfirst = & (vp->first); - int res1 = swig::asval(first, pfirst); - if (!SWIG_IsOK(res1)) { - return res1; - } - U* psecond = & (vp->second); - int res2 = swig::asval(second, psecond); - if (!SWIG_IsOK(res2)) { - return res2; - } - *val = vp; - return SWIG_AddNewMask(res1 > res2 ? res1 : res2); - } else { - T* pfirst = 0; - int res1 = swig::asval(first, pfirst); - if (!SWIG_IsOK(res1)) { - return res1; - } - U* psecond = 0; - int res2 = swig::asval(second, psecond); - if (!SWIG_IsOK(res2)) { - return res2; - } - return res1 > res2 ? res1 : res2; - } - return SWIG_ERROR; + struct traits_asptr<std::pair<T,U> > { + typedef std::pair<T,U> value_type; + + static int get_pair(const octave_value& first, octave_value second, + std::pair<T,U> **val) + { + if (val) { + value_type *vp = %new_instance(std::pair<T,U>); + T *pfirst = &(vp->first); + int res1 = swig::asval(first, pfirst); + if (!SWIG_IsOK(res1)) + return res1; + U *psecond = &(vp->second); + int res2 = swig::asval(second, psecond); + if (!SWIG_IsOK(res2)) + return res2; + *val = vp; + return SWIG_AddNewMask(res1 > res2 ? res1 : res2); + } else { + T *pfirst = 0; + int res1 = swig::asval(first, pfirst); + if (!SWIG_IsOK(res1)) + return res1; + U *psecond = 0; + int res2 = swig::asval(second, psecond); + if (!SWIG_IsOK(res2)) + return res2; + return res1 > res2 ? res1 : res2; + } + return SWIG_ERROR; } - static int asptr(const octave_value& obj, std::pair<T, U> **val) { - if (obj.is_cell()) { - Cell c = obj.cell_value(); - if (c.numel() < 2) { - error("pair from Cell array requires at least two elements"); - return SWIG_ERROR; - } - return get_pair(c(0), c(1), val); - } else { - value_type* p; - int res = SWIG_ConvertPtr(obj, (void**) &p, swig::type_info<value_type>(), 0); - if (SWIG_IsOK(res) && val) { - *val = p; - } - return res; - } - return SWIG_ERROR; + static int asptr(const octave_value& obj, std::pair<T,U> **val) { + if (obj.is_cell()) { + Cell c=obj.cell_value(); + if (c.numel()<2) { + error("pair from Cell array requires at least two elements"); + return SWIG_ERROR; + } + return get_pair(c(0),c(1),val); + } else { + value_type *p; + int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0); + if (SWIG_IsOK(res) && val) + *val = p; + return res; + } + return SWIG_ERROR; } }; #endif - template <class T, class U > - struct traits_from<std::pair<T, U> > { - static octave_value from(const std::pair<T, U>& val) { - Cell c(1, 2); - c(0) = swig::from(val.first); - c(1) = swig::from(val.second); - return c; + struct traits_from<std::pair<T,U> > { + static octave_value from(const std::pair<T,U>& val) { + Cell c(1,2); + c(0)=swig::from(val.first); + c(1)=swig::from(val.second); + return c; } }; - } - } %define %swig_pair_methods(pair...) %enddef %include <std/std_pair.i> + diff --git a/Lib/octave/std_string.i b/Lib/octave/std_string.i index e9ad572e0..dc1378ae6 100644 --- a/Lib/octave/std_string.i +++ b/Lib/octave/std_string.i @@ -1,5 +1 @@ -// -// std_string.i - STL string support -// - %include <typemaps/std_string.swg> diff --git a/Lib/octave/std_vector.i b/Lib/octave/std_vector.i index 386aea2a4..2862b5e77 100644 --- a/Lib/octave/std_vector.i +++ b/Lib/octave/std_vector.i @@ -1,21 +1,19 @@ -// -// std_vector.i - STL vector support -// +// Vectors -%fragment("StdVectorTraits", "header", fragment = "StdSequenceTraits") +%fragment("StdVectorTraits","header",fragment="StdSequenceTraits") %{ namespace swig { template <class T> struct traits_asptr<std::vector<T> > { static int asptr(const octave_value& obj, std::vector<T> **vec) { - return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec); + return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec); } }; - + template <class T> struct traits_from<std::vector<T> > { static octave_value from(const std::vector<T>& vec) { - return traits_from_stdseq<std::vector<T> >::from(vec); + return traits_from_stdseq<std::vector<T> >::from(vec); } }; } @@ -25,3 +23,4 @@ #define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); %include <std/std_vector.i> + diff --git a/Lib/octave/stl.i b/Lib/octave/stl.i index 83714cb8f..b29f7d84d 100644 --- a/Lib/octave/stl.i +++ b/Lib/octave/stl.i @@ -1,7 +1,4 @@ -// -// stl.i - STL support -// - +/* initial STL definition. extended as needed in each language */ %include <std_common.i> %include <std_string.i> %include <std_vector.i> diff --git a/Lib/octave/typemaps.i b/Lib/octave/typemaps.i index c093399ed..1f9b9c432 100644 --- a/Lib/octave/typemaps.i +++ b/Lib/octave/typemaps.i @@ -1,5 +1 @@ -// -// typemaps.i - Standard typemaps -// - %include <typemaps/typemaps.swg> diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ec54e8b99..3ec60c31d 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -205,8 +205,8 @@ public: Printf(f_runtime, "\n"); - Printf(s_global_tab, "\nstatic const struct SwigOctMember swig_globals[] = {\n"); - Printf(f_init, "SWIGINTERN bool SWIG_Octave_InitUser(SwigOctType* module_ns)\n{\n"); + Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n"); + Printf(f_init, "static bool SWIG_init_user(octave_swig_type* module_ns)\n{\n"); if (!CPlusPlus) { Printf(f_header, "extern \"C\" {\n"); @@ -222,6 +222,10 @@ public: emit_doc_texinfo(); } + if (directorsEnabled()) { + Swig_insert_file("director.swg", f_runtime); + } + Printf(f_init, "return true;\n}\n"); Printf(s_global_tab, "{0,0,0,0,0}\n};\n"); @@ -586,7 +590,7 @@ public: int varargs = emit_isvarargs(l); char source[64]; - Printf(w->code, "if (!SWIG_Octave_CheckNumArgs(\"%s\",args.length(),%i,%i,%i)) " + Printf(w->code, "if (!SWIG_check_num_args(\"%s\",args.length(),%i,%i,%i)) " "{\n SWIG_fail;\n }\n", iname, num_arguments, num_required, varargs); if (constructor && num_arguments == 1 && num_required == 1) { @@ -807,9 +811,9 @@ public: Octave_begin_function(n, w->def, iname, wname, true); Wrapper_add_local(w, "argc", "int argc = args.length()"); - Printf(tmp, "SwigOctValueRef argv[%d] = {", maxargs); + Printf(tmp, "octave_value_ref argv[%d]={", maxargs); for (int j = 0; j < maxargs; ++j) { - Printf(tmp, "%sSwigOctValueRef(args,%d)", j ? "," : " ", j); + Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j); } Printf(tmp, "}"); Wrapper_add_local(w, "argv", tmp); @@ -845,7 +849,7 @@ public: String* setwname = Swig_name_wrapper(setname); Octave_begin_function(n, setw->def, setname, setwname, true); - Printf(setw->def, "if (!SWIG_Octave_CheckNumArgs(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname); + Printf(setw->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname); if (is_assignable(n)) { Setattr(n, "wrap:name", setname); if ((tm = Swig_typemap_lookup("varin", n, name, 0))) { @@ -863,7 +867,7 @@ public: Append(setw->code, "fail:\n"); Printf(setw->code, "return octave_value_list();\n"); } else { - Printf(setw->code, "return SWIG_Octave_SetImmutable(args,nargout);"); + Printf(setw->code, "return octave_set_immutable(args,nargout);"); } Append(setw->code, "}\n"); Wrapper_print(setw, f_wrappers); @@ -973,7 +977,7 @@ public: assert(!s_members_tab); s_members_tab = NewStringEmpty(); - Printv(s_members_tab, "static SwigOctMember swig_", class_name, "_members[] = {\n", NIL); + Printv(s_members_tab, "static swig_octave_member swig_", class_name, "_members[] = {\n", NIL); Language::classHandler(n); @@ -1033,7 +1037,7 @@ public: Printv(f_wrappers, "static const char *swig_", class_name, "_base_names[] = {", base_class_names, "0};\n", NIL); Printv(f_wrappers, "static const swig_type_info *swig_", class_name, "_base[] = {", base_class, "0};\n", NIL); - Printv(f_wrappers, "static SwigOctClass _wrap_class_", class_name, " = {\"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_octave_class _wrap_class_", class_name, " = {\"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); Printv(f_wrappers, Swig_directorclass(n) ? "1," : "0,", NIL); if (have_constructor) { String* nspace = Getattr(n, "sym:nspace"); @@ -1107,7 +1111,7 @@ public: String* getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); String* setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); String* getwname = Swig_name_wrapper(getname); - String* setwname = GetFlag(n, "feature:immutable") ? NewString("SWIG_Octave_SetImmutable") : Swig_name_wrapper(setname); + String* setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname); assert(s_members_tab); Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getwname, setwname); @@ -1196,7 +1200,7 @@ public: String* getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); String* setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); String* getwname = Swig_name_wrapper(getname); - String* setwname = GetFlag(n, "feature:immutable") ? NewString("SWIG_Octave_SetImmutable") : Swig_name_wrapper(setname); + String* setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname); assert(s_members_tab); Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getwname, setwname); @@ -1277,12 +1281,12 @@ public: { Wrapper* w = NewWrapper(); Printf(w->def, "SwigDirector_%s::SwigDirector_%s(void* self) :" - "\nSwig::Director((SwigOctType*)self,static_cast<%s*>(this)) { \n", classname, classname, classname); + "\nSwig::Director((octave_swig_type*)self,static_cast<%s*>(this)) { \n", classname, classname, classname); Append(w->def, "}\n"); Wrapper_print(w, f_directors); DelWrapper(w); } - Printf(f_directors_h, " SwigDirector_%s(SwigOctType* self);\n", classname); + Printf(f_directors_h, " SwigDirector_%s(octave_swig_type* self);\n", classname); Delete(classname); return Language::classDirectorDefaultConstructor(n); } @@ -1563,20 +1567,12 @@ public: String* runtimeCode() { String* s = NewStringEmpty(); - const char* runtimeFiles[] = { - "octrundecl.swg", - "octrunfunc.swg", - "octrunclass.swg", - "octruninit.swg" - }; - for (size_t i = 0; i < sizeof(runtimeFiles)/sizeof(runtimeFiles[0]); ++i) { - String* srun = Swig_include_sys(runtimeFiles[i]); - if (!srun) { - Printf(stderr, "*** Unable to open '%s'\n", runtimeFiles[i]); - } else { - Append(s, srun); - Delete(srun); - } + String* srun = Swig_include_sys("octrun.swg"); + if (!srun) { + Printf(stderr, "*** Unable to open 'octrun.swg'\n"); + } else { + Append(s, srun); + Delete(srun); } return s; } |