I am trying to make a template class that will hold me variables to be used with a shader class. These classes pretty much hold the variable itself and its type (an enum value). Here is how the code works:
enum VarType
{
VT_Bool1,
VT_Bool2,
VT_Bool3,
VT_Bool4,
VT_Float1,
VT_Float2,
VT_Float3,
VT_Float4,
VT_Mat2x2,
VT_Mat3x3,
VT_Mat4x4,
};
// ===========================
template<class T>
class ShaderVar
{
VarType variableType;
T var;
public:
ShaderVar(const T &initValue = T());
~ShaderVar();
// Getters
VarType getVariableType() const;
T &getVariable();
// Setters
Void setVariable(const T &v);
};
What I'm trying to achieve is auto-assignment of the VarType variable when the user instantiates the class with a certain template declaration:
ShaderVar<Matrix3x3> foo;
Internally it would assign the variables the following way:
ShaderVar::var = Matrix3x3()
ShaderVar::variableType= VT_Mat3x3
I believe there is a way of doing this way using templates, I just cant remember the syntax.
EDIT: Alternatively, I can pass in two variables into the template and type def the class into its own type. But I would like to explore the above instance first.
typedef ShaderVar<Matrix3x3, VT_Mat3x3> ShaderMat3x3;