00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "token.H"
00033
00034 #ifndef runTimeSelectionTables_H
00035 #define runTimeSelectionTables_H
00036
00037 #include "autoPtr.H"
00038 #include "HashTable.H"
00039
00040
00041
00042 namespace Foam
00043 {
00044
00045
00046
00047 #define declareRunTimeSelectionTable(autoPtr,baseType,argNames,argList,parList)\
00048 \
00049 \
00050 typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \
00051 \
00052 \
00053 typedef HashTable<argNames##ConstructorPtr, word, string::hash> \
00054 argNames##ConstructorTable; \
00055 \
00056 \
00057 static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
00058 \
00059 \
00060 template<class baseType##Type> \
00061 class add##argNames##ConstructorToTable \
00062 { \
00063 public: \
00064 \
00065 static autoPtr<baseType> New argList \
00066 { \
00067 return autoPtr<baseType>(new baseType##Type parList); \
00068 } \
00069 \
00070 add##argNames##ConstructorToTable() \
00071 { \
00072 construct##argNames##ConstructorTables(); \
00073 \
00074 argNames##ConstructorTablePtr_ \
00075 ->insert(baseType##Type::typeName, New); \
00076 } \
00077 }; \
00078 \
00079 \
00080 static void construct##argNames##ConstructorTables()
00081
00082
00083 #define defineRunTimeSelectionTableConstructor(baseType,argNames) \
00084 \
00085 \
00086 void baseType::construct##argNames##ConstructorTables() \
00087 { \
00088 static bool constructed = false; \
00089 \
00090 if (!constructed) \
00091 { \
00092 baseType::argNames##ConstructorTablePtr_ \
00093 = new baseType::argNames##ConstructorTable; \
00094 \
00095 constructed = true; \
00096 } \
00097 }
00098
00099 #define defineRunTimeSelectionTablePtr(baseType,argNames) \
00100 \
00101 \
00102 baseType::argNames##ConstructorTable* \
00103 baseType::argNames##ConstructorTablePtr_ = NULL
00104
00105 #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \
00106 \
00107 \
00108 typename baseType::argNames##ConstructorTable* \
00109 baseType::argNames##ConstructorTablePtr_ = NULL
00110
00111 #define defineRunTimeSelectionTable(baseType,argNames) \
00112 \
00113 defineRunTimeSelectionTablePtr(baseType,argNames); \
00114 defineRunTimeSelectionTableConstructor(baseType,argNames)
00115
00116 #define defineTemplateRunTimeSelectionTable(baseType,argNames) \
00117 \
00118 template<> \
00119 defineRunTimeSelectionTablePtr(baseType,argNames); \
00120 template<> \
00121 defineRunTimeSelectionTableConstructor(baseType,argNames)
00122
00123
00124
00125
00126 }
00127
00128
00129
00130 #endif
00131
00132