List of template classes
Good day,
I have the following code and am uncertain as to how it should best done / =
thought of. I'm creating a "data access layer", and am aware that there are=
c++ libraries for this, but am just doing it for the practice. I would lik=
e to have a dbField class, that holds the various column info, that is the =
name, type and data. A dbClass would then hold a list of dbFields, mapping =
to the columns available in the table. The dbField will thus have different=
data depending on that of the database column, i.e. integer / varchar / bi=
t etc.
My implementation thinking is as follows
enum eDbFieldType
{
Varchar, Integer, Boolean
};
template <class T>
class dbField
{
private:
// Name of column in the database
QString fieldName;
// Column datatype
eDbFieldType dtColumn;
// Data the field contains
T data;
public:
void setData(T);
T getData();
};
class DbClass
{
private:
map<QString, dbField<> > mDbFields;
....
After loading the data from the database into the dbField, I may have to do=
other things to it depending on its type, for example to base64 decode/enc=
ode, etc when getData() is called, and then return the data.
I figure I could use a void* for data, is that what is generally done in th=
is type of situation? I've read that templates are preferable to void* but =
is that the case here and can they be used? Or should I be thinking differe=
ntly and do something different? I'm ideally trying to avoid casting.