ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / src / OpenFOAM / db / IOstreams / Pstreams / PstreamImplI.H
blob2e6830faf93a38324de46b760ebaf4dae6c9f6ec
1 /*----------------------------------------------------------------------------*\
2                 ______                _     ____          __  __
3                |  ____|             _| |_  / __ \   /\   |  \/  |
4                | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
5                |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
6                | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
7                |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
9                     FreeFOAM: The Cross-Platform CFD Toolkit
11   Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
12                           Gerber van der Graaf <gerber_graaf@users.sf.net>
13 --------------------------------------------------------------------------------
14 License
15     This file is part of FreeFOAM.
17     FreeFOAM is free software: you can redistribute it and/or modify it
18     under the terms of the GNU General Public License as published by the
19     Free Software Foundation, either version 3 of the License, or (at your
20     option) any later version.
22     FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25     for more details.
27     You should have received a copy of the GNU General Public License
28     along with FreeFOAM.  If not, see <http://www.gnu.org/licenses/>.
30 \*----------------------------------------------------------------------------*/
32 #include <OpenFOAM/PstreamImpl.H>
33 #include <OpenFOAM/debug.H>
34 #include <OpenFOAM/OSspecific.H>
35 #include <OpenFOAM/dictionary.H>
36 #include <OpenFOAM/dlLibraryTable.H>
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam {
42 // * * * * * * * * * * * * * Local Helper Functions  * * * * * * * * * * * * //
44 // helper function to find the config section name
45 word PstreamConfigSectionName();
47 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * //
49 template<class T, class CTable>
50 autoPtr<T> PstreamImpl::loadPstreamInstance(const word& dictEntry, const word& envName, CTable* ctable)
52     word PstreamClassName;
53     // check whether the environment variable is set
54     if(env(envName))
55     {
56         PstreamClassName = getEnv(envName);
57     }
58     else
59     {
60         // otherwise check the global controlDict
61         word configName = PstreamConfigSectionName();
62         debug::controlDict().subDict("PstreamImplementation")
63             .subDict(configName).lookup(dictEntry) >> PstreamClassName;
64     }
66     if(PstreamImpl::debug)
67     {
68         Info<< "Trying to instantiate '" << PstreamClassName << "'" << endl;
69     }
71     typename CTable::iterator cstrIter =
72         ctable->find(PstreamClassName);
74     if (cstrIter == ctable->end())
75     {
76         FatalErrorIn
77         (
78             "PstreamImpl::loadPstreamInstance(const word&, const word&)"
79         )   << "Unknown type '" << PstreamClassName << "'"
80             << endl << endl
81             << "Valid types are :" << endl
82             << ctable->toc()
83             << Foam::exit(FatalError);
84     }
86     // instantiate
87     return cstrIter()();
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 } // End namespace Foam
94 // ************************ vim: set sw=4 sts=4 et: ************************ //