PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/memberin_extend_c.i

#
Swig | 38 lines | 28 code | 8 blank | 2 comment | 0 complexity | db18736b7a10d44e7db66b7e313b003e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module memberin_extend_c
  2. /* Example from the Manual, section 5.5.6: "Adding member functions to C structures" */
  3. %{
  4. typedef struct {
  5. char name[50];
  6. } Person;
  7. %}
  8. typedef struct {
  9. %extend {
  10. char name[50];
  11. }
  12. } Person;
  13. %{
  14. #include <ctype.h>
  15. #include <string.h>
  16. void make_upper(char *name) {
  17. char *c;
  18. for (c = name; *c; ++c)
  19. *c = (char)toupper((int)*c);
  20. }
  21. /* Specific implementation of set/get functions forcing capitalization */
  22. char *Person_name_get(Person *p) {
  23. make_upper(p->name);
  24. return p->name;
  25. }
  26. void Person_name_set(Person *p, char *val) {
  27. strncpy(p->name,val,50);
  28. make_upper(p->name);
  29. }
  30. %}