I have a a bunch of subclasses each with static class factory methods of varying argument numbers and types, and would also like to instantiate them from data loaded via a json data file using jsonpp.
So say I'll have an array of Json::Value objects for the arguments, is there a smart way, using macros or something in c++ to create alternate proxy methods that accepts the Json::Value array and calls the original method, e.g.)
Foo* Foo::create(int a, const char* b) { /* ... */ }
Foo* Foo::create(Json::Value args) { //the Json::Value args represents an array value here
// can I avoid having to manually create each of these Json methods?
return Foo::create(args[0].asInt(), args[1].asCString());
}
Sorry, my c++ is still getting up to speed. I've found a few topics that seem to deal with unpacking tuple arguments for example,
- C++11: I can go from multiple args to tuple, but can I go from tuple to multiple args?
- How do I expand a tuple into variadic template function's arguments?
- Any Solution to Unpack a Vector to Function Arguments in C++?
but I am unsure of which approach to proceed with. Thanks for the help