Problem
Assume there is a set of different functions. Each of there functions may be a member function of some object, and may take an arbitary number of arguments. For simplicity sake lets assume that each function has no more than 8 arguments of int, double or std::string types. For example:
class MyClass{
public:
void DoA(int i);
void DoB(double d, int i);
};
class YourClass{
public:
void DoC(std::string s);
void DoD(int i1, int i2, int i3);
};
Lets assume there is a file containing a series of records about functions. Each record contains name of the function to be called, its arguments values and pointer to the object for the member function. I need a way to read all this data from the file and execute functions in correct order with correct arguments.
It is okay to have names of the functions hard-coded, for example, but adding a new function to a libary should be as easy as possible.
Motivation
This is a part of roguelike game project I’m trying to create, specifically a save/load game system. Once a player tries to save his game, all events that have not yet occurred must be saved too, and next time the player loads the game events should be loaded and scheduled properly. Since roguelike is clearly needs a lot of space to expand, I don’t want to make any assumptions about the functions type.
Here’s an idea:
Input file:
Parsing: