Guest User

Untitled

a guest
Apr 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class VirtualBase {
  4. public:
  5. VirtualBase() { std::cout << "init from VirtualBase" << std::endl; }
  6. virtual int doWork() {
  7. std::cout << "doing work from c++" << std::endl;
  8. return 0;
  9. }
  10. virtual int processWorker() = 0;
  11. };
  12.  
  13.  
  14.  
  15. #include "rice/Director.hpp"
  16. using namespace Rice;
  17.  
  18. class VirtualBaseProxy : public VirtualBase, public Rice::Director {
  19. public:
  20. VirtualBaseProxy(Object self) : Rice::Director(self) { }
  21.  
  22. virtual int doWork() {
  23. std::cout << "salut!!" << std::endl;
  24. if(callIsFromRuby("do_work")) {
  25. std::cout << "hello!!" << std::endl;
  26. return VirtualBase::doWork();
  27. } else {
  28. return from_ruby<int>( getSelf().call("do_work") );
  29. }
  30. }
  31.  
  32. virtual int processWorker() {
  33. if(callIsFromRuby("process_worker")) {
  34. raisePureVirtual();
  35. } else {
  36. return from_ruby<int>( getSelf().call("process_worker") );
  37. }
  38. }
  39. };
  40.  
  41. #include "rice/Constructor.hpp"
  42.  
  43. extern "C"
  44. void Init_virtual() {
  45. // See Caveat below
  46. define_class<VirtualBase>("__VirtualBase__");
  47. // .define_method("do_work", &VirtualBase::doWork);
  48.  
  49. define_class<VirtualBaseProxy, VirtualBase>("VirtualBase")
  50. .define_constructor(Constructor<VirtualBaseProxy, Object>())
  51. .define_method("do_work", &VirtualBaseProxy::doWork)
  52. .define_method("process_worker", &VirtualBaseProxy::processWorker);
  53. }
Add Comment
Please, Sign In to add comment