In the past couple of days I've been making a little system which I'm going to use in my latest engine to monitor some variables and their values (a bit like the Autos window in MSVC).
Anyways, I stumbled upon some minor problems here. First off, I'd like to have a class accepting any possible variable type in the project and I found the use of templates extremely useful here.
However, the problem is that I want to print the contents of a specific variable to the screen and that would require me to get the contents of the variable on char* form. This means I'll have to implement some way to convert the data type to a char*.
Since I want this system to be as dynamic and abstract as possible I don't like the idea of just hardcoding the handling of all possible types into the core of the system.
Instead it would be neat if I could e.g have a base class (or similar) which can hold some basic properties, like the name of the variable etc.
As I said before, since I want the system to be able to handle all possible types (including custom types), I need to implement some way where one can easily add some code to do the conversion from the data type to a char*.
So far I've been using RTTI to check the data type and then done a simple if.. else if statement to convert to a char*, like this:
Since doing string comparison is pretty slow I'd rather avoid this and come up with a better way to implement the conversion to char*.Code:if (GetVarType() == "int") sprintf(szBuffer, "%d", GetVarValue()); ...
I've been thinking about using inheritance so the user could just add a new class whose only purpose would be to store the pointer to the variable in question AND do the conversion to a char* through some virtual function declared in a base class. I just have a hard time seeing how this could be done in practice, though.
As you can see I've been thinking quite a bit about this and my ideas might not be the brightest, but I'm hoping some of you have some ideas which I can, hopefully, adapt
Huge thanks in advance