Mapping a constant its associated type using templates
I earlier posted this in c.l.c++. Because I worded it poorly I didn't
get any response. I am trying it again here.
I have a class supplied by a third-party library that models a column
in a DB like so:
struct Column
{
enum Type
{
BOOL = 1,
INT = 2,
FLOAT = 3
// so on and so forth
};
Type getType(); // datatype of this column
};
The vendor API allows me get a column pointer given the name:
Column* c = APIPtr->column("BID");
The API also provides a function that is overloaded for several types
to extract a value related to a column:
APIPtr->get(Column* c, int& val);
APIPtr->get(Column* c, char const*& val);
APIPtr->get(Column* c, double& val);
// and so on
If I have a vector of such column pointers:
std::vector<Column*> columnCont;
I want to find a good way to iterate through the container, peruse the
type information already stored in the Column pointer (using the Type
enum) and extract the value of its fields. I am thinking it involves
somehow mapping that constant (Type) to its associated datatype --
something like type traits. Trouble is I can't seem to find a right
way to do this. I am still learning my way around templates and any
insights or even pointers in the right direction would be greatly
appreciated.
thanks!
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]