Commit 0a6ca7ae authored by Henry's avatar Henry
Browse files

includeEtcEntry: New dictionary include directive: #includeEtc "etcFile"

Description
    Specify an etc file to include when reading dictionaries, expects a
    single string to follow.

    Searches for files from user/group/shipped directories.
    The search scheme allows for version-specific and
    version-independent files using the following hierarchy:
    - \b user settings:
      - ~/.OpenFOAM/\<VERSION\>
      - ~/.OpenFOAM/
    - \b group (site) settings (when $WM_PROJECT_SITE is set):
      - $WM_PROJECT_SITE/\<VERSION\>
      - $WM_PROJECT_SITE
    - \b group (site) settings (when $WM_PROJECT_SITE is not set):
      - $WM_PROJECT_INST_DIR/site/\<VERSION\>
      - $WM_PROJECT_INST_DIR/site/
    - \b other (shipped) settings:
      - $WM_PROJECT_DIR/etc/

    An example of the \c \#includeEtc directive:
    \verbatim
        #includeEtc "etcFile"
    \endverbatim

    The usual expansion of environment variables and other constructs is
    retained.
parent db524d94
......@@ -174,6 +174,7 @@ $(functionEntries)/calcEntry/calcEntry.C
$(functionEntries)/codeStream/codeStream.C
$(functionEntries)/functionEntry/functionEntry.C
$(functionEntries)/includeEntry/includeEntry.C
$(functionEntries)/includeEtcEntry/includeEtcEntry.C
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/removeEntry/removeEntry.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "includeEtcEntry.H"
#include "dictionary.H"
#include "IFstream.H"
#include "addToMemberFunctionSelectionTable.H"
#include "stringOps.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::includeEtcEntry::typeName
(
Foam::functionEntries::includeEtcEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include includeEtcEntry
int Foam::functionEntries::includeEtcEntry::debug(0);
bool Foam::functionEntries::includeEtcEntry::report(false);
namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
(
functionEntry,
includeEtcEntry,
execute,
dictionaryIstream
);
addToMemberFunctionSelectionTable
(
functionEntry,
includeEtcEntry,
execute,
primitiveEntryIstream
);
}
}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeEtcEntry::includeEtcFileName
(
const fileName& f,
const dictionary& dict
)
{
fileName fName(f);
// Substitute dictionary and environment variables.
// Allow empty substitutions.
stringOps::inplaceExpand(fName, dict, true, true);
if (fName.empty() || fName.isAbsolute())
{
return fName;
}
else
{
// Search the etc directories for the file
return findEtcFile(fName);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::includeEtcEntry::execute
(
dictionary& parentDict,
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeEtcFileName(rawFName, parentDict)
);
IFstream ifs(fName);
if (ifs)
{
if (Foam::functionEntries::includeEtcEntry::report)
{
Info<< fName << endl;
}
parentDict.read(ifs);
return true;
}
else
{
FatalIOErrorIn
(
"functionEntries::includeEtcEntry::includeEtcEntry"
"(dictionary& parentDict, Istream&)",
is
) << "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
return false;
}
}
bool Foam::functionEntries::includeEtcEntry::execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeEtcFileName(rawFName, parentDict)
);
IFstream ifs(fName);
if (ifs)
{
if (Foam::functionEntries::includeEtcEntry::report)
{
Info<< fName << endl;
}
entry.read(parentDict, ifs);
return true;
}
else
{
FatalIOErrorIn
(
"functionEntries::includeEtcEntry::includeEtcEntry"
"(dictionary& parentDict, primitiveEntry&, Istream&)",
is
) << "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
return false;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::functionEntries::includeEtcEntry
Description
Specify an etc file to include when reading dictionaries, expects a
single string to follow.
Searches for files from user/group/shipped directories.
The search scheme allows for version-specific and
version-independent files using the following hierarchy:
- \b user settings:
- ~/.OpenFOAM/\<VERSION\>
- ~/.OpenFOAM/
- \b group (site) settings (when $WM_PROJECT_SITE is set):
- $WM_PROJECT_SITE/\<VERSION\>
- $WM_PROJECT_SITE
- \b group (site) settings (when $WM_PROJECT_SITE is not set):
- $WM_PROJECT_INST_DIR/site/\<VERSION\>
- $WM_PROJECT_INST_DIR/site/
- \b other (shipped) settings:
- $WM_PROJECT_DIR/etc/
An example of the \c \#includeEtc directive:
\verbatim
#includeEtc "etcFile"
\endverbatim
The usual expansion of environment variables and other constructs is
retained.
See Also
findEtcFile, fileName, string::expand()
SourceFiles
includeEtcEntry.C
\*---------------------------------------------------------------------------*/
#ifndef includeEtcEntry_H
#define includeEtcEntry_H
#include "functionEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class includeEtcEntry Declaration
\*---------------------------------------------------------------------------*/
class includeEtcEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
includeEtcEntry(const includeEtcEntry&);
//- Disallow default bitwise assignment
void operator=(const includeEtcEntry&);
//- Expand include fileName and return
static fileName includeEtcFileName
(
const fileName&,
const dictionary&
);
public:
// Static data members
//- Report which file is included to stdout
static bool report;
//- Runtime type information
ClassName("includeEtc");
// 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
// ************************************************************************* //
......@@ -38,7 +38,7 @@ boundaryField
staticWalls { $:wall.T; }
movingWalls { $staticWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -39,7 +39,7 @@ boundaryField
staticWalls { $:wall.U; }
movingWalls { $:movingWall.U; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -28,7 +28,7 @@ boundaryField
movingWalls { $:wall.alphat; }
staticWalls { $movingWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
......
......@@ -39,7 +39,7 @@ boundaryField
staticWalls { $:wall.epsilon; }
movingWalls { $staticWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -39,7 +39,7 @@ boundaryField
staticWalls { $:wall.k; }
movingWalls { $staticWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -28,7 +28,7 @@ boundaryField
movingWalls { $:wall.nut; }
staticWalls { $movingWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -28,7 +28,7 @@ boundaryField
staticWalls { $:wall.p; }
movingWalls { $staticWalls; }
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
}
// ************************************************************************* //
......@@ -21,7 +21,7 @@ internalField uniform 265;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -21,7 +21,7 @@ internalField uniform (0 0 0);
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -22,7 +22,7 @@ internalField uniform 0;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -22,7 +22,7 @@ internalField uniform 0.01;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -22,7 +22,7 @@ internalField uniform 0.1;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -22,7 +22,7 @@ internalField uniform 0;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -21,7 +21,7 @@ internalField uniform 0;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -21,7 +21,7 @@ internalField uniform 0;
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
wall
{
......
......@@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Include defaults parameters from master dictionary
#include "$WM_PROJECT_DIR/etc/caseDicts/meshQualityDict"
#includeEtc "caseDicts/meshQualityDict"
// ************************************************************************* //
......@@ -22,7 +22,7 @@ internalField uniform (0.1 0 0);
boundaryField
{
//- Set patchGroups for constraint patches
#include "${WM_PROJECT_DIR}/etc/caseDicts/setConstraintTypes"
#includeEtc "caseDicts/setConstraintTypes"
floor
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment