Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / test-suite / template_typedef_funcptr.i
1 %module template_typedef_funcptr
2
3 //Bug #1832613
4
5 #if !defined(SWIGR)
6 // R Swig fails on this test.  Because it tries to return a nil SEXP in
7 // an error
8
9 %include <std_string.i>
10
11 %inline %{
12
13 #include <string>
14
15 template<typename T> class Ptr {};
16  
17 class MCContract {};
18 typedef Ptr<MCContract> MCContractPtr;
19 %}
20
21 %template() Ptr<MCContract>;
22
23 %inline %{
24 template <class Contract, typename ContractID, typename CallbackType>
25 class ContractFactory 
26 {
27   public:
28     static ContractFactory<Contract,ContractID,CallbackType> &getInstance() {
29       static ContractFactory<Contract, ContractID, CallbackType> instance;
30       return instance;
31     }
32 };
33 /**
34  * CreateXXContractCallback is a pointer to a function taking no arguments and 
35  * returning a pointer to an XXContract. 
36  */
37 typedef MCContractPtr (*CreateMCContractCallback)();
38 %}
39
40
41 //Get around it by changing this:
42 %template(MCContractFactory) ContractFactory<MCContract, std::string, CreateMCContractCallback>;
43
44 //to a form which expands the typedef:
45 //%template(MCContractFactory) ContractFactory<MCContract, std::string, Ptr<MCContract>(*)()>;
46
47 %inline %{
48 typedef MCContractPtr* ContractPtrPtr;
49 %}
50 // Plain pointers were also causing problems...
51 %template(MCContractFactory2) ContractFactory<MCContract, std::string, ContractPtrPtr>;
52
53 #endif