I'm relatively new to C ++ - I adapted it about 6 years ago, but never used it until a few months ago.
What is a scenario:
- Significantly large system with a large number of modules.
Output Required:
- Modules (namely X) "expose" certain functions for a call over the network and return the result to the caller (namely Y)
- Caller Y does not know information about X, despite the fact that it was exposed by the library (function name and parameters).
- A function call from X from the library must occur through a string obtained from Y - or a set of strings, since there will also be parameters.
Ideally, what I want to have is something more general with the possible types of return / parametric variables or some type of erasure - due to the fact that I do not know what functions each module wants to expose. I find it pretty utopian to get something like this working in C ++. But hopefully with predefined possible return types / parameters this is possible. Communication is not a problem at present; what matters is what needs to be done on the module side.
Question:
- Is it possible to accomplish such a thing with C ++ and Boost? I would be very grateful if someone could give me some recommendations - examples of literature / textbooks / (pseudo), etc. Etc. I do not expect a complete solution here.
Possible Solution:
I lost a little what kind of “functionality” of languages that I can / should use, mainly due to my limitations in the project.
I thought about using Variadic templates and found the question below that really helps, the only problem is that Variadic Templates are not supported in VS2010.
Common functor for functions with any argument list
After several extensive research on the Internet, the immediate answer I received was as follows:
map of pointers to functions of different types of returns and signatures
The scenario is almost the same. However, the difference is that the OP already knows in advance about the return / parameters of the functions that it will use. Due to my low reputation (I just joined) I, unfortunately, cannot ask / comment anything.
TBH I understood so well how to accomplish what explains the selected answer.
Using maps is a way, but I would have to store objects containing pointers to functions (as well as answers to the question), but, as it can be seen in the code provided by the user, encoded things that I did not want to have.
Additional explanations:
- Yes, I am limited to using C ++ and VS2010 SP1.
- No, despite Boost, I cannot use any third library - it would be great to use some Reflection libraries, such as CPGF http://www.cpgf.org/ (although I am not 100% sure if this is what I really needed)
Minor change: - Linking a scripting language (e.g. LUA) is really a way, but I did not want to include it in the project.
I hope someone can shed light on this issue!
Thank you in advance for any input!
c ++ boost visual-studio-2010 function-pointers
skullmetal
source share