I am trying to build a custom ORM. Here is a basic code for the same.
class modelField
{
public:
modelField(int size) {__size__=size;};
modelField() {};
virtual ~modelField() {};
virtual std::string __type__() = 0;
virtual void set(std::string) = 0;
virtual void set(int) = 0;
int __size__ = -1;
};
class charField : public modelField
{
public:
charField(int value) : modelField(value) {};
charField() : modelField() {};
virtual void set(std::string val) {__value__ = val;};
virtual void set(int) {};
std::string __type__();
private:
int size;
std::string __value__;
};
Now charField in this is just a column type, i have more ranging from int to double. Currently, i made two virtual methods set
and overloaded them to accept diffrent data types. But this doesn't seem to be the best way to go. How can i make a generic function that can accept string/int/double or other values passed to the same.
There probably is some solution in template although i am not able to think of any.
Another thing that i should mention is that modelField
is only base there can be other fields like lets say IPv4 addr
which is a child of charField.
Thanks in advance for any suggestions.