Static member variable handler.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10623 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-07-01 23:32:34 +00:00
commit 0b3d9dad0d
2 changed files with 39 additions and 7 deletions

View file

@ -9,7 +9,7 @@ int main(int argc, char **argv) {
Square* s = new_Square(10);
printf(" Created square\n");
printf("\nA total of %d shapes were created\n", 0);
printf("\nA total of %d shapes were created\n", Shape_get_nshapes());
Circle_set_x(c, 20);
Circle_set_y(c, 30);
@ -36,7 +36,7 @@ int main(int argc, char **argv) {
delete_Square(s);
delete_Circle(c);
printf("%d shapes remain\n", 0);
printf("%d shapes remain\n", Shape_get_nshapes());
printf("Goodbye\n");
}

View file

@ -579,15 +579,48 @@ public:
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node* n) {
String* name = Getattr(n, "sym:name");
String* classname = Getattr(parentNode(n), "name");
String* newclassname = Copy(classname);
String* new_name = NewString("");
String* code = NewString("");
Replaceall(newclassname, "::", "_");
// create code for 'get' function
Printv(code, "$cppresult = ", classname, "::", name, ";\n", NIL);
Setattr(n, "wrap:action", code);
// modify the method name
Printv(new_name, newclassname, "_get_", name, NIL);
Setattr(n, "sym:name", new_name);
functionWrapper(n);
// create parameter for 'set' function
Parm* p = NewParm(Getattr(n, "type"), "value");
Setattr(p, "lname", "arg1");
Setattr(n, "parms", p);
// create code for 'set' function
code = NewString("");
Printv(code, classname, "::", name, " = arg1;\n", NIL);
Setattr(n, "wrap:action", code);
// modify the method name
new_name = NewString("");
Printv(new_name, newclassname, "_set_", name, NIL);
Setattr(n, "sym:name", new_name);
Setattr(n, "type", "void");
functionWrapper(n);
Delete(code);
Delete(new_name);
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* membervariableHandler()
*
* TODO: generate additional setters and getters to handle inheritance
* properly, i.e. pair of functions for each type in hierarchy
*
* --------------------------------------------------------------------- */
virtual int membervariableHandler(Node* n) {
@ -643,7 +676,6 @@ public:
Setattr(n, "wrap:action", code);
// modify method name
Delete(new_name);
new_name = NewString("");
Printv(new_name, newclassname, "_set_", name, NIL);
Setattr(n, "sym:name", new_name);