/*---------------------------------------------------------------------------*\
========= |
\\ / 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 .
\*---------------------------------------------------------------------------*/
#include "dictionary.H"
#include "primitiveEntry.H"
#include "dictionaryEntry.H"
#include "unitSet.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template
std::tuple Foam::dictionary::entries
(
const Entries& ... entries
)
{
return std::tuple(entries ...);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
void Foam::dictionary::set
(
const std::tuple& entries,
const std::integer_sequence&
)
{
set(std::get(entries) ...);
}
template
void Foam::dictionary::set
(
const std::tuple& entries
)
{
set(entries, std::make_integer_sequence());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::dictionary::dictionary(const std::tuple& entries)
:
dictionary()
{
set(entries);
}
template
Foam::dictionary::dictionary
(
const fileName& name,
const std::tuple& entries
)
:
dictionary(name)
{
set(entries);
}
template
Foam::dictionary::dictionary
(
const fileName& name,
const dictionary& parentDict,
const std::tuple& entries
)
:
dictionary(name, parentDict)
{
set(entries);
}
template
Foam::dictionary::dictionary
(
const dictionary& dict,
const std::tuple& entries
)
:
dictionary(dict)
{
set(entries);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
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(entryPtr->stream());
}
template
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(entryPtr->stream(), defaultUnits);
}
template
T Foam::dictionary::lookupBackwardsCompatible
(
const wordList& keywords,
bool recursive,
bool patternMatch
) const
{
const entry* entryPtr =
lookupEntryPtrBackwardsCompatible(keywords, recursive, patternMatch);
if (entryPtr)
{
return Foam::readAndMaybeConvert(entryPtr->stream());
}
else
{
// Generate error message using the first keyword
return lookup(keywords[0], recursive, patternMatch);
}
}
template
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(entryPtr->stream(), defaultUnits);
}
else
{
// Generate error message using the first keyword
return lookup(keywords[0], recursive, patternMatch);
}
}
template
T Foam::dictionary::lookupOrDefault
(
const word& keyword,
const T& defaultValue
) const
{
const entry* entryPtr = lookupEntryPtr(keyword, false, false);
if (entryPtr)
{
return Foam::readAndMaybeConvert(entryPtr->stream());
}
else
{
if (haveDefaults(*this))
{
defaults(*this).add
(
new primitiveEntry(keyword, defaultValue),
true
);
}
return defaultValue;
}
}
template
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(entryPtr->stream(), defaultUnits);
}
else
{
if (haveDefaults(*this))
{
defaults(*this).add
(
new primitiveEntry(keyword, defaultValue),
true
);
}
return defaultValue;
}
}
template
T Foam::dictionary::lookupOrDefaultBackwardsCompatible
(
const wordList& keywords,
const T& defaultValue
) const
{
const entry* entryPtr =
lookupEntryPtrBackwardsCompatible(keywords, false, false);
if (entryPtr)
{
return Foam::readAndMaybeConvert(entryPtr->stream());
}
else
{
// Generate debugging messages using the first keyword
return lookupOrDefault(keywords[0], defaultValue);
}
}
template
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(entryPtr->stream(), defaultUnits);
}
else
{
// Generate debugging messages using the first keyword
return lookupOrDefault(keywords[0], defaultValue);
}
}
template
T Foam::dictionary::lookupOrAddDefault
(
const word& keyword,
const T& defaultValue
)
{
const entry* entryPtr = lookupEntryPtr(keyword, false, false);
if (entryPtr)
{
return Foam::readAndMaybeConvert(entryPtr->stream());
}
else
{
if (haveDefaults(*this))
{
defaults(*this).add
(
new primitiveEntry(keyword, defaultValue),
true
);
}
add(new primitiveEntry(keyword, defaultValue));
return defaultValue;
}
}
template
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(entryPtr->stream());
return true;
}
else
{
return false;
}
}
template
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(entryPtr->stream(), defaultUnits);
return true;
}
else
{
return false;
}
}
template
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(entryPtr->stream());
}
template
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>(firstToken.compoundToken());
}
template
void Foam::dictionary::add(const keyType& k, const T& t, bool overwrite)
{
add(new primitiveEntry(k, t), overwrite);
}
template
void Foam::dictionary::set(const keyType& k, const T& t)
{
set(new primitiveEntry(k, t));
}
template
void Foam::dictionary::set
(
const keyType& k,
const std::tuple& entries
)
{
set(new dictionaryEntry(k, *this, entries));
}
template
void Foam::dictionary::set(const entry& e, const Entries& ... entries)
{
set(e);
set(entries ...);
}
template
void Foam::dictionary::set
(
const keyType& k,
const T& t,
const Entries& ... entries
)
{
set(k, t);
set(entries ...);
}
// * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
template
void Foam::writeEntry
(
Ostream& os,
const word& entryName,
const std::tuple& entries
)
{
writeEntry(os, entryName, dictionary(entries));
}
template
void Foam::writeEntry
(
Ostream& os,
const word& entryName,
const EntryType& value
)
{
writeKeyword(os, entryName);
writeEntry(os, value);
os << token::END_STATEMENT << endl;
}
template
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
void Foam::writeEntryIfDifferent
(
Ostream& os,
const word& entryName,
const EntryType& value1,
const EntryType& value2
)
{
if (value1 != value2)
{
writeEntry(os, entryName, value2);
}
}
template
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);
}
}
// ************************************************************************* //