import source from 1.3.40
[external/swig.git] / Examples / test-suite / apply_strings.i
1 /* Test %apply for char *, signed char *, unsigned char * 
2    This won't work in all situations, so does not necessarily have to be implemented. See 
3    http://groups.google.com.ai/group/comp.lang.c++.moderated/browse_thread/thread/ad5873ce25d49324/0ae94552452366be?lnk=raot */
4 %module(directors="1") apply_strings
5
6 %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) DirectorTest;
7 %warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) DigitsGlobalB;
8 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK) DigitsGlobalC;
9
10 %apply char * {UCharPtr};
11 %apply char * {SCharPtr};
12 %apply const char * {CUCharPtr};
13 %apply const char * {CSCharPtr};
14
15 %inline %{
16   typedef unsigned char* UCharPtr;
17   typedef signed char* SCharPtr;
18   typedef const unsigned char* CUCharPtr;
19   typedef const signed char* CSCharPtr;
20
21   UCharPtr UCharFunction(UCharPtr str) { return str; }
22   SCharPtr SCharFunction(SCharPtr str) { return str; }
23   CUCharPtr CUCharFunction(CUCharPtr str) { return str; }
24   CSCharPtr CSCharFunction(CSCharPtr str) { return str; }
25 %}
26
27 %typemap(freearg) SWIGTYPE * ""
28 %apply SWIGTYPE* {CharPtr};
29 %apply SWIGTYPE* {CCharPtr};
30
31 %inline %{
32   typedef char* CharPtr;
33   typedef const char* CCharPtr;
34
35   CharPtr CharFunction(CharPtr buffer) { return buffer; }
36   CCharPtr CCharFunction(CCharPtr buffer) { return buffer; }
37 %}
38
39 // unsigned char* as strings
40 #if defined(SWIGJAVA) || defined(SWIGCSHARP)
41
42 /* Note: Chicken does not allow unsigned char * in strings */
43
44 %apply char [ANY] {TAscii[ANY]}
45 %apply char [] {TAscii []}
46 %apply char * {TAscii *}
47
48 #endif
49
50 %inline %{
51 typedef unsigned char TAscii;
52 typedef struct {
53    TAscii DigitsMemberA[20];
54    TAscii *DigitsMemberB;
55 } TNumber;
56  
57 TAscii DigitsGlobalA[20];
58 TAscii DigitsGlobalB[] = {(unsigned char)'A', (unsigned char)'B', 0};
59 TAscii *DigitsGlobalC;
60
61 %} 
62
63 // Director test
64 %feature("director");
65
66 %inline %{
67   struct DirectorTest {
68     virtual UCharPtr UCharFunction(UCharPtr str) { return str; }
69     virtual SCharPtr SCharFunction(SCharPtr str) { return str; }
70     virtual CUCharPtr CUCharFunction(CUCharPtr str) { return str; }
71     virtual CSCharPtr CSCharFunction(CSCharPtr str) { return str; }
72     virtual CharPtr CharFunction(CharPtr buffer) { return buffer; }
73     virtual CCharPtr CCharFunction(CCharPtr buffer) { return buffer; }
74     virtual ~DirectorTest() {}
75   };
76 %}
77
78