OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

includeEntry.C

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-2009 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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "includeEntry.H"
00028 #include "dictionary.H"
00029 #include "IFstream.H"
00030 #include "addToMemberFunctionSelectionTable.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 const Foam::word Foam::functionEntries::includeEntry::typeName
00035 (
00036     Foam::functionEntries::includeEntry::typeName_()
00037 );
00038 
00039 // Don't lookup the debug switch here as the debug switch dictionary
00040 // might include includeEntry
00041 int Foam::functionEntries::includeEntry::debug(0);
00042 
00043 namespace Foam
00044 {
00045 namespace functionEntries
00046 {
00047     addToMemberFunctionSelectionTable
00048     (
00049         functionEntry,
00050         includeEntry,
00051         execute,
00052         dictionaryIstream
00053     );
00054 
00055     addToMemberFunctionSelectionTable
00056     (
00057         functionEntry,
00058         includeEntry,
00059         execute,
00060         primitiveEntryIstream
00061     );
00062 }
00063 }
00064 
00065 // * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * * //
00066 
00067 Foam::fileName Foam::functionEntries::includeEntry::includeFileName
00068 (
00069     Istream& is
00070 )
00071 {
00072     fileName fName(is);
00073     fName.expand();
00074 
00075     // relative name
00076     if (fName.size() && fName[0] != '/')
00077     {
00078         fName = fileName(is.name()).path()/fName;
00079     }
00080 
00081     return fName;
00082 }
00083 
00084 
00085 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00086 
00087 bool Foam::functionEntries::includeEntry::execute
00088 (
00089     dictionary& parentDict,
00090     Istream& is
00091 )
00092 {
00093     IFstream ifs(includeFileName(is));
00094 
00095     if (ifs)
00096     {
00097         parentDict.read(ifs);
00098         return true;
00099     }
00100     else
00101     {
00102         FatalIOErrorIn
00103         (
00104             "functionEntries::includeEntry::includeEntry"
00105             "(dictionary& parentDict, Istream&)",
00106             is
00107         )   << "Cannot open include file " << ifs.name()
00108             << " while reading dictionary " << parentDict.name()
00109             << exit(FatalIOError);
00110 
00111         return false;
00112     }
00113 }
00114 
00115 
00116 bool Foam::functionEntries::includeEntry::execute
00117 (
00118     const dictionary& parentDict,
00119     primitiveEntry& entry,
00120     Istream& is
00121 )
00122 {
00123     IFstream ifs(includeFileName(is));
00124 
00125     if (ifs)
00126     {
00127         entry.read(parentDict, ifs);
00128         return true;
00129     }
00130     else
00131     {
00132         FatalIOErrorIn
00133         (
00134             "functionEntries::includeEntry::includeEntry"
00135             "(dictionary& parentDict, primitiveEntry&, Istream&)",
00136             is
00137         )   << "Cannot open include file " << ifs.name()
00138             << " while reading dictionary " << parentDict.name()
00139             << exit(FatalIOError);
00140 
00141         return false;
00142     }
00143 }
00144 
00145 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd