I have to write following type of code
if ( itr->second == "char" )
{
MemberProperty<Owner,char> *ptr = (MemberProperty<Owner, char> *)GetterSetterItr->second;
pw->writeChar(itr->first.c_str() ,(pOwner->*(ptr->m_Getter))());
} else if ( itr->second == "wchar" ) {
MemberProperty<Owner,wchar_t> *ptr = (MemberProperty<Owner, wchar_t> *)GetterSetterItr->second;
pw->writeWideChar(itr->first.c_str() ,(pOwner->*(ptr->m_Getter))());
}
There are going to be many types, is there any c++ trick, preferably template tricks, to reduce this to one single call for this type of code.
Assuming writeChar() and writeWideChar() are identical except for parameter types, you could restructure your code like this:
Then in the class of which *pw is an instance, replace writeChar and writeWideChar with a template member function: