]> git.mxchange.org Git - simgear.git/commitdiff
cppbind.Ghost: more member overloads.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 18 May 2014 21:54:59 +0000 (23:54 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 18 May 2014 21:55:43 +0000 (23:55 +0200)
simgear/nasal/cppbind/Ghost.hxx
simgear/nasal/cppbind/cppbind_test.cxx

index 43ed7d0a1159c0a30c96e2fb19a0dd01c403a573..7c8f03d1082026fc529354065b2789d519dd7513 100644 (file)
@@ -467,6 +467,22 @@ namespace nasal
         return member(field, to_getter(getter), to_setter(setter));
       }
 
+      template<class Param>
+      Ghost& member( const std::string& field,
+                     const getter_t& getter,
+                     void (raw_type::*setter)(Param) )
+      {
+        return member(field, getter, to_setter(setter));
+      }
+
+      template<class Ret>
+      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<MyClassPtr>::init("Test")
@@ -558,7 +598,7 @@ namespace nasal
        * @endcode
        */
       template<class Param>
-      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<bool (raw_type&, const std::string&, Param&)>(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) );
       }
index 665cb0a919e3eb2d1d38f899248f420b407ab4eb..2af6877bca58a601a4e32a02a340af6ee2a9dc6e 100644 (file)
@@ -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<int>(naNumValue(r).num);
+}
+
 struct DoubleDerived:
   public Derived
 {
@@ -237,6 +247,9 @@ int main(int argc, char* argv[])
     .bases<BasePtr>()
     .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);