From: Thomas Geymayer Date: Sun, 18 May 2014 21:54:59 +0000 (+0200) Subject: cppbind.Ghost: more member overloads. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1af6cbc1aa070f2fe70682a798ab79d4a5a1a052;p=simgear.git cppbind.Ghost: more member overloads. --- diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 43ed7d0a..7c8f03d1 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -467,6 +467,22 @@ namespace nasal return member(field, to_getter(getter), to_setter(setter)); } + template + Ghost& member( const std::string& field, + const getter_t& getter, + void (raw_type::*setter)(Param) ) + { + return member(field, getter, to_setter(setter)); + } + + template + Ghost& member( const std::string& field, + Ret (raw_type::*getter)() const, + const setter_t& setter ) + { + return member(field, to_getter(getter), setter); + } + /** * Register a read only member variable. * @@ -480,6 +496,18 @@ namespace nasal return member(field, to_getter(getter), setter_t()); } + Ghost& member( const std::string& field, + naRef (*getter)(const raw_type&, naContext) ) + { + return member(field, getter_t(getter), setter_t()); + } + + Ghost& member( const std::string& field, + naRef (*getter)(raw_type&, naContext) ) + { + return member(field, getter_t(getter), setter_t()); + } + /** * Register a write only member variable. * @@ -493,6 +521,18 @@ namespace nasal return member(field, getter_t(), to_setter(setter)); } + Ghost& member( const std::string& field, + void (*setter)(raw_type&, naContext, naRef) ) + { + return member(field, getter_t(), setter_t(setter)); + } + + Ghost& member( const std::string& field, + const setter_t& setter ) + { + return member(field, getter_t(), setter); + } + /** * Register a member variable by passing a getter and/or setter method. * @@ -550,7 +590,7 @@ namespace nasal * { * public: * bool getMember( const std::string& key, - * std::string& value_out ); + * std::string& value_out ) const; * } * * Ghost::init("Test") @@ -558,7 +598,7 @@ namespace nasal * @endcode */ template - Ghost& _get(bool (raw_type::*getter)(const std::string&, Param&)) + Ghost& _get(bool (raw_type::*getter)(const std::string&, Param&) const) { return _get( boost::function(getter) @@ -584,7 +624,7 @@ namespace nasal */ Ghost& _get(bool (raw_type::*getter)( naContext, const std::string&, - naRef& )) + naRef& ) const) { return _get( fallback_getter_t(getter) ); } diff --git a/simgear/nasal/cppbind/cppbind_test.cxx b/simgear/nasal/cppbind/cppbind_test.cxx index 665cb0a9..2af6877b 100644 --- a/simgear/nasal/cppbind/cppbind_test.cxx +++ b/simgear/nasal/cppbind/cppbind_test.cxx @@ -44,7 +44,7 @@ struct Base { return key == "test"; } - bool genericGet(const std::string& key, std::string& val_out) + bool genericGet(const std::string& key, std::string& val_out) const { if( key != "get_test" ) return false; @@ -67,6 +67,16 @@ struct Derived: int getX() const { return _x; } void setX(int x) { _x = x; } }; + +naRef f_derivedGetRandom(const Derived&, naContext) +{ + return naNil(); +} +void f_derivedSetX(Derived& d, naContext, naRef r) +{ + d._x = static_cast(naNumValue(r).num); +} + struct DoubleDerived: public Derived { @@ -237,6 +247,9 @@ int main(int argc, char* argv[]) .bases() .member("x", &Derived::getX, &Derived::setX) .member("x_alternate", &f_derivedGetX) + .member("x_mixed", &f_derivedGetRandom, &Derived::setX) + .member("x_mixed2", &Derived::getX, &f_derivedSetX) + .member("x_w", &f_derivedSetX) .method("free_fn", &derivedFreeMember) .method("free_member", &derivedFreeMember) .method("baseDoIt", &baseFuncCallContext);