I have these lines in my code:
//lines in mycode.c++
QString str = "...some id...";
if( str == "int")
foo< int>()
else if( str == "QString")
foo< QString>()
...
I need to create a mechanism to include custom types in this conditional statement. So, any programmer can register his class and his implementation of foo templated function.
I imagine it like this:
//A.h -- custom class
class A { };
template< >
void foo< A>() { ... };
DECL( A, "A"); //macro to declare class
I want conditional statement in mycode.c++ that would automatically take in account declaration of class A, so it will have additional lines:
else if( str == "A")
foo< A>()
I could have this effect like this:
//common.h
void process_id( QString str) {
if( str == "int")
foo< int>()
else if( str == "QString")
foo< QString>()
...
else if( str == "A") //this lines programmer put manually
foo< A>();
}
//mycode.c++
#include "common.h"
QString str = "some_id";
process_id( str);
but what if programmer forgets to edit common.h file?
I thought, maybe to use C-macros system, or somehow Qt-precompilation. Is it possible?