コードに次の行があります。
//lines in mycode.c++
QString str = "...some id...";
if( str == "int")
foo< int>()
else if( str == "QString")
foo< QString>()
...
この条件ステートメントにカスタム型を含めるメカニズムを作成する必要があります。したがって、どのプログラマーも自分のクラスとfooテンプレート関数の実装を登録できます。
私は次のように想像します。
//A.h -- custom class
class A { };
template< >
void foo< A>() { ... };
DECL( A, "A"); //macro to declare class
クラスA の宣言を自動的に考慮する mycode.c++の条件文が必要なので、追加の行があります。
else if( str == "A")
foo< A>()
次のような効果が得られます。
//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);
しかし、プログラマーがcommon.hファイルの編集を忘れたらどうなるでしょうか?
私は、おそらくCマクロシステムを使用するか、何らかの方法でQtプリコンパイルを使用することを考えました。出来ますか?