/
demo.cpp
87 lines (55 loc) · 2.26 KB
/
demo.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright John R. Bandela 2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "DemoInterface.hpp"
#include <iostream>
using namespace std;
void test(cross_compiler_interface::use_interface<DemoInterface> iDemo){
// Test out base
cout<< "Hello from base = " << iDemo.hello_from_base() << endl;
cout << "plus_5(5) = " << iDemo.plus_5(5) << endl;
cout << "times_2point5(4) = " << iDemo.times_2point5(4) << endl;
int i = 4;
iDemo.double_referenced_int(i);
cout << "double_referenced_int(i) where i=4 = " << i << endl;;
cout << "count_characters(\"Hello World\") = " << iDemo.count_characters("Hello World") << endl;
cout << "say_hello(\"John\") = " << iDemo.say_hello("John") << endl;
cout << "Split \"This is a test\" into worlds " << endl;
for(auto s:iDemo.split_into_words("This is a test")){
cout << s << endl;
}
try{
iDemo.use_at_out_of_range("Test");
}
catch(std::out_of_range&){
cout << "Caught out_of_range exception for use_at_out_of_range " << endl;
}
try{
iDemo.not_implemented();
}
catch(cross_compiler_interface::error_not_implemented&){
cout << "Caught cross_compiler_interface::error_not_implemented exception for not_implemented() " << endl;
}
cout << "Use passed in IGetName that returns \"My name is IGetName\"" << endl;
cross_compiler_interface::implement_interface<IGetName> ign;
ign.get_name = [](){return "My name is IGetName";};
cout << "say_hello2 = " << iDemo.say_hello2(ign.get_use_interface()) << endl;
std::vector<std::string> v;
v.push_back("This");
v.push_back("is");
v.push_back("a");
v.push_back("test");
auto p = iDemo.get_string_at(v,3);
cout << "String at " << p.first << " " << p.second << endl;
}
int main(){
cross_compiler_interface::module m("DemoDLL");
cross_compiler_interface::use_interface<DemoInterface> iDemo(cross_compiler_interface::create<DemoInterface>(m,"CreateDemoInterface"));
test(iDemo);
// Now test inheritance
cross_compiler_interface::implement_interface<DemoInterface> imp_demo;
imp_demo.hello_from_base = [](){return std::string("Hello from imp_demo");};
imp_demo.set_runtime_parent(iDemo);
test(imp_demo.get_use_interface());
}