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:
William S Fulton 2009-02-13 22:42:45 +00:00
commit 589eb8e509
6 changed files with 261 additions and 15 deletions

View file

@ -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; }
};
%}