FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

PstreamImplI.H

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------*\
00002                 ______                _     ____          __  __
00003                |  ____|             _| |_  / __ \   /\   |  \/  |
00004                | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
00005                |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
00006                | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
00007                |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
00008 
00009                     FreeFOAM: The Cross-Platform CFD Toolkit
00010 
00011   Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
00012                           Gerber van der Graaf <gerber_graaf@users.sf.net>
00013 --------------------------------------------------------------------------------
00014 License
00015     This file is part of FreeFOAM.
00016 
00017     FreeFOAM is free software: you can redistribute it and/or modify it
00018     under the terms of the GNU General Public License as published by the
00019     Free Software Foundation, either version 3 of the License, or (at your
00020     option) any later version.
00021 
00022     FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
00023     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025     for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with FreeFOAM.  If not, see <http://www.gnu.org/licenses/>.
00029 
00030 \*----------------------------------------------------------------------------*/
00031 
00032 #include <OpenFOAM/PstreamImpl.H>
00033 #include <OpenFOAM/debug.H>
00034 #include <OpenFOAM/OSspecific.H>
00035 #include <OpenFOAM/dictionary.H>
00036 #include <OpenFOAM/dlLibraryTable.H>
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace Foam {
00041 
00042 // * * * * * * * * * * * * * Local Helper Functions  * * * * * * * * * * * * //
00043 
00044 // helper function to find the config section name
00045 word PstreamConfigSectionName();
00046 
00047 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * //
00048 
00049 template<class T, class CTable>
00050 autoPtr<T> PstreamImpl::loadPstreamInstance(const word& dictEntry, const word& envName, CTable* ctable)
00051 {
00052     word PstreamClassName;
00053     // check whether the environment variable is set
00054     if(env(envName))
00055     {
00056         PstreamClassName = getEnv(envName);
00057     }
00058     else
00059     {
00060         // otherwise check the global controlDict
00061         word configName = PstreamConfigSectionName();
00062         debug::controlDict().subDict("PstreamImplementation")
00063             .subDict(configName).lookup(dictEntry) >> PstreamClassName;
00064     }
00065 
00066     if(PstreamImpl::debug)
00067     {
00068         Info<< "Trying to instantiate '" << PstreamClassName << "'" << endl;
00069     }
00070 
00071     typename CTable::iterator cstrIter =
00072         ctable->find(PstreamClassName);
00073 
00074     if (cstrIter == ctable->end())
00075     {
00076         FatalErrorIn
00077         (
00078             "PstreamImpl::loadPstreamInstance(const word&, const word&)"
00079         )   << "Unknown type '" << PstreamClassName << "'"
00080             << endl << endl
00081             << "Valid types are :" << endl
00082             << ctable->toc()
00083             << Foam::exit(FatalError);
00084     }
00085 
00086     // instantiate
00087     return cstrIter()();
00088 }
00089 
00090 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00091 
00092 } // End namespace Foam
00093 
00094 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines