mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-04 17:15:23 -06:00
bazaar: BoostPyTest: Callbacks improvements, CtrlCore / TopWindow export at 80%, virtual methods and eval examples, ValueMap export; ValueCtrl: ValueMap and ErrorValue editor
git-svn-id: svn://ultimatepp.org/upp/trunk@3421 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a5dd6dbe7b
commit
ac648bbee1
10 changed files with 730 additions and 115 deletions
|
|
@ -3,25 +3,102 @@ using namespace boost::python;
|
|||
//#include <iostream>
|
||||
//using namespace std;
|
||||
|
||||
|
||||
class WorldWrap : public World, public wrapper<World> {
|
||||
public:
|
||||
virtual std::string vir(int a) const {
|
||||
//if pure virtual
|
||||
#if PUREVIRTEST
|
||||
return this->get_override("vir")(a);
|
||||
#else
|
||||
//from c++ calls to WorldWrap instaces as World instance (i.e. InvokeWorld)
|
||||
//calls python derived function if present, or base function.
|
||||
if(override f = this->get_override("vir"))
|
||||
return f(a);
|
||||
return World::vir(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PUREVIRTEST
|
||||
#else
|
||||
//from python calls this, if not derived in python
|
||||
//if vir derived in python, gets called directly
|
||||
std::string default_vir(int a) const {
|
||||
return World::vir(a);
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
std::string InvokeWorld(const World& w, int a) //for testing the instances from python env
|
||||
{
|
||||
return w.vir(a);
|
||||
}
|
||||
|
||||
class UniverseWrap : public Universe, public wrapper<Universe> {
|
||||
public:
|
||||
virtual std::string vir(int a) const {
|
||||
//if pure virtual
|
||||
#if PUREVIRTEST
|
||||
return this->get_override("vir")(a);
|
||||
#else
|
||||
//from c++ calls to WorldWrap instaces as World instance (i.e. InvokeWorld)
|
||||
//calls python derived function if present, or base function.
|
||||
if(override f = this->get_override("vir"))
|
||||
return f(a);
|
||||
return Universe::vir(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PUREVIRTEST
|
||||
#else
|
||||
//from python calls this, if not derived in python
|
||||
//if vir derived in python, gets called directly
|
||||
std::string default_vir(int a) const {
|
||||
return Universe::vir(a);
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
void export_world()
|
||||
{
|
||||
ONCELOCK
|
||||
{
|
||||
class_<World, boost::noncopyable>("World", "A simple world")
|
||||
class_<WorldWrap, boost::noncopyable>("World", "A simple world"
|
||||
#if 0 //PUREVIRTEST, not needed though abstract, otherwise it cant instantiate in python
|
||||
, no_init
|
||||
#endif
|
||||
)
|
||||
//.def(init<const World&>())
|
||||
.def("__str__", &World::get) //somehow works only for print not for general return as string echo
|
||||
.def("greet", &World::greet)
|
||||
.def("get", &World::get)
|
||||
.def("set", &World::set)
|
||||
#if PUREVIRTEST
|
||||
.def("vir", pure_virtual(&World::vir))
|
||||
#else
|
||||
.def("vir", &World::vir, &WorldWrap::default_vir)
|
||||
#endif
|
||||
;
|
||||
|
||||
class_<Universe, bases<World>, boost::noncopyable >("Universe", "A simple Universe")
|
||||
//.def(init<const World&>())
|
||||
def("invworld", &InvokeWorld);
|
||||
|
||||
class_<UniverseWrap, bases<World>, boost::noncopyable >("Universe", "A simple Universe")
|
||||
//.def(init<const Universe&>())
|
||||
.def("__str__", &Universe::getg) //somehow works only for print not for general return as string echo
|
||||
.def("getg", &Universe::getg)
|
||||
.def("setg", &Universe::setg)
|
||||
#if 1
|
||||
//somehow does not override the World export of vir
|
||||
#if PUREVIRTEST
|
||||
.def("vir", pure_virtual(&Universe::vir))
|
||||
#else
|
||||
.def("vir", &Universe::vir, &UniverseWrap::default_vir)
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue