OpenFOAM logo
Open Source CFD Toolkit

runTimeSelectionTables.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     runTimeSelectionTables
00027 
00028 Description
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     /* Construct from argList function pointer type */                  \
00050     typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList;       \
00051                                                                         \
00052     /* Construct from argList function table type */                    \
00053         typedef HashTable<argNames##ConstructorPtr, word, string::hash> \
00054         argNames##ConstructorTable;                                     \
00055                                                                         \
00056     /* Construct from argList function pointer table pointer */         \
00057     static argNames##ConstructorTable* argNames##ConstructorTablePtr_;  \
00058                                                                         \
00059     /* Class to add constructor from argList to table */                \
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     /* Table Constructor called from the table add function */          \
00080     static void construct##argNames##ConstructorTables()
00081 
00082 
00083 #define defineRunTimeSelectionTableConstructor(baseType,argNames)       \
00084                                                                         \
00085     /* Table Constructor called from the table add function */          \
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     /* Define the constructor function table */                         \
00102     baseType::argNames##ConstructorTable*                               \
00103         baseType::argNames##ConstructorTablePtr_ = NULL
00104 
00105 #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames)       \
00106                                                                         \
00107     /* Define the constructor function table */                         \
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 } // End namespace Foam
00127 
00128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00129 
00130 #endif
00131 
00132 // ************************************************************************* //
For further information go to www.openfoam.org