diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 5fd1c07e862c72bd9480427a2a5ac6c29dc39df6..92cd475adb69b6f23c18cdd21769e2742d9c8ce7 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -14,8 +14,8 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#includeIfPresent "someUnknownFile" -#includeIfPresent "$FOAM_CASE/someUnknownFile" +#sinclude "someUnknownFile" +#sinclude "$FOAM_CASE/someUnknownFile" #includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME" internalField uniform 1; diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index 88a4df557c349c290b8d8ca1d77e56492b85f54d..c8d972fd512c7437ee8ce71940329e8c56d26c3f 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -59,7 +59,7 @@ Usage the resulting dictionary to standard output. - \par -includes - List the \c \#include and \c \#includeIfPresent files to standard output + List the \c \#include and \c \#sinclude files to standard output - \par -disableFunctionEntries Do not expand macros or directives (\#include etc) @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) argList::addBoolOption ( "includes", - "List the #include/#includeIfPresent files to standard output" + "List the #include/#sinclude files to standard output" ); argList::addBoolOption ( diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 96fc8ca422b658741a62c9d67b4e91a3a004944f..fe8b3afb9480240a591d5b4080aa10f2c016ff49 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -231,7 +231,6 @@ $(functionEntries)/functionEntry/functionEntry.C $(functionEntries)/includeEntry/includeEntry.C $(functionEntries)/includeEtcEntry/includeEtcEntry.C $(functionEntries)/includeFuncEntry/includeFuncEntry.C -$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C $(functionEntries)/inputMode/inputMode.C $(functionEntries)/removeEntry/removeEntry.C diff --git a/src/OpenFOAM/db/dictionary/functionEntries/README b/src/OpenFOAM/db/dictionary/functionEntries/README index b16070ab982edb3b5a1dc561ef13c227d1697476..73d6e163de742be0bad577893ab2921ca546ea1a 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/README +++ b/src/OpenFOAM/db/dictionary/functionEntries/README @@ -10,8 +10,9 @@ #remove | dict | keyType or List<keyType> | | #include | dict/primitive | string - #includeEtc | dict/primitive | string + #sinclude | dict/primitive | string #includeIfPresent | dict/primitive | string + #includeEtc | dict/primitive | string #includeFunc | dict | word | | #calc | dict/primitive | string @@ -27,4 +28,4 @@ Pending future extensions #undef | dict | keyType or List<keyType> -2017-11-26 +2018-05-28 diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index 90fe356885c8486ea37d9277f294bd873a8046cc..e39e9a657ae9ae01be90ea435cf9915059acaa94 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,9 +57,47 @@ namespace functionEntries primitiveEntryIstream, include ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + sincludeEntry, + execute, + dictionaryIstream, + sinclude + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + sincludeEntry, + execute, + primitiveEntryIstream, + sinclude + ); + + // Compat 1712 and earlier + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + sincludeEntry, + execute, + dictionaryIstream, + includeIfPresent + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + sincludeEntry, + execute, + primitiveEntryIstream, + includeIfPresent + ); } } + // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // Foam::fileName Foam::functionEntries::includeEntry::resolveFile @@ -97,7 +135,7 @@ bool Foam::functionEntries::includeEntry::execute const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); + auto& ifs = *ifsPtr; if (ifs) { @@ -144,7 +182,7 @@ bool Foam::functionEntries::includeEntry::execute const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); + auto& ifs = *ifsPtr; if (ifs) { @@ -180,4 +218,79 @@ bool Foam::functionEntries::includeEntry::execute } +bool Foam::functionEntries::sincludeEntry::execute +( + dictionary& parentDict, + Istream& is +) +{ + const fileName rawName(is); + const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); + + autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); + auto& ifs = *ifsPtr; + + if (ifs) + { + if (Foam::functionEntries::includeEntry::log) + { + Info<< fName << endl; + } + + // Add watch on included file + const dictionary& top = parentDict.topDict(); + if (isA<regIOobject>(top)) + { + regIOobject& rio = const_cast<regIOobject&> + ( + dynamic_cast<const regIOobject&>(top) + ); + rio.addWatch(fName); + } + + parentDict.read(ifs); + } + + return true; // Never fails +} + + +bool Foam::functionEntries::sincludeEntry::execute +( + const dictionary& parentDict, + primitiveEntry& entry, + Istream& is +) +{ + const fileName rawName(is); + const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); + + autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); + auto& ifs = *ifsPtr; + + if (ifs) + { + if (Foam::functionEntries::includeEntry::log) + { + Info<< fName << endl; + } + + // Add watch on included file + const dictionary& top = parentDict.topDict(); + if (isA<regIOobject>(top)) + { + regIOobject& rio = const_cast<regIOobject&> + ( + dynamic_cast<const regIOobject&>(top) + ); + rio.addWatch(fName); + } + + entry.read(parentDict, ifs); + } + + return true; // Never fails +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H index a2e7f5c90914f547e802efe8ae9b1823daa194ff..cda8acb28a6b3770d8701889dcc7fe0003d1f0c2 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,19 +25,25 @@ Class Foam::functionEntries::includeEntry Description - Specify an include file when reading dictionaries, expects a - single string to follow. + A dictionary directive for including a file, expects a single string + to follow. - An example of the \c \#include directive: + An example of the \c \#include directive to include a file: \verbatim - #include "includeFile" + #include "includeFileMustExist" \endverbatim - The usual expansion of environment variables and other constructs - (eg, the \c ~OpenFOAM/ expansion) is retained. + An example of the \c \#sinclude directive to conditionally include a file + when it exists. + \verbatim + #sinclude "includeFileCanBeMissing" + \endverbatim + + The usual expansion of environment variables and other expansions + (eg, a leading "<case>/", "<system>/", "<etc>/", ...) are retained. See also - fileName, string::expand() + fileName, string::expand(), functionEntries::sincludeEntry SourceFiles includeEntry.C @@ -97,7 +103,35 @@ public: primitiveEntry& entry, Istream& is ); +}; + + +/*---------------------------------------------------------------------------*\ + Class sincludeEntry Declaration +\*---------------------------------------------------------------------------*/ + +//- A dictionary directive for conditionally including a file, +//- expects a single string to follow. +// +// The \c \#sinclude directive (and the \c \#includeIfPresent alias) behaves +// identically to the \c \#include directive, but does not generate an error +// if the file does not exist. +class sincludeEntry +: + public includeEntry +{ +public: + + //- Include file (if it exists) in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); + //- Include file (if it exists) in a primitiveEntry context + static bool execute + ( + const dictionary& parentDict, + primitiveEntry& entry, + Istream& is + ); }; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C index 8fd559b7d69fe066acd4236e42936d55a89b03d0..da008f6842c56210cada6d9d492e46535fa716ba 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C @@ -96,7 +96,7 @@ bool Foam::functionEntries::includeEtcEntry::execute const fileName fName(resolveEtcFile(rawName, parentDict)); autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); + auto& ifs = *ifsPtr; if (ifs) { @@ -131,7 +131,7 @@ bool Foam::functionEntries::includeEtcEntry::execute const fileName fName(resolveEtcFile(rawName, parentDict)); autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); + auto& ifs = *ifsPtr; if (ifs) { diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.H index 9d6ccae4091b308ada100de03f28f20d8d261ebc..28564375b2cd18979e977f88a7d7b18e5b7a4275 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.H @@ -25,6 +25,9 @@ Class Foam::functionEntries::includeEtcEntry Description + A dictionary directive for including a file found using the findEtcFile() + mechanism. + Specify an etc file to include when reading dictionaries, expects a single string to follow. diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C deleted file mode 100644 index a110e55cd974e7e9eaf215680c69f7fd6b5d235a..0000000000000000000000000000000000000000 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C +++ /dev/null @@ -1,136 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 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 "includeIfPresentEntry.H" -#include "dictionary.H" -#include "IFstream.H" -#include "regIOobject.H" -#include "addToMemberFunctionSelectionTable.H" -#include "fileOperation.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ -namespace functionEntries -{ - addNamedToMemberFunctionSelectionTable - ( - functionEntry, - includeIfPresentEntry, - execute, - dictionaryIstream, - includeIfPresent - ); - - addNamedToMemberFunctionSelectionTable - ( - functionEntry, - includeIfPresentEntry, - execute, - primitiveEntryIstream, - includeIfPresent - ); -} -} - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::functionEntries::includeIfPresentEntry::execute -( - dictionary& parentDict, - Istream& is -) -{ - const fileName rawName(is); - const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); - - autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); - - if (ifs) - { - if (Foam::functionEntries::includeEntry::log) - { - Info<< fName << endl; - } - - // Add watch on included file - const dictionary& top = parentDict.topDict(); - if (isA<regIOobject>(top)) - { - regIOobject& rio = const_cast<regIOobject&> - ( - dynamic_cast<const regIOobject&>(top) - ); - rio.addWatch(fName); - } - - parentDict.read(ifs); - } - - return true; -} - - -bool Foam::functionEntries::includeIfPresentEntry::execute -( - const dictionary& parentDict, - primitiveEntry& entry, - Istream& is -) -{ - const fileName rawName(is); - const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); - - autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName)); - ISstream& ifs = ifsPtr(); - - if (ifs) - { - if (Foam::functionEntries::includeEntry::log) - { - Info<< fName << endl; - } - - // Add watch on included file - const dictionary& top = parentDict.topDict(); - if (isA<regIOobject>(top)) - { - regIOobject& rio = const_cast<regIOobject&> - ( - dynamic_cast<const regIOobject&>(top) - ); - rio.addWatch(fName); - } - - entry.read(parentDict, ifs); - } - - return true; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.H deleted file mode 100644 index a6d581e6089661a391afd05f043ad20d9a2ba5e0..0000000000000000000000000000000000000000 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.H +++ /dev/null @@ -1,86 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 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::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 -{ -public: - - //- Include (if present) in a sub-dict context - static bool execute(dictionary& parentDict, Istream& is); - - //- Include (if present) in a primitiveEntry context - static bool execute - ( - const dictionary& parentDict, - primitiveEntry& entry, - Istream& is - ); - -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace functionEntries -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.C b/src/OpenFOAM/global/etcFiles/etcFiles.C index 5271b4de48b31292dbafef2144a3c71212ccd5c1..448bf64f27b3aa0275fcbc632b15bd7b41343bb4 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.C +++ b/src/OpenFOAM/global/etcFiles/etcFiles.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,8 +32,10 @@ License // // These could be exposed too (if required), but are fairly special purpose. // -//! \cond fileScope -// + +namespace +{ + // Assign 'queried' parameter to the user resource directory. // Return true if this directory exists. // @@ -62,9 +64,15 @@ static inline bool groupResourceDir(Foam::fileName& queried) return Foam::isDir(queried); } - // Fallback (when WM_PROJECT_SITE is unset) + // When WM_PROJECT_SITE is unset: queried = Foam::getEnv("WM_PROJECT_INST_DIR")/"site"; - return (queried.size() > 5 && Foam::isDir(queried)); + return (queried.size() > 4 && Foam::isDir(queried)); + + // NOTE: this alternative bit of code corresponds to how we patch things + // for spack (and EasyBuild?) to avoid leaking out to the parent directory + // + // queried = Foam::getEnv("WM_PROJECT_DIR")/"site"; + // return (queried.size() > 4 && Foam::isDir(queried)); } @@ -77,170 +85,124 @@ static inline bool groupResourceDir(Foam::fileName& queried) static inline bool projectResourceDir(Foam::fileName& queried) { queried = Foam::getEnv("WM_PROJECT_DIR")/"etc"; - return (queried.size() > 4 && Foam::isDir(queried)); + return (queried.size() > 3 && Foam::isDir(queried)); } -//! \endcond - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -Foam::fileNameList Foam::findEtcDirs +Foam::fileNameList searchEtc ( - const fileName& name, - const bool findFirst + const Foam::fileName& name, + const bool findFirst, + bool (*accept)(const Foam::fileName&) ) { - fileNameList results; + Foam::fileNameList list; + Foam::fileName dir, candidate; - do + // User resource directories + if (userResourceDir(dir)) { - fileName dir, candidate; - - // User resource directories - if (userResourceDir(dir)) + candidate = dir/Foam::FOAMversion/name; + if (accept(candidate)) { - candidate = dir/FOAMversion/name; - if (isDir(candidate)) + list.append(std::move(candidate)); + if (findFirst) { - results.append(candidate); - if (findFirst) - { - break; - } + return list; } + } - candidate = dir/name; - if (isDir(candidate)) + candidate = dir/name; + if (accept(candidate)) + { + list.append(std::move(candidate)); + if (findFirst) { - results.append(candidate); - if (findFirst) - { - break; - } + return list; } } + } - // Group resource directories - if (groupResourceDir(dir)) + // Group resource directories + if (groupResourceDir(dir)) + { + candidate = dir/Foam::FOAMversion/name; + if (accept(candidate)) { - candidate = dir/FOAMversion/name; - if (isDir(candidate)) + list.append(std::move(candidate)); + if (findFirst) { - results.append(candidate); - if (findFirst) - { - break; - } + return list; } + } - candidate = dir/name; - if (isDir(candidate)) + candidate = dir/name; + if (accept(candidate)) + { + list.append(std::move(candidate)); + if (findFirst) { - results.append(candidate); - if (findFirst) - { - break; - } + return list; } } + } - // Other (project) resource directory - if (projectResourceDir(dir)) + // Other (project) resource directory + if (projectResourceDir(dir)) + { + candidate = dir/name; + if (accept(candidate)) { - candidate = dir/name; - if (isDir(dir) && isDir(candidate)) - { - results.append(candidate); - } + list.append(std::move(candidate)); } } - while (false); // Run exactly once - return results; + return list; } +} // End anonymous namespace -Foam::fileNameList Foam::findEtcFiles + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +Foam::fileNameList Foam::findEtcDirs ( const fileName& name, - const bool mandatory, const bool findFirst ) { - fileNameList results; - - do - { - fileName dir, candidate; - - // User resource directories - if (userResourceDir(dir)) - { - candidate = dir/FOAMversion/name; - if (isFile(candidate)) - { - results.append(candidate); - if (findFirst) - { - break; - } - } - - candidate = dir/name; - if (isFile(candidate)) - { - results.append(candidate); - if (findFirst) - { - break; - } - } - } - - // Group resource directories - if (groupResourceDir(dir)) - { - candidate = dir/FOAMversion/name; - if (isFile(candidate)) - { - results.append(candidate); - if (findFirst) - { - break; - } - } + return + searchEtc + ( + name, + findFirst, + [](const fileName& f){ return isDir(f); } + ); +} - candidate = dir/name; - if (isFile(candidate)) - { - results.append(candidate); - if (findFirst) - { - break; - } - } - } - // Other (project) resource directory - if (projectResourceDir(dir)) - { - candidate = dir/name; - if (isDir(dir) && isFile(candidate)) - { - results.append(candidate); - } - } - } - while (false); // Run exactly once +Foam::fileNameList Foam::findEtcFiles +( + const fileName& name, + const bool mandatory, + const bool findFirst +) +{ + fileNameList list; - // No name? It cannot be a file! - if (name.empty()) + if (name.size()) { - results.clear(); + // A file must have a name! + list = searchEtc + ( + name, + findFirst, + [](const fileName& f){ return isFile(f); } + ); } - if (mandatory && results.empty()) + if (mandatory && list.empty()) { // Abort if file is mandatory but not found std::cerr @@ -250,21 +212,21 @@ Foam::fileNameList Foam::findEtcFiles ::exit(1); } - return results; + return list; } Foam::fileName Foam::findEtcFile(const fileName& name, const bool mandatory) { - fileNameList results(findEtcFiles(name, mandatory, true)); + fileName file; - if (results.size()) + fileNameList list(findEtcFiles(name, mandatory, true)); + if (list.size()) { - return results[0]; + file = std::move(list.first()); } - // Return null-constructed fileName rather than fileName::null - return fileName(); + return file; } diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.H b/src/OpenFOAM/global/etcFiles/etcFiles.H index 5e3532148c8fe468f1a940f92a10c1c391cf64ce..7c190fb1a8417825433931878318522bea3b0f10 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.H +++ b/src/OpenFOAM/global/etcFiles/etcFiles.H @@ -45,19 +45,8 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- Search for directories from user/group/other 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 (project) settings: -// - $WM_PROJECT_DIR/etc/ +// +// \note Uses search hierarchy as per findEtcFiles(). // // \return The list of full paths of all the matching directories or // an empty list if the name cannot be found. @@ -68,19 +57,22 @@ fileNameList findEtcDirs const bool findFirst = false ); + //- Search for files from user/group/other directories. -// The search scheme allows for version-specific and -// version-independent files using the following hierarchy: +// +// \note +// The following search hierarchy is also used by the foamEtcFile shell +// script, which allows for version-specific and version-independent files: // - \b user settings: // - ~/.OpenFOAM/\<VERSION\> // - ~/.OpenFOAM/ -// - \b group (site) settings (when $WM_PROJECT_SITE is set): +// - \b group 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): +// - \b group settings (when $WM_PROJECT_SITE is not set): // - $WM_PROJECT_INST_DIR/site/\<VERSION\> // - $WM_PROJECT_INST_DIR/site/ -// - \b other (project) settings: +// - \b other (shipped) settings: // - $WM_PROJECT_DIR/etc/ // // \return The list of full paths of all the matching files or @@ -94,7 +86,9 @@ fileNameList findEtcFiles const bool findFirst = false ); -//- Search for a single file using findEtcFiles. + +//- Search for a single file using findEtcFiles(). +// // \return The full path name of the first file found in the // search hierarchy or an empty fileName if the name cannot be found. // Optionally abort if the file cannot be found but is mandatory. diff --git a/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/system/controlDict b/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/system/controlDict index 06168ee7c29ae6a1146a11b0ece5739a1055f1fa..974e73771c8199a2dc992257920b6df13eba1fe8 100644 --- a/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/system/controlDict +++ b/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/system/controlDict @@ -52,6 +52,6 @@ maxAlphaCo 1; maxDeltaT 1; -#includeIfPresent "sampling" +#sinclude "sampling" // ************************************************************************* //