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 const word& lookup = baseType##Type::typeName \
00073 ) \
00074 { \
00075 construct##argNames##ConstructorTables(); \
00076 argNames##ConstructorTablePtr_->insert(lookup, New); \
00077 } \
00078 \
00079 ~add##argNames##ConstructorToTable() \
00080 { \
00081 destroy##argNames##ConstructorTables(); \
00082 } \
00083 }; \
00084 \
00085 \
00086 static void construct##argNames##ConstructorTables(); \
00087 \
00088 \
00089 static void destroy##argNames##ConstructorTables()
00090
00091
00092 #define defineRunTimeSelectionTableConstructor(baseType,argNames) \
00093 \
00094 \
00095 void baseType::construct##argNames##ConstructorTables() \
00096 { \
00097 static bool constructed = false; \
00098 \
00099 if (!constructed) \
00100 { \
00101 baseType::argNames##ConstructorTablePtr_ \
00102 = new baseType::argNames##ConstructorTable; \
00103 \
00104 constructed = true; \
00105 } \
00106 }
00107
00108 #define defineRunTimeSelectionTableDestructor(baseType,argNames) \
00109 \
00110 \
00111 void baseType::destroy##argNames##ConstructorTables() \
00112 { \
00113 if (baseType::argNames##ConstructorTablePtr_) \
00114 { \
00115 delete baseType::argNames##ConstructorTablePtr_; \
00116 baseType::argNames##ConstructorTablePtr_ = NULL; \
00117 } \
00118 }
00119
00120 #define defineRunTimeSelectionTablePtr(baseType,argNames) \
00121 \
00122 \
00123 baseType::argNames##ConstructorTable* \
00124 baseType::argNames##ConstructorTablePtr_ = NULL
00125
00126 #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \
00127 \
00128 \
00129 typename baseType::argNames##ConstructorTable* \
00130 baseType::argNames##ConstructorTablePtr_ = NULL
00131
00132 #define defineRunTimeSelectionTable(baseType,argNames) \
00133 \
00134 defineRunTimeSelectionTablePtr(baseType,argNames); \
00135 defineRunTimeSelectionTableConstructor(baseType,argNames) \
00136 defineRunTimeSelectionTableDestructor(baseType,argNames)
00137
00138 #define defineTemplateRunTimeSelectionTable(baseType,argNames) \
00139 \
00140 template<> \
00141 defineRunTimeSelectionTablePtr(baseType,argNames); \
00142 template<> \
00143 defineRunTimeSelectionTableConstructor(baseType,argNames) \
00144 template<> \
00145 defineRunTimeSelectionTableDestructor(baseType,argNames)
00146
00147
00148
00149
00150 }
00151
00152
00153
00154 #endif
00155
00156
Copyright © 2000-2007 OpenCFD Ltd