PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 53 lines | 35 code | 14 blank | 4 comment | 0 complexity | a109cfb724992b20be104f0e7e53be8e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module template_typedef_funcptr
  2. //Bug #1832613
  3. #if !defined(SWIGR)
  4. // R Swig fails on this test. Because it tries to return a nil SEXP in
  5. // an error
  6. %include <std_string.i>
  7. %inline %{
  8. #include <string>
  9. template<typename T> class Ptr {};
  10. class MCContract {};
  11. typedef Ptr<MCContract> MCContractPtr;
  12. %}
  13. %template() Ptr<MCContract>;
  14. %inline %{
  15. template <class Contract, typename ContractID, typename CallbackType>
  16. class ContractFactory
  17. {
  18. public:
  19. static ContractFactory<Contract,ContractID,CallbackType> &getInstance() {
  20. static ContractFactory<Contract, ContractID, CallbackType> instance;
  21. return instance;
  22. }
  23. };
  24. /**
  25. * CreateXXContractCallback is a pointer to a function taking no arguments and
  26. * returning a pointer to an XXContract.
  27. */
  28. typedef MCContractPtr (*CreateMCContractCallback)();
  29. %}
  30. //Get around it by changing this:
  31. %template(MCContractFactory) ContractFactory<MCContract, std::string, CreateMCContractCallback>;
  32. //to a form which expands the typedef:
  33. //%template(MCContractFactory) ContractFactory<MCContract, std::string, Ptr<MCContract>(*)()>;
  34. %inline %{
  35. typedef MCContractPtr* ContractPtrPtr;
  36. %}
  37. // Plain pointers were also causing problems...
  38. %template(MCContractFactory2) ContractFactory<MCContract, std::string, ContractPtrPtr>;
  39. #endif