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