Fix ~15 tests, minor doc fixes, improve STL support.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10298 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
25fd00698b
commit
4d283f59c3
32 changed files with 744 additions and 522 deletions
|
|
@ -1,12 +1,6 @@
|
|||
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
%include <typemaps/fragments.swg>
|
||||
%include <octruntime.swg>
|
||||
%include <octuserdir.swg>
|
||||
%include <octtypemaps.swg>
|
||||
%include <octopers.swg>
|
||||
|
||||
|
||||
%typemap(constcode) int double {
|
||||
SWIG_Octave_SetConstant(module_ns,"$symname",octave_value($value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pycontainer.swg
|
||||
* octcontainer.swg
|
||||
*
|
||||
* Octave sequence <-> C++ container wrapper
|
||||
* Octave cell <-> C++ container wrapper
|
||||
*
|
||||
* This wrapper, and its iterator, allows a general use (and reuse) of
|
||||
* the the mapping between C++ and Octave, thanks to the C++
|
||||
|
|
@ -52,14 +52,14 @@ namespace swig {
|
|||
|
||||
template <>
|
||||
struct traits_check<octave_value, value_category> {
|
||||
static bool check(octave_value) {
|
||||
static bool check(const octave_value&) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct traits_asval<octave_value > {
|
||||
typedef octave_value value_type;
|
||||
static int asval(octave_value obj, value_type *val) {
|
||||
static int asval(const octave_value& obj, value_type *val) {
|
||||
if (val) *val = obj;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
|
@ -76,16 +76,10 @@ namespace std {
|
|||
struct less <octave_value>: public binary_function<octave_value, octave_value, bool>
|
||||
{
|
||||
bool
|
||||
operator()(octave_value v, octave_value w) const
|
||||
operator()(const octave_value& v, const octave_value& w) const
|
||||
{
|
||||
/*
|
||||
bool res;
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
res = PyObject_Compare(v, w) < 0;
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return res;
|
||||
*/
|
||||
return false;
|
||||
octave_value res = do_binary_op(octave_value::op_le,v,w);
|
||||
return res.is_true();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -201,9 +195,9 @@ namespace swig {
|
|||
namespace swig
|
||||
{
|
||||
template <class T>
|
||||
struct OctSequence_Ref
|
||||
struct OctSequence_Ref // * octave can't support these, because of how assignment works
|
||||
{
|
||||
OctSequence_Ref(octave_value seq, int index)
|
||||
OctSequence_Ref(const octave_value& seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
|
@ -262,7 +256,7 @@ namespace swig
|
|||
{
|
||||
}
|
||||
|
||||
OctSequence_InputIterator(octave_value seq, int index)
|
||||
OctSequence_InputIterator(const octave_value& seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
|
@ -279,7 +273,7 @@ namespace swig
|
|||
|
||||
bool operator==(const self& ri) const
|
||||
{
|
||||
return (_index == ri._index) && (_seq == ri._seq);
|
||||
return (_index == ri._index);
|
||||
}
|
||||
|
||||
bool operator!=(const self& ri) const
|
||||
|
|
@ -355,7 +349,7 @@ namespace swig
|
|||
typedef OctSequence_InputIterator<T, reference> iterator;
|
||||
typedef OctSequence_InputIterator<T, const_reference> const_iterator;
|
||||
|
||||
OctSequence_Cont(octave_value seq) : _seq(seq)
|
||||
OctSequence_Cont(const octave_value& seq) : _seq(seq)
|
||||
{
|
||||
// * assert that we have map type etc.
|
||||
/*
|
||||
|
|
@ -446,32 +440,28 @@ namespace swig
|
|||
|
||||
%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,noblock=1,fragment="OctSequence_Cont")
|
||||
%typemap(out,fragment="OctSequence_Cont")
|
||||
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
||||
/*
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
%fragment("PyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="OctSequence_Cont") {}
|
||||
|
||||
%typemap(out,noblock=1,fragment="OctPairBoolOutputIterator")
|
||||
%typemap(out,fragment="OctPairBoolOutputIterator")
|
||||
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
||||
/*
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
|
||||
*/
|
||||
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")
|
||||
|
|
@ -479,7 +469,6 @@ namespace swig
|
|||
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);
|
||||
|
|
@ -491,16 +480,13 @@ namespace swig
|
|||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
%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");
|
||||
|
|
@ -517,6 +503,29 @@ namespace swig
|
|||
%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;
|
||||
}
|
||||
|
||||
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 append(value_type x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
|
||||
%enddef
|
||||
|
||||
%define %swig_sequence_methods(Sequence...)
|
||||
|
|
@ -525,19 +534,6 @@ namespace swig
|
|||
|
||||
%define %swig_sequence_methods_val(Sequence...)
|
||||
%swig_sequence_methods_common(%arg(Sequence))
|
||||
%extend {
|
||||
value_type __getitem__(difference_type i) throw (std::out_of_range) {
|
||||
return *(swig::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(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);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
//
|
||||
|
|
@ -549,17 +545,17 @@ namespace swig
|
|||
fragment="OctSequence_Cont")
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class Seq>
|
||||
template <class OctSeq, class Seq>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, Seq* seq) {
|
||||
assign(const OctSeq& octseq, Seq* seq) {
|
||||
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++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(pyseq.begin(), pyseq.end());
|
||||
seq->assign(octseq.begin(), octseq.end());
|
||||
%#endif
|
||||
}
|
||||
|
||||
|
|
@ -568,38 +564,32 @@ namespace swig {
|
|||
typedef Seq sequence;
|
||||
typedef T value_type;
|
||||
|
||||
static int asptr(octave_value obj, sequence **seq) {
|
||||
/*
|
||||
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
|
||||
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 (OctSequence_Check(obj)) {
|
||||
} else if (obj.is_cell()) {
|
||||
try {
|
||||
OctSequence_Cont<value_type> pyseq(obj);
|
||||
OctSequence_Cont<value_type> octseq(obj);
|
||||
if (seq) {
|
||||
sequence *pseq = new sequence();
|
||||
assign(pyseq, pseq);
|
||||
assign(octseq, pseq);
|
||||
*seq = pseq;
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
return pyseq.check() ? SWIG_OK : SWIG_ERROR;
|
||||
return octseq.check() ? SWIG_OK : SWIG_ERROR;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
if (seq) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, e.what());
|
||||
}
|
||||
}
|
||||
if (seq&&!error_state)
|
||||
error("swig type error: %s",e.what());
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
*/
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -611,8 +601,7 @@ namespace swig {
|
|||
typedef typename sequence::const_iterator const_iterator;
|
||||
|
||||
static octave_value from(const sequence& seq) {
|
||||
/*
|
||||
#ifdef SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
|
||||
#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);
|
||||
|
|
@ -620,18 +609,17 @@ namespace swig {
|
|||
#endif
|
||||
size_type size = seq.size();
|
||||
if (size <= (size_type)INT_MAX) {
|
||||
PyObject *obj = PyTuple_New((int)size);
|
||||
Cell c(size,1);
|
||||
int i = 0;
|
||||
for (const_iterator it = seq.begin();
|
||||
it != seq.end(); ++it, ++i) {
|
||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
||||
c(i) = swig::from<value_type>(*it);
|
||||
}
|
||||
return obj;
|
||||
return c;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
|
||||
return NULL;
|
||||
error("swig overflow error: sequence size not valid in octave");
|
||||
return octave_value();
|
||||
}
|
||||
*/
|
||||
return octave_value();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pyiterators.swg
|
||||
*
|
||||
* Implement a python 'output' iterator for Python 2.2 or higher.
|
||||
* 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
|
||||
|
|
@ -31,19 +29,15 @@ namespace swig {
|
|||
public:
|
||||
virtual ~OctSwigIterator() {}
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual octave_value value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual OctSwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
|
||||
virtual OctSwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
throw stop_iteration();
|
||||
}
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const OctSwigIterator &x) const
|
||||
{
|
||||
throw std::invalid_argument("operation not supported");
|
||||
|
|
@ -54,7 +48,6 @@ namespace swig {
|
|||
throw std::invalid_argument("operation not supported");
|
||||
}
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual OctSwigIterator *copy() const = 0;
|
||||
|
||||
octave_value next()
|
||||
|
|
@ -84,15 +77,15 @@ namespace swig {
|
|||
{
|
||||
return ! operator==(x);
|
||||
}
|
||||
|
||||
OctSwigIterator& operator += (ptrdiff_t n)
|
||||
{
|
||||
return *advance(n);
|
||||
|
||||
OctSwigIterator* operator ++ () {
|
||||
incr();
|
||||
return this;
|
||||
}
|
||||
|
||||
OctSwigIterator& operator -= (ptrdiff_t n)
|
||||
{
|
||||
return *advance(-n);
|
||||
OctSwigIterator* operator -- () {
|
||||
decr();
|
||||
return this;
|
||||
}
|
||||
|
||||
OctSwigIterator* operator + (ptrdiff_t n) const
|
||||
|
|
@ -306,12 +299,8 @@ namespace swig
|
|||
struct stop_iteration {};
|
||||
|
||||
%typemap(throws) stop_iteration {
|
||||
assert(0); *(int*)0=0;
|
||||
/*
|
||||
(void)$1;
|
||||
SWIG_SetErrorObj(PyExc_StopIteration, SWIG_Py_Void());
|
||||
error("stop_iteration exception");
|
||||
SWIG_fail;
|
||||
*/
|
||||
}
|
||||
|
||||
// Mark methods that return new objects
|
||||
|
|
@ -343,37 +332,29 @@ namespace swig
|
|||
public:
|
||||
virtual ~OctSwigIterator();
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual octave_value value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual OctSwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
virtual OctSwigIterator *decr(size_t n = 1);
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const OctSwigIterator &x) const;
|
||||
|
||||
virtual bool equal (const OctSwigIterator &x) const;
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual OctSwigIterator *copy() const = 0;
|
||||
|
||||
octave_value next();
|
||||
octave_value previous();
|
||||
OctSwigIterator *advance(ptrdiff_t n);
|
||||
|
||||
// * todo: need operator support
|
||||
/*
|
||||
bool operator == (const OctSwigIterator& x) const;
|
||||
bool operator != (const OctSwigIterator& x) const;
|
||||
OctSwigIterator& operator += (ptrdiff_t n);
|
||||
OctSwigIterator& operator -= (ptrdiff_t n);
|
||||
OctSwigIterator* operator ++ ();
|
||||
OctSwigIterator* operator -- ();
|
||||
OctSwigIterator* operator + (ptrdiff_t n) const;
|
||||
OctSwigIterator* operator - (ptrdiff_t n) const;
|
||||
ptrdiff_t operator - (const OctSwigIterator& x) const;
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,8 +111,14 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val)
|
|||
if (v!=floor(v))
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.int64_scalar_value().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;
|
||||
}
|
||||
}
|
||||
|
|
@ -147,8 +153,14 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val)
|
|||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.uint64_scalar_value().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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,8 +163,10 @@ struct swig_octave_class {
|
|||
|
||||
// octave_swig_type plays the role of both the shadow class and the class
|
||||
// representation within Octave, since there is no support for classes.
|
||||
// Ideally these would be separated (with the latter in Octave itself),
|
||||
// but for brevity/simplicity this is not done here.
|
||||
//
|
||||
// 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 {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
|||
octave_swig_packed::register_type();
|
||||
SWIG_InitializeModule(0);
|
||||
SWIG_PropagateClientData();
|
||||
|
||||
|
||||
install_builtin_function(swig_type,"swig_type",std::string());
|
||||
install_builtin_function(swig_typequery,"swig_typequery",std::string());
|
||||
install_builtin_function(swig_this,"swig_this",std::string());
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace swig {
|
|||
// Traits that provides the asval/as/check method
|
||||
template <class Type>
|
||||
struct traits_asptr {
|
||||
static int asptr(octave_value obj, Type **val) {
|
||||
static int asptr(const octave_value& obj, Type **val) {
|
||||
Type *p;
|
||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0;
|
||||
if (SWIG_IsOK(res)) {
|
||||
|
|
@ -51,13 +51,13 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type>
|
||||
inline int asptr(octave_value obj, Type **vptr) {
|
||||
inline int asptr(const octave_value& obj, Type **vptr) {
|
||||
return traits_asptr<Type>::asptr(obj, vptr);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
struct traits_asval {
|
||||
static int asval(octave_value obj, Type *val) {
|
||||
static int asval(const octave_value& obj, Type *val) {
|
||||
if (val) {
|
||||
Type *p = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &p);
|
||||
|
|
@ -80,7 +80,7 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type> struct traits_asval<Type*> {
|
||||
static int asval(octave_value obj, Type **val) {
|
||||
static int asval(const octave_value& obj, Type **val) {
|
||||
if (val) {
|
||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
noconst_type *p = 0;
|
||||
|
|
@ -96,13 +96,13 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type>
|
||||
inline int asval(octave_value obj, Type *val) {
|
||||
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(octave_value obj, bool throw_error) {
|
||||
static Type as(const octave_value& obj, bool throw_error) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj.is_defined() || !SWIG_IsOK(res)) {
|
||||
|
|
@ -117,9 +117,9 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(octave_value obj, bool throw_error) {
|
||||
static Type as(const octave_value& obj, bool throw_error) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
if (SWIG_IsNewObj(res)) {
|
||||
Type r(*v);
|
||||
|
|
@ -143,9 +143,9 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(octave_value obj, bool throw_error) {
|
||||
static Type* as(const octave_value& obj, bool throw_error) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return v;
|
||||
} else {
|
||||
|
|
@ -159,28 +159,28 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(octave_value obj, bool te = false) {
|
||||
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(octave_value obj) {
|
||||
int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR;
|
||||
static bool check(const octave_value& obj) {
|
||||
int res = asval(obj, (Type *)(0));
|
||||
return SWIG_IsOK(res) ? true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_check<Type, pointer_category> {
|
||||
static bool check(octave_value obj) {
|
||||
int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR;
|
||||
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(octave_value obj) {
|
||||
inline bool check(const octave_value& obj) {
|
||||
return traits_check<Type, typename traits<Type>::category>::check(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ namespace swig {
|
|||
namespace swig {
|
||||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(octave_value obj, value_type *val) {
|
||||
static int asval(const octave_value& obj, value_type *val) {
|
||||
if (Check(obj)) {
|
||||
if (val) *val = As(obj);
|
||||
return SWIG_OK;
|
||||
|
|
@ -208,7 +208,7 @@ namespace swig {
|
|||
|
||||
template <>
|
||||
struct traits_check<Type, value_category> {
|
||||
static int check(octave_value obj) {
|
||||
static int check(const octave_value& obj) {
|
||||
int res = Check(obj);
|
||||
return obj && res ? res : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@
|
|||
#define SWIG_Object octave_value
|
||||
#define VOID_Object octave_value()
|
||||
|
||||
/*
|
||||
// Octave allows implicit conversion
|
||||
#define %implicitconv_flag $implicitconv
|
||||
*/
|
||||
|
||||
// append output
|
||||
#define SWIG_AppendOutput(result, obj) SWIG_Octave_AppendOutput(result, obj)
|
||||
|
|
@ -33,3 +37,28 @@
|
|||
|
||||
// Include the unified typemap library
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
|
||||
|
||||
%typemap(constcode,noblock=1) int double {
|
||||
SWIG_Octave_SetConstant(module_ns,"$symname",octave_value($value));
|
||||
}
|
||||
|
||||
/*
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
72
Lib/octave/octuserdir.swg
Normal file
72
Lib/octave/octuserdir.swg
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* -------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Implicit Conversion using the C++ constructor mechanism
|
||||
*/
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
||||
%define %extend_smart_pointer(Type...)
|
||||
%implicitconv Type;
|
||||
%apply const SWIGTYPE& SMARTPOINTER { const Type& };
|
||||
%apply SWIGTYPE SMARTPOINTER { Type };
|
||||
%enddef
|
||||
|
|
@ -3,21 +3,19 @@
|
|||
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
/*
|
||||
template <class T>
|
||||
struct traits_asptr<std::vector<T> > {
|
||||
static int asptr(PyObject *obj, std::vector<T> **vec) {
|
||||
static int asptr(const octave_value& obj, std::vector<T> **vec) {
|
||||
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::vector<T> > {
|
||||
static PyObject *from(const std::vector<T>& vec) {
|
||||
static octave_value from(const std::vector<T>& vec) {
|
||||
return traits_from_stdseq<std::vector<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
*/
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue