Pulling an object's functions through to a single point of entry interface
Here's a nice generic problem that I'm trying to think about the best way to approach.
Basically I have a class Thingy with a bunch of methods, some of which are overloaded by name, and have different numbers of arguments etc.
I want to create a class ThingyWrapper with an invoke method with approximate arguments invoke(string, VaryingTypeArray args) where the second argument is an array of objects of some variant type capable of representing any of the types common in some client scripting environment (int, double, string, arrays thereof), and the first argument is a string giving the name of the method on a member Thingy to invoke with the specified argument.
So if you call thingyWrap.invoke("someFunction", argsForSomeFunction) you get m_thingy.someFunction(arg1, arg2, ...) where the types of the arguments have been deduced, the arguments have been cast to the appropriate types and used to call someFunction on m_thingy.
Essentially, the thingyWrapper creates a single point of entry for Thingy objects for import in some other environment.
I haven't got that far with my train of thought but I'd be interested to hear about potential approaches people can think of. or if you've done it before. As generic as possible, because doing this the long-winded way is pretty easy (massive switch statements etc.) but a pain to maintain if the interface of Thingy ever changes.
As hinted above, the ultimate purpose of this is to make it easy for me to export the interface into some non C++ scripting environments, e.g. Python and Javascript (via ActiveX).
The VaryingType object/type/struct will basically just be a pair containing type information and some sort of agnostic data store.
It'd be cool if you could do it as a template class, i.e. template <class Wrapped> SinglePointOfEntry, that's getting interesting though *grin*.
The whole idea is reminiscent of interoperability setups with marshalled parameters and so on, but I don't want to have to rely on a specific one of those, even though I guess I could probably use COM given what my requirements are going to be.
If the whole idea is maintainability suicide or stupid for some reason that'd be good to know as well. I am interested in solutions that both do and don't use RTTI.
Basically I have a class Thingy with a bunch of methods, some of which are overloaded by name, and have different numbers of arguments etc.
I want to create a class ThingyWrapper with an invoke method with approximate arguments invoke(string, VaryingTypeArray args) where the second argument is an array of objects of some variant type capable of representing any of the types common in some client scripting environment (int, double, string, arrays thereof), and the first argument is a string giving the name of the method on a member Thingy to invoke with the specified argument.
So if you call thingyWrap.invoke("someFunction", argsForSomeFunction) you get m_thingy.someFunction(arg1, arg2, ...) where the types of the arguments have been deduced, the arguments have been cast to the appropriate types and used to call someFunction on m_thingy.
Essentially, the thingyWrapper creates a single point of entry for Thingy objects for import in some other environment.
I haven't got that far with my train of thought but I'd be interested to hear about potential approaches people can think of. or if you've done it before. As generic as possible, because doing this the long-winded way is pretty easy (massive switch statements etc.) but a pain to maintain if the interface of Thingy ever changes.
As hinted above, the ultimate purpose of this is to make it easy for me to export the interface into some non C++ scripting environments, e.g. Python and Javascript (via ActiveX).
The VaryingType object/type/struct will basically just be a pair containing type information and some sort of agnostic data store.
It'd be cool if you could do it as a template class, i.e. template <class Wrapped> SinglePointOfEntry, that's getting interesting though *grin*.
The whole idea is reminiscent of interoperability setups with marshalled parameters and so on, but I don't want to have to rely on a specific one of those, even though I guess I could probably use COM given what my requirements are going to be.
If the whole idea is maintainability suicide or stupid for some reason that'd be good to know as well. I am interested in solutions that both do and don't use RTTI.
