FreeFOAM The Cross-Platform CFD Toolkit
PstreamImplI.H
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*\
2  ______ _ ____ __ __
3  | ____| _| |_ / __ \ /\ | \/ |
4  | |__ _ __ ___ ___ / \| | | | / \ | \ / |
5  | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
6  | | | | | __/ __/\_ _/| |__| / ____ \| | | |
7  |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
8 
9  FreeFOAM: The Cross-Platform CFD Toolkit
10 
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.
16 
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.
21 
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.
26 
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/>.
29 
30 \*----------------------------------------------------------------------------*/
31 
32 #include <OpenFOAM/PstreamImpl.H>
33 #include <OpenFOAM/debug.H>
34 #include <OpenFOAM/OSspecific.H>
35 #include <OpenFOAM/dictionary.H>
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam {
41 
42 // * * * * * * * * * * * * * Local Helper Functions * * * * * * * * * * * * //
43 
44 // helper function to find the config section name
46 
47 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * //
48 
49 template<class T, class CTable>
50 autoPtr<T> PstreamImpl::loadPstreamInstance(const word& dictEntry, const word& envName, CTable* ctable)
51 {
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  }
65 
66  if(PstreamImpl::debug)
67  {
68  Info<< "Trying to instantiate '" << PstreamClassName << "'" << endl;
69  }
70 
71  typename CTable::iterator cstrIter =
72  ctable->find(PstreamClassName);
73 
74  if (cstrIter == ctable->end())
75  {
77  (
78  "PstreamImpl::loadPstreamInstance(const word&, const word&)"
79  ) << "Unknown type '" << PstreamClassName << "'"
80  << endl << endl
81  << "Valid types are :" << endl
82  << ctable->toc()
84  }
85 
86  // instantiate
87  return cstrIter()();
88 }
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 } // End namespace Foam
93 
94 // ************************ vim: set sw=4 sts=4 et: ************************ //