PageRenderTime 7ms CodeModel.GetById 3ms app.highlight 1ms RepoModel.GetById 1ms 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
 1%module memberin_extend_c
 2
 3/* Example from the Manual, section 5.5.6: "Adding member functions to C structures" */
 4
 5%{
 6typedef struct {
 7  char name[50];
 8} Person;
 9%}
10
11typedef struct {
12  %extend {
13    char name[50];
14  }
15} Person;
16
17%{
18#include <ctype.h>
19#include <string.h>
20
21void make_upper(char *name) {
22  char *c;
23  for (c = name; *c; ++c)
24    *c = (char)toupper((int)*c);
25}
26
27/* Specific implementation of set/get functions forcing capitalization */
28
29char *Person_name_get(Person *p) {
30  make_upper(p->name);
31  return p->name;
32}
33
34void Person_name_set(Person *p, char *val) {
35  strncpy(p->name,val,50);
36  make_upper(p->name);
37}
38%}