Download data/src/OpenFOAM/db/dictionary/dictionaryTemplates.C from introvoyz042/OpenFOAM-dev: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/datasets/introvoyz042/OpenFOAM-dev/resolve/main/data/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
- Command line
-
hf download hf://datasets/introvoyz042/OpenFOAM-dev/data/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
-
curl -L -o dictionaryTemplates.C https://huggingface.co/datasets/introvoyz042/OpenFOAM-dev/resolve/main/data/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
11.9 kB
| /*---------------------------------------------------------------------------*\ | |
| ========= | | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | |
| \\ / O peration | Website: https://openfoam.org | |
| \\ / A nd | Copyright (C) 2011-2026 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/>. | |
| \*---------------------------------------------------------------------------*/ | |
| // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // | |
| template<class ... Entries> | |
| std::tuple<const Entries& ...> Foam::dictionary::entries | |
| ( | |
| const Entries& ... entries | |
| ) | |
| { | |
| return std::tuple<const Entries& ...>(entries ...); | |
| } | |
| // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // | |
| template<class ... Entries, size_t ... Indices> | |
| void Foam::dictionary::set | |
| ( | |
| const std::tuple<const Entries& ...>& entries, | |
| const std::integer_sequence<size_t, Indices ...>& | |
| ) | |
| { | |
| set(std::get<Indices>(entries) ...); | |
| } | |
| template<class ... Entries> | |
| void Foam::dictionary::set | |
| ( | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| { | |
| set(entries, std::make_integer_sequence<size_t, sizeof ... (Entries)>()); | |
| } | |
| // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // | |
| template<class ... Entries> | |
| Foam::dictionary::dictionary(const std::tuple<const Entries& ...>& entries) | |
| : | |
| dictionary() | |
| { | |
| set(entries); | |
| } | |
| template<class ... Entries> | |
| Foam::dictionary::dictionary | |
| ( | |
| const fileName& name, | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| : | |
| dictionary(name) | |
| { | |
| set(entries); | |
| } | |
| template<class ... Entries> | |
| Foam::dictionary::dictionary | |
| ( | |
| const fileName& name, | |
| const dictionary& parentDict, | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| : | |
| dictionary(name, parentDict) | |
| { | |
| set(entries); | |
| } | |
| template<class ... Entries> | |
| Foam::dictionary::dictionary | |
| ( | |
| const dictionary& dict, | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| : | |
| dictionary(dict) | |
| { | |
| set(entries); | |
| } | |
| // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // | |
| template<class T> | |
| T Foam::dictionary::lookup | |
| ( | |
| const word& keyword, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr == nullptr) | |
| { | |
| FatalIOErrorInFunction(*this) | |
| << "keyword " << keyword << " is undefined in dictionary " | |
| << name() << exit(FatalIOError); | |
| } | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| template<class T, class DefaultUnits> | |
| T Foam::dictionary::lookup | |
| ( | |
| const word& keyword, | |
| const DefaultUnits& defaultUnits, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr == nullptr) | |
| { | |
| FatalIOErrorInFunction(*this) | |
| << "keyword " << keyword << " is undefined in dictionary " | |
| << name() << exit(FatalIOError); | |
| } | |
| return Foam::readAndConvert<T>(entryPtr->stream(), defaultUnits); | |
| } | |
| template<class T> | |
| T Foam::dictionary::lookupBackwardsCompatible | |
| ( | |
| const wordList& keywords, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupEntryPtrBackwardsCompatible(keywords, recursive, patternMatch); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| else | |
| { | |
| // Generate error message using the first keyword | |
| return lookup<T>(keywords[0], recursive, patternMatch); | |
| } | |
| } | |
| template<class T, class DefaultUnits> | |
| T Foam::dictionary::lookupBackwardsCompatible | |
| ( | |
| const wordList& keywords, | |
| const DefaultUnits& defaultUnits, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupEntryPtrBackwardsCompatible(keywords, recursive, patternMatch); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndConvert<T>(entryPtr->stream(), defaultUnits); | |
| } | |
| else | |
| { | |
| // Generate error message using the first keyword | |
| return lookup<T>(keywords[0], recursive, patternMatch); | |
| } | |
| } | |
| template<class T> | |
| T Foam::dictionary::lookupOrDefault | |
| ( | |
| const word& keyword, | |
| const T& defaultValue | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, false, false); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| else | |
| { | |
| if (haveDefaults(*this)) | |
| { | |
| defaults(*this).add | |
| ( | |
| new primitiveEntry(keyword, defaultValue), | |
| true | |
| ); | |
| } | |
| return defaultValue; | |
| } | |
| } | |
| template<class T, class DefaultUnits> | |
| T Foam::dictionary::lookupOrDefault | |
| ( | |
| const word& keyword, | |
| const DefaultUnits& defaultUnits, | |
| const T& defaultValue | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, false, false); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndConvert<T>(entryPtr->stream(), defaultUnits); | |
| } | |
| else | |
| { | |
| if (haveDefaults(*this)) | |
| { | |
| defaults(*this).add | |
| ( | |
| new primitiveEntry(keyword, defaultValue), | |
| true | |
| ); | |
| } | |
| return defaultValue; | |
| } | |
| } | |
| template<class T> | |
| T Foam::dictionary::lookupOrDefaultBackwardsCompatible | |
| ( | |
| const wordList& keywords, | |
| const T& defaultValue | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupEntryPtrBackwardsCompatible(keywords, false, false); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| else | |
| { | |
| // Generate debugging messages using the first keyword | |
| return lookupOrDefault<T>(keywords[0], defaultValue); | |
| } | |
| } | |
| template<class T, class DefaultUnits> | |
| T Foam::dictionary::lookupOrDefaultBackwardsCompatible | |
| ( | |
| const wordList& keywords, | |
| const DefaultUnits& defaultUnits, | |
| const T& defaultValue | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupEntryPtrBackwardsCompatible(keywords, false, false); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndConvert<T>(entryPtr->stream(), defaultUnits); | |
| } | |
| else | |
| { | |
| // Generate debugging messages using the first keyword | |
| return lookupOrDefault<T>(keywords[0], defaultValue); | |
| } | |
| } | |
| template<class T> | |
| T Foam::dictionary::lookupOrAddDefault | |
| ( | |
| const word& keyword, | |
| const T& defaultValue | |
| ) | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, false, false); | |
| if (entryPtr) | |
| { | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| else | |
| { | |
| if (haveDefaults(*this)) | |
| { | |
| defaults(*this).add | |
| ( | |
| new primitiveEntry(keyword, defaultValue), | |
| true | |
| ); | |
| } | |
| add(new primitiveEntry(keyword, defaultValue)); | |
| return defaultValue; | |
| } | |
| } | |
| template<class T> | |
| bool Foam::dictionary::readIfPresent | |
| ( | |
| const word& keyword, | |
| T& val, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr) | |
| { | |
| val = Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| return true; | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| } | |
| template<class T, class DefaultUnits> | |
| bool Foam::dictionary::readIfPresent | |
| ( | |
| const word& keyword, | |
| const DefaultUnits& defaultUnits, | |
| T& val, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr) | |
| { | |
| val = Foam::readAndConvert<T>(entryPtr->stream(), defaultUnits); | |
| return true; | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| } | |
| template<class T> | |
| T Foam::dictionary::lookupScoped | |
| ( | |
| const word& keyword, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupScopedEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr == nullptr) | |
| { | |
| FatalIOErrorInFunction(*this) | |
| << "keyword " << keyword << " is undefined in dictionary " | |
| << name() << exit(FatalIOError); | |
| } | |
| return Foam::readAndMaybeConvert<T>(entryPtr->stream()); | |
| } | |
| template<class T> | |
| const T& Foam::dictionary::lookupCompoundScoped | |
| ( | |
| const word& keyword, | |
| bool recursive, | |
| bool patternMatch | |
| ) const | |
| { | |
| const entry* entryPtr = | |
| lookupScopedEntryPtr(keyword, recursive, patternMatch); | |
| if (entryPtr == nullptr) | |
| { | |
| FatalIOErrorInFunction | |
| ( | |
| *this | |
| ) << "keyword " << keyword << " is undefined in dictionary " | |
| << name() | |
| << exit(FatalIOError); | |
| } | |
| token firstToken(entryPtr->stream()); | |
| return dynamicCast<const token::Compound<T>>(firstToken.compoundToken()); | |
| } | |
| template<class T> | |
| void Foam::dictionary::add(const keyType& k, const T& t, bool overwrite) | |
| { | |
| add(new primitiveEntry(k, t), overwrite); | |
| } | |
| template<class T> | |
| void Foam::dictionary::set(const keyType& k, const T& t) | |
| { | |
| set(new primitiveEntry(k, t)); | |
| } | |
| template<class ... Entries> | |
| void Foam::dictionary::set | |
| ( | |
| const keyType& k, | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| { | |
| set(new dictionaryEntry(k, *this, entries)); | |
| } | |
| template<class ... Entries> | |
| void Foam::dictionary::set(const entry& e, const Entries& ... entries) | |
| { | |
| set(e); | |
| set(entries ...); | |
| } | |
| template<class T, class ... Entries> | |
| void Foam::dictionary::set | |
| ( | |
| const keyType& k, | |
| const T& t, | |
| const Entries& ... entries | |
| ) | |
| { | |
| set(k, t); | |
| set(entries ...); | |
| } | |
| // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * // | |
| template<class ... Entries> | |
| void Foam::writeEntry | |
| ( | |
| Ostream& os, | |
| const word& entryName, | |
| const std::tuple<const Entries& ...>& entries | |
| ) | |
| { | |
| writeEntry(os, entryName, dictionary(entries)); | |
| } | |
| template<class EntryType> | |
| void Foam::writeEntry | |
| ( | |
| Ostream& os, | |
| const word& entryName, | |
| const EntryType& value | |
| ) | |
| { | |
| writeKeyword(os, entryName); | |
| writeEntry(os, value); | |
| os << token::END_STATEMENT << endl; | |
| } | |
| template<class EntryType, class DefaultUnits> | |
| void Foam::writeEntry | |
| ( | |
| Ostream& os, | |
| const word& entryName, | |
| const DefaultUnits& defaultUnits, | |
| const EntryType& value | |
| ) | |
| { | |
| writeKeyword(os, entryName); | |
| writeEntry(os, defaultUnits, value); | |
| os << token::END_STATEMENT << endl; | |
| } | |
| template<class EntryType> | |
| void Foam::writeEntryIfDifferent | |
| ( | |
| Ostream& os, | |
| const word& entryName, | |
| const EntryType& value1, | |
| const EntryType& value2 | |
| ) | |
| { | |
| if (value1 != value2) | |
| { | |
| writeEntry(os, entryName, value2); | |
| } | |
| } | |
| template<class EntryType, class DefaultUnits> | |
| void Foam::writeEntryIfDifferent | |
| ( | |
| Ostream& os, | |
| const word& entryName, | |
| const DefaultUnits& defaultUnits, | |
| const EntryType& value1, | |
| const EntryType& value2 | |
| ) | |
| { | |
| if (value1 != value2) | |
| { | |
| writeEntry(os, entryName, defaultUnits, value2); | |
| } | |
| } | |
| // ************************************************************************* // | |