Lets say, I have a class, which can have many variables. Each of these variables will have an unique enum mapped to it. I want to set/get values to variables using switch case. Instead of writing each time "case" for each variable, I want to have macro which expands to the set/get functions and corresponding switch case.
class myClass
{
int m_i, m_j;
void Set(int variable, int i);
void Get(var variable, int& i);
};
enum var{ VAR_I, VAR_J };
//..........cpp.........
//here I will map enum to member variables
//so if i write this.
//
VARIABLE_START(myClass)
VARIABLE(VAR_I, m_i)
VARIABLE(VAR_J, m_j)
VARIABLE_END
//it should expand to....
void myClass::Set(var variable, int i)
{
switch(var)
{
case VAR_I: ....
break;
case VAR_J: ....
break;
}
}
void myClass::Get(var variable, int& i)
{
switch(var)
{
case VAR_I: ....
break;
case VAR_J: ....
break;
}
}
Now I am facing problem in defining those macros, which should expands to two (or more) member functions with switch cases for each member variable. Any sort of help is appreciated. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire