PageRenderTime 15ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 78 lines | 67 code | 11 blank | 0 comment | 0 complexity | c154de5234cdb4db82d6fc505e829678 MD5 | raw file
 1// Tests for the allprotected option
 2
 3%module(directors="1", allprotected="1") allprotected
 4
 5%{
 6#include <string>
 7%}
 8
 9%include "std_string.i"
10
11%feature("director") PublicBase;
12%feature("director") ProtectedBase;
13
14// protected types not supported (ProtectedEnum, IntegerType). Make sure they can be ignored.
15%ignore ProtectedBase::protectedenum;
16%ignore ProtectedBase::typedefs;
17
18%inline %{
19class Klass {
20  std::string name;
21public:
22  Klass(const std::string& n) : name(n) {}
23  std::string getName() { return name; }
24};
25
26class PublicBase {
27  std::string str;
28public:
29  enum AnEnum { EnumVal1, EnumVal2 };
30public:
31  PublicBase(const char* s): str(s), instanceMemberVariable(0), anEnum(EnumVal1), stringMember(0) {}
32  virtual ~PublicBase() { }
33  virtual std::string virtualMethod() const { return "PublicBase"; }
34  Klass instanceMethod(Klass k) const { return k; }
35  Klass *instanceOverloaded(Klass *k) const { return k; }
36  Klass *instanceOverloaded(Klass *k, std::string name) const { return new Klass(name); }
37  static Klass staticMethod(Klass k) { return k; }
38  static Klass *staticOverloaded(Klass *k) { return k; }
39  static Klass *staticOverloaded(Klass *k, std::string name) { return new Klass(name); }
40  int instanceMemberVariable;
41  static int staticMemberVariable;
42  static const int staticConstMemberVariable = 20;
43  AnEnum anEnum;
44  char *stringMember;
45};
46int PublicBase::staticMemberVariable = 10;
47
48class ProtectedBase {
49  std::string str;
50public:
51  enum AnEnum { EnumVal1, EnumVal2 };
52  std::string getName() { return str; }
53protected:
54  ProtectedBase(const char* s): str(s), instanceMemberVariable(0), anEnum(EnumVal1), stringMember(0), protectedenum(ProtEnumVal1) {}
55  virtual ~ProtectedBase() { }
56  virtual std::string virtualMethod() const { return "ProtectedBase"; }
57  Klass instanceMethod(Klass k) const { return k; }
58  Klass *instanceOverloaded(Klass *k) const { return k; }
59  Klass *instanceOverloaded(Klass *k, std::string name) const { return new Klass(name); }
60  static Klass staticMethod(Klass k) { return k; }
61  static Klass *staticOverloaded(Klass *k) { return k; }
62  static Klass *staticOverloaded(Klass *k, std::string name) { return new Klass(name); }
63  int instanceMemberVariable;
64  static int staticMemberVariable;
65  static const int staticConstMemberVariable = 20;
66  AnEnum anEnum;
67  char *stringMember;
68
69// unsupported: types defined with protected access and thus methods/variables which use them
70  enum ProtectedEnum { ProtEnumVal1, ProtEnumVal2 };
71  typedef int IntegerType;
72  ProtectedEnum protectedenum;
73  IntegerType typedefs(IntegerType it) { return it; }
74};
75int ProtectedBase::staticMemberVariable = 10;
76
77%}
78