Add %attributeval and %attributestring to attribute.swg library
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11128 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9be7fe899d
commit
589eb8e509
6 changed files with 261 additions and 15 deletions
|
|
@ -93,9 +93,11 @@ struct MyFoo; // %attribute2 does not work with templates
|
|||
%template(Param_i) Param<int>;
|
||||
|
||||
|
||||
// class/struct attribute with get/set methods using return/pass by reference
|
||||
%attribute2(MyClass, MyFoo, Foo, GetFoo, SetFoo);
|
||||
%inline %{
|
||||
struct MyFoo {
|
||||
MyFoo() : x(-1) {}
|
||||
int x;
|
||||
};
|
||||
class MyClass {
|
||||
|
|
@ -106,3 +108,32 @@ struct MyFoo; // %attribute2 does not work with templates
|
|||
};
|
||||
%}
|
||||
|
||||
|
||||
// class/struct attribute with get/set methods using return/pass by value
|
||||
%attributeval(MyClassVal, MyFoo, ReadWriteFoo, GetFoo, SetFoo);
|
||||
%attributeval(MyClassVal, MyFoo, ReadOnlyFoo, GetFoo);
|
||||
%inline %{
|
||||
class MyClassVal {
|
||||
MyFoo foo;
|
||||
public:
|
||||
MyFoo GetFoo() { return foo; }
|
||||
void SetFoo(MyFoo other) { foo = other; }
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
// string attribute with get/set methods using return/pass by value
|
||||
%include <std_string.i>
|
||||
%attributestring(MyStringyClass, std::string, ReadWriteString, GetString, SetString);
|
||||
%attributestring(MyStringyClass, std::string, ReadOnlyString, GetString);
|
||||
%inline %{
|
||||
class MyStringyClass {
|
||||
std::string str;
|
||||
public:
|
||||
MyStringyClass(const std::string &val) : str(val) {}
|
||||
std::string GetString() { return str; }
|
||||
void SetString(std::string other) { str = other; }
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue