allowing template arguments
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5787 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a27e364d14
commit
73ba9f4506
1 changed files with 43 additions and 18 deletions
|
|
@ -52,10 +52,10 @@
|
||||||
|
|
||||||
You can also use
|
You can also use
|
||||||
|
|
||||||
%attribute_ref(class, type, pyattr, cppame);
|
%attribute_ref(class, type, refname, attr);
|
||||||
|
|
||||||
if the internal C++ reference methods have a different
|
if the internal C++ reference methods have a different name from the
|
||||||
name from the python attribute you want.
|
attribute you want.
|
||||||
|
|
||||||
Then you can use the instances like:
|
Then you can use the instances like:
|
||||||
|
|
||||||
|
|
@ -65,44 +65,69 @@
|
||||||
|
|
||||||
x.b = 3 # calls A::b()
|
x.b = 3 # calls A::b()
|
||||||
print x.b # calls A::b() const
|
print x.b # calls A::b() const
|
||||||
|
|
||||||
|
NOTE: remember that if the type contains commas, such as
|
||||||
|
'std::pair<int,int>', you need to use the macro like:
|
||||||
|
|
||||||
|
%attribute_ref(A, SWIG_arg(std::pair<int,int>), pval);
|
||||||
|
|
||||||
|
where SWIG_arg() 'normalize' the type to be understood as a single
|
||||||
|
argument, otherwise the macro will get confused (see the 'cpp'
|
||||||
|
documentation).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
%define %_attribute(Class, type, attr, getcode, setcode)
|
%define %_attribute(Class, Wrap, type, attr, getcode, setcode)
|
||||||
%extend Class {
|
%extend Class {
|
||||||
type attr;
|
type attr;
|
||||||
}
|
}
|
||||||
%{
|
%{
|
||||||
#define Class ##_## attr ## _get(_t) getcode
|
#define Wrap ##_## attr ## _get(_t) getcode
|
||||||
#define Class ##_## attr ## _set(_t, _val) setcode
|
#define Wrap ##_## attr ## _set(_t, _val) setcode
|
||||||
%}
|
%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define %attribute(Class, type, attr, get, ...)
|
//
|
||||||
|
// Internal versions, need Wrap name
|
||||||
|
//
|
||||||
|
|
||||||
|
%define %attribute_T(Class, Wrap, type, attr, get, ...)
|
||||||
%ignore Class::get;
|
%ignore Class::get;
|
||||||
#if #__VA_ARGS__ != ""
|
#if #__VA_ARGS__ != ""
|
||||||
%ignore Class::__VA_ARGS__;
|
%ignore Class::__VA_ARGS__;
|
||||||
%_attribute(SWIG_arg(Class), SWIG_arg(type),
|
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
|
||||||
attr, _t->get(), _t->__VA_ARGS__(_val))
|
attr, _t->get(), _t->__VA_ARGS__(_val))
|
||||||
#else
|
#else
|
||||||
%_attribute(SWIG_arg(Class), SWIG_arg(type),
|
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
|
||||||
attr, _t->get(),
|
attr, _t->get(),
|
||||||
fprintf(stderr,"'attr' is a read-only attribute"))
|
fprintf(stderr,"'attr' is a read-only attribute"))
|
||||||
#endif
|
#endif
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define %_attribute_ref(Class, type, attr, ref_name)
|
%define %_attribute_ref_T(Class, Wrap, type, refname, attr)
|
||||||
%ignore Class::ref_name();
|
%ignore Class::refname();
|
||||||
%ignore Class::ref_name() const;
|
%ignore Class::refname() const;
|
||||||
%_attribute(SWIG_arg(Class), SWIG_arg(type),
|
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
|
||||||
attr, _t->ref_name(), _t->ref_name() = _val)
|
attr, _t->refname(), _t->refname() = _val)
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define %attribute_ref(Class, type, attr, ...)
|
%define %attribute_ref_T(Class, Wrap, type, refname, ...)
|
||||||
#if #__VA_ARGS__ == ""
|
#if #__VA_ARGS__ == ""
|
||||||
%_attribute_ref(SWIG_arg(Class), SWIG_arg(type), attr, attr)
|
%_attribute_ref_T(SWIG_arg(Class), Wrap, SWIG_arg(type), refname, refname)
|
||||||
#else
|
#else
|
||||||
%_attribute_ref(SWIG_arg(Class), SWIG_arg(type), attr, __VA_ARGS__)
|
%_attribute_ref_T(SWIG_arg(Class), Wrap, SWIG_arg(type), refname, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
//
|
||||||
|
// User versions
|
||||||
|
//
|
||||||
|
|
||||||
|
%define %attribute(Class, type, attr, get, ...)
|
||||||
|
%attribute_T(Class, #@Class, SWIG_arg(type), attr, get, __VA_ARGS__)
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%define %attribute_ref(Class, type, refname, ...)
|
||||||
|
%attribute_ref_T(Class, #@Class, SWIG_arg(type), refname, __VA_ARGS__)
|
||||||
|
%enddef
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue