Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » template + convert problem
Re: template + convert problem [message #23161 is a reply to message #23160] |
Sun, 20 September 2009 12:08  |
Didier
Messages: 728 Registered: November 2008 Location: France
|
Contributor |
|
|
After another look, something is missing. You mixed up type passing (template paremeters), and specific value fixing (you're parameters).
You need a constructor, no need for template !
The following code compiles:
struct ConvDict : Convert
{
private:
const SqlId TBL;
const SqlId ID;
const SqlId NAME;
const int CLEARTIME;
public:
ConvDict(SqlId tbl ,SqlId id, SqlId name,int clearTime)
: TBL(tbl)
, ID(id)
, NAME(name)
, CLEARTIME(clearTime)
{
}
virtual Value Format(const Value& q) const
{
if(q.IsNull()) return Null;
static VectorMap<int, String> dict;
static Time lastcleartime;
if(GetSysTime()-lastcleartime > CLEARTIME)
{
dict.Clear();
lastcleartime=GetSysTime();
}
int f = dict.Find(int(q));
if(f >= 0)
{
return dict[f];
} else {
Sql sql;
sql * Select(NAME).From(TBL).Where(ID == q);
String s;
if(sql.Fetch()) {
int sid = int(q);
s = sql[NAME];
dict.Add(sid, s);
} else {
s = "";
}
return s;
}
}
};
|
|
|
Goto Forum:
Current Time: Wed Jun 18 11:53:48 CEST 2025
Total time taken to generate the page: 0.05071 seconds
|