I would like to save some settings made by the user to a file. I have a class called Project
and would like to store the values of the member. I've worked a lot with Java and there I would do it with reflection, but now I have to find a solution for C++ (not having this feature).
My idea:
class Project
{
Project();
public:
//Getter and Setter for private member...
private:
string mProjectName; //(="Test")
string mProjectCreator;
}
class ProjectParser
{
ProjectParser();
public:
void SaveProject(Project* aProjectPtr)
{
//do stuff with the example below
}
}
The ProjectParser would contain a pair list like this:
std::pair<[memberName],[memberFunction]>("projectName",&Project::GetProjectName)...
To save the member of a Project to a file the function
SaveProject(Project* aProjectPtr)
of the ProjectParser should be called and would do:
- Iterate the pairs with [memberName] and [memberFunction]
- Get return of [memberFunction] (together with the Project instance)
- Write value for [memberName] (for example in a JSON file or XML)
projectName:"Test"
But beeing new to C++, I have no clue how to execute the member function for a instance of an object and how to get the return value. Is there a possibility to do it like this?