Wrap C++ function using Boost Reflect or another C++ reflection library -
i posted this question. spongebobfan
said answer reflection. found boost.reflect , wondering how heck can pull off using library or c++ reflection library. please explain answer, cannot glance @ code , figure out what's going on. question this:
ok, have question. have code:
int myfunc(int arg-a, int arg-b); int mywrapperfunc(obj a, obj b);
mywrapperfunc
supposed wrap myfunc
. mywrapperfunc
discards first argument , takes second, array. uses array items parameters. don't know how many parameters myfunc
takes, nor know how many items in array-type object (b
). how programatically call myfunc
correct number of args? number of args handed on same number of items in array-type object.
edit: arg-a
, arg-b
supposed come array-type object. split object args.
edit: ok, ok, i'm trying wrap python c api sense involved, hiding background jobs.
have looked @ reflex? tool uses gcc-xml create reflection library similar 1 in java.
here's initial take on (i don't have lot of free time flush out further):
// use reflex library "myfunc" reflectively type t = type::byname("myfunc"); // reflex type 'type" has "functionparametersize()" tells // how many args in function size_t num_params = t.functionparametersize(); // use information call "myfunc" objects "b"
if reflex provides invocation capability on member of class, make myfunc()
static class member, , try this:
// load myclass reflectively (where myclass contains static member function "myfunc") type t = type::byname("myclass"); // find member function "myfunc" member m = t.memberbyname("myfunc"); // pack parameters "b" vector // (assumes "b" has indexing operators, , "length()" function) std::vector params(&b[0], &b[b.length()-1]); // invoke method "myfunc" reflectively m.invoke(params);
you'll have fiddle this, i'm not sure if i'm doing parameter passing correctly, etc. gives new ideas.
Comments
Post a Comment