/* @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 #include #include using namespace classdesc; using namespace boost::python; #include #include #include #include #include #include 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 c1; int d[3]; int d1[3][2]; std::vector h; std::list l; std::map m; std::list > llex; Exclude iex; std::vector vs; EnumFoo ef; std::shared_ptr sef; //string (*hello)(); // still not working ... classdesc::StringKeyMap 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(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& x) { return x.size(); } std::vector 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 vFoo; static tuple varArgExample(tuple args, dict kw) { Bar& self=extract(args[0]); std::cout << self.f << std::endl; return make_tuple(args,kw); } static pointer_wrapper self(const tuple& args, const dict& kw) { return ptr(&extract(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 fp{new Foo}; int g; EnumFoo barfoo; std::vector 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"