mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
versatility improvement: #includeIfPresent dictionary directive
- similar to the #include directive, but does not generate an error if the file does not exist. Note: opted for an explicit naming #includeIfPresent rather than #cinclude
This commit is contained in:
@ -58,6 +58,8 @@
|
||||
their keywords. When searching, an exact match has priority over a regular
|
||||
expression match. Multiple regular expressions are matched in reverse
|
||||
order.
|
||||
+ The *new* =#includeIfPresent= directive is similar to the =#include=
|
||||
directive, but does not generate an error if the file does not exist.
|
||||
+ The default =#inputMode= is now '=merge=', which corresponds to the most
|
||||
general usage. The =#inputMode warn= corresponds to the previous default
|
||||
behaviour.
|
||||
|
||||
@ -78,6 +78,7 @@ boundaryField
|
||||
// NB: the inputMode has a global scope
|
||||
#inputMode merge
|
||||
#include "testDict2"
|
||||
#includeIfPresent "SomeUnknownFile"
|
||||
|
||||
foo
|
||||
{
|
||||
|
||||
@ -132,6 +132,7 @@ $(dictionaryEntry)/dictionaryEntryIO.C
|
||||
functionEntries = $(dictionary)/functionEntries
|
||||
$(functionEntries)/functionEntry/functionEntry.C
|
||||
$(functionEntries)/includeEntry/includeEntry.C
|
||||
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
|
||||
$(functionEntries)/inputModeEntry/inputModeEntry.C
|
||||
$(functionEntries)/removeEntry/removeEntry.C
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ namespace functionEntries
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName Foam::functionEntries::includeEntry::includeFileName
|
||||
(
|
||||
@ -112,6 +112,7 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionEntries::includeEntry::execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
|
||||
@ -67,15 +67,19 @@ class includeEntry
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Read the include fileName from Istream, expand and return
|
||||
static fileName includeFileName(Istream&);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
includeEntry(const includeEntry&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const includeEntry&);
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read the include fileName from Istream, expand and return
|
||||
static fileName includeFileName(Istream&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "includeIfPresentEntry.H"
|
||||
#include "dictionary.H"
|
||||
#include "IFstream.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word Foam::functionEntries::includeIfPresentEntry::typeName
|
||||
(
|
||||
Foam::functionEntries::includeIfPresentEntry::typeName_()
|
||||
);
|
||||
|
||||
// Don't lookup the debug switch here as the debug switch dictionary
|
||||
// might include includeIfPresentEntry
|
||||
int Foam::functionEntries::includeIfPresentEntry::debug(0);
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionEntries
|
||||
{
|
||||
addToMemberFunctionSelectionTable
|
||||
(
|
||||
functionEntry,
|
||||
includeIfPresentEntry,
|
||||
execute,
|
||||
dictionaryIstream
|
||||
);
|
||||
|
||||
addToMemberFunctionSelectionTable
|
||||
(
|
||||
functionEntry,
|
||||
includeIfPresentEntry,
|
||||
execute,
|
||||
primitiveEntryIstream
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionEntries::includeIfPresentEntry::execute
|
||||
(
|
||||
dictionary& parentDict,
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
parentDict.read(ifs);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionEntries::includeIfPresentEntry::execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
primitiveEntry& entry,
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
entry.read(parentDict, ifs);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,101 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::functionEntries::includeIfPresentEntry
|
||||
|
||||
Description
|
||||
Specify a file to include if it exists. Expects a single string to follow.
|
||||
|
||||
The @c \#includeIfPresent directive is similar to the @c \#include
|
||||
directive, but does not generate an error if the file does not exist.
|
||||
|
||||
See Also
|
||||
Foam::functionEntries::includeEntry
|
||||
|
||||
SourceFiles
|
||||
includeIfPresentEntry.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef includeIfPresentEntry_H
|
||||
#define includeIfPresentEntry_H
|
||||
|
||||
#include "includeEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionEntries
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class includeIfPresentEntry Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class includeIfPresentEntry
|
||||
:
|
||||
public includeEntry
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
includeIfPresentEntry(const includeIfPresentEntry&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const includeIfPresentEntry&);
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("includeIfPresent");
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Execute the functionEntry in a sub-dict context
|
||||
static bool execute(dictionary& parentDict, Istream&);
|
||||
|
||||
//- Execute the functionEntry in a primitiveEntry context
|
||||
static bool execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
primitiveEntry&,
|
||||
Istream&
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionEntries
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user