i'm writing an ADO-like wrapper class for SQLite. I'd like to emulate (and expand upon) their "AsType" methods, but i'm running into trouble mixing template specializations
Code:template<> void castResult(String &arg,char *result) { arg = (String)result; } template<> void castResult(double &arg,char *result) { if(!TryStrToFloat(result,arg)) { throw Exception((String)result+"cannot be cast to double"); } } template<> void castResult(unsigned int &arg,char *result) { if(!TryStrToInt(result,arg)) { throw Exception((String)result+"cannot be cast to int"); } } template<> void castResult(__int64 &arg,char *result) { if(!TryStrToInt64(result,arg)) { throw Exception((String)result+"cannot be cast to double"); } } template<> void castResult(unsigned __int64 &arg,char *result) { if(!TryStrToInt64(result,arg)) { throw Exception((String)result+"cannot be cast to double"); } } template<> void castResult(bool &arg,char *result) { if(!TryStrToBool(result,arg)) { throw Exception((String)result+"cannot be cast to bool"); } } template<> void castResult(TDateTime &arg,char *result) { if(!TryStrToTime(result,arg)) { throw Exception((String)result+"cannot be cast to TDateTime"); } } template<> void castResult(int &arg,char *result) { if(!TryStrToInt(result,arg)) { throw Exception((String)result+"cannot be cast to double"); } } template<typename T> T __fastcall field(char *colName) { T t; castResult<T>(t,results[colNumber(colName)+cols*recordOffset]); return t; } template<typename T> T __fastcall field(char *colName,unsigned int row) { if(row>=rows) { invalidRow(row); } T t; return castResult(t,results[colNumber(colName)+cols*(row+1)]); } template<typename T> T __fastcall field(unsigned int col) { if(col>=cols) { invalidCol(col); } T t; return castResult(t,results[col+cols*recordOffset]); } template<typename T> T __fastcall field(unsigned int col,unsigned int row) { if(row>=rows) { invalidRow(row); } if(col>=cols) { invalidCol(col); } T t; return castResult(t,results[cols*(row+1)+col]); }Code:sqlitedb::sqlResult *result = db.exec("select reportData.RPTID,reportData.SVID from reportData,eventReports where reportData.RPTID = eventReports.RPTID and eventReports.CEID = 0"); unsigned int row = 1; while(!result->eof) { int rptid = result->field<int>("RPTID"); int svid = result->field<int>("SVID"); row++; result->next(); } delete result;
i've tried many different variations, including a T& as an argument to both field and castResult, but for some reason, my compiler won't deduce how to relate non-specialized and specialized templates.
suggestions on the best way to proceed? i'd like not to have to specialize each of the 4 incarnations of field for each type.



LinkBack URL
About LinkBacks


