OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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             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     /* Table Constructor called from the table add function */          \
00086     static void construct##argNames##ConstructorTables();               \
00087                                                                         \
00088     /* Table destructor called from the table add function destructor */\
00089     static void destroy##argNames##ConstructorTables()
00090 
00091 
00092 #define defineRunTimeSelectionTableConstructor(baseType,argNames)       \
00093                                                                         \
00094     /* Table Constructor called from the table add function */          \
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     /* Table destructor called from the table add function destructor */\
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     /* Define the constructor function table */                         \
00123     baseType::argNames##ConstructorTable*                               \
00124         baseType::argNames##ConstructorTablePtr_ = NULL
00125 
00126 #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames)       \
00127                                                                         \
00128     /* Define the constructor function table */                         \
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 } // End namespace Foam
00151 
00152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00153 
00154 #endif
00155 
00156 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd