PageRenderTime 10ms CodeModel.GetById 8ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 53 lines | 40 code | 13 blank | 0 comment | 0 complexity | 1a8aa484a28f6e41c6c8d116181cb7a5 MD5 | raw file
 1%module(directors="1") director_classic
 2
 3%include "std_string.i"
 4
 5%feature("director");
 6
 7%inline %{
 8
 9#include <cstdio>
10#include <iostream>
11#include <string>
12
13struct Being {
14  virtual std::string id() { return "Being"; }
15  virtual ~Being() {}
16};
17
18struct Person : Being {
19  virtual std::string id() { return "Person"; }
20};
21
22struct Child : Person {
23  virtual std::string id() { return "Child"; }
24};
25
26struct GrandChild : Child {
27  virtual std::string id() { return "GrandChild"; }
28};
29
30// Orphans - don't override id() in C++
31struct OrphanPerson : Person {
32  // no overridden id()
33};
34
35struct OrphanChild : Child {
36  // no overridden id()
37};
38
39class Caller {
40private:
41  Person *_callback;
42public:
43  Caller(): _callback(0) {}
44  ~Caller() { delCallback(); }
45  void delCallback() { delete _callback; _callback = 0; }
46  void setCallback(Person *cb) { delCallback(); _callback = cb; }
47  void resetCallback() { _callback = 0; }
48  std::string call() { if (_callback) return _callback->id(); else return "oops";  }
49  Person* baseClass() { return _callback; }
50};
51
52%}
53