我有很多这样的函数:
void Business::convertDataToListEntityOfTypeX() // X = A,B,C.....
{
QByteArray tmp = getData();
bool ok;
QVariantList result = parse (tmp,&ok);
if (ok) {
for (int i = 0; i < result.size(); ++i) {
TypeXEntity e;
convertVariantToTypeXEntity(result[i],e);
typeXEntityList.push_back(e);//typeXEntityList are private variables in Business
}
}
}
我想将它们分组为一个像这样的函数
enum Type{TypeA, TypeB};
void Business::convertDataToListEntity(Type tp)
{
QByteArray tmp = getData();
bool ok;
QVariantList result = parse (tmp,&ok);
if (ok) {
for (int i = 0; i < result.size(); ++i) {
TypeXEntity e;// need a magic function map the enum with TypeXEntity
convertVariantToTypeXEntity(result[i],e);
typeXEntityList.push_back(e);//need a magic function map the enum with TypeXEntityList
}
}
}
那么有没有办法用Qt
或Boost
(Qt优先)做到这一点?
赞赏任何想法:)