-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpythonExample.h
168 lines (150 loc) · 3.86 KB
/
pythonExample.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
@copyright Russell Standish 2000-2013
@author Russell Standish
This file is part of Classdesc
Open source licensed under the MIT license. See LICENSE for details.
*/
#include <classdesc.h>
#include <stringKeyMap.h>
#include <python_base.h>
using namespace classdesc;
using namespace boost::python;
#include <string>
#include <vector>
#include <list>
#include <map>
#include <math.h>
#include <string.h>
enum EnumFoo {ea, eb, ec=12, ed};
string printHello() {return "hello";}
struct Foo
{
const static int csi=20;
static int si;
char ch;
double a;
float af;
int b;
bool bf, bt;
std::string c;
std::vector<std::string> c1;
int d[3];
int d1[3][2];
std::vector<int> h;
std::list<int> l;
std::map<int,int> m;
std::list<std::list<std::string> > llex;
Exclude<int> iex;
std::vector<string> vs;
EnumFoo ef;
std::shared_ptr<EnumFoo> sef;
//string (*hello)(); // still not working ...
classdesc::StringKeyMap<int> sm;
Foo() {}
Foo(int i): ch('M'), a(0.1), af(0.2), b(i), bf(false), bt(true),
c("\r hello & 123 "), c1(2,"\r"), h(3,2), l(3,2),
llex(2,std::list<std::string>(2,"hello")),
vs(2," hello"), ef(ea)//, hello(printHello)
{
for (int i=0; i<3; i++)
{
d[i]=i;
for (int j=0; j<2; ++j)
d1[i][j]=2*i+j;
}
m[0]=5; m[3]=2;
}
string vs0() const {return vs[0];}
static string shello() {return "hello";}
int getEF() {return ef;}
string getc() {return c;}
size_t seqLength(const std::vector<int>& x) {
return x.size();
}
std::vector<string> getVS() const {return vs;}
virtual std::string name() const {return "Foo";}
// function pointer member not yet supported
// int (Foo::* memPtrEx)(int);
// int (*ptrEx)(int);
};
enum GlobE {ga,gb};
struct Bar: Foo
{
enum BarE {a, b};
Bar(const Bar&)=delete;
int f;
EnumFoo barfoo;
std::vector<Foo> vFoo;
static tuple varArgExample(tuple args, dict kw) {
Bar& self=extract<Bar&>(args[0]);
std::cout << self.f << std::endl;
return make_tuple(args,kw);
}
static pointer_wrapper<Bar*> self(const tuple& args, const dict& kw) {
return ptr(&extract<Bar&>(args[0])());
}
Bar& overloadExample() {return *this;}
int overloadExample(int x, int y=0) const {return x+y;}
// test overloading
BarE barE(BarE e) const {return e;}
BarE barE() const {return a;}
GlobE globE() const {return ga;}
Bar() {}
Bar(int i): Foo(i), f(20), barfoo(eb), vFoo(3,1) {}
std::string name() const override {return "Bar";}
Foo& foo() {return *this;}
};
struct Bar1
{
Foo f;
shared_ptr<Foo> fp{new Foo};
int g;
EnumFoo barfoo;
std::vector<Foo> vFoo;
Bar1() {}
Bar1(int i): f(i), g(2), barfoo(ec), vFoo(2,Foo(1)) {}
Foo foo() {return f;}
Foo& fooRef() {return f;}
Foo* foop() {return &f;} // should be ignored, as can't determine ownership
static Foo* sfoop() {return nullptr;}// should be ignored, as can't determine ownership
static Foo* sfoop(int) {return nullptr;}// should be ignored, as can't determine ownership
Bar1& recursiveType(const Bar1&) {return *this;} // tests a recursive type definition bug
Bar1& recursiveType(const char* x) {return *this;} // tests another parsing bug
Bar::BarE barE(Bar::BarE x) {return x;} // tests another parsing bug
};
struct FooBar1
{
Foo f{0};
};
// extra class to test that argument types are automatically registered
struct DD
{
int a;
};
// abstract and default constructorless tests
struct Abstract
{
virtual int foo()=0;
int bar() const {return 2;}
};
struct Defaultless: public Abstract
{
Defaultless(int) {}
int foo() override {return 0;}
};
// root type
struct Root
{
Defaultless defaultless{1};
Bar bar;
Bar1 bar1;
static Bar sbar;
FooBar1& getFB1() {
static FooBar1 m;
return m;
}
double fb1a() {return getFB1().f.a;}
Root(): bar(3), bar1(2) {}
void dummy(DD& x) {}
};
#include "pythonExample.cd"