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 13 struct Being { idBeing14 virtual std::string id() { return "Being"; } ~BeingBeing15 virtual ~Being() {} 16 }; 17 18 struct Person : Being { idPerson19 virtual std::string id() { return "Person"; } 20 }; 21 22 struct Child : Person { idChild23 virtual std::string id() { return "Child"; } 24 }; 25 26 struct GrandChild : Child { idGrandChild27 virtual std::string id() { return "GrandChild"; } 28 }; 29 30 // Orphans - don't override id() in C++ 31 struct OrphanPerson : Person { 32 // no overridden id() 33 }; 34 35 struct OrphanChild : Child { 36 // no overridden id() 37 }; 38 39 class Caller { 40 private: 41 Person *_callback; 42 public: Caller()43 Caller(): _callback(0) {} ~Caller()44 ~Caller() { delCallback(); } delCallback()45 void delCallback() { delete _callback; _callback = 0; } setCallback(Person * cb)46 void setCallback(Person *cb) { delCallback(); _callback = cb; } resetCallback()47 void resetCallback() { _callback = 0; } call()48 std::string call() { if (_callback) return _callback->id(); else return "oops"; } baseClass()49 Person* baseClass() { return _callback; } 50 }; 51 52 %} 53 54