ENH: expose dictionary relativeName() method

STYLE: more consistent noexcept for dictionary and entry
This commit is contained in:
Mark Olesen
2021-11-01 14:04:27 +01:00
parent b364a9e72c
commit 1c354ce299
7 changed files with 53 additions and 58 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,23 +59,6 @@ registerInfoSwitch
); );
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::fileName Foam::dictionary::relativeName(const bool caseTag) const
{
const fileName caseDir(argList::envGlobalPath());
if (!caseDir.empty() && name().isAbsolute())
{
return name().relative(caseDir, caseTag);
}
else
{
return name();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dictionary::dictionary() Foam::dictionary::dictionary()
@ -189,6 +172,12 @@ Foam::dictionary::~dictionary()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::dictionary::relativeName(const bool caseTag) const
{
return argList::envRelativePath(name(), caseTag);
}
const Foam::dictionary& Foam::dictionary::topDict() const const Foam::dictionary& Foam::dictionary::topDict() const
{ {
const dictionary& p = parent(); const dictionary& p = parent();

View File

@ -171,7 +171,8 @@ public:
pointer eptr_; pointer eptr_;
//- Construct for the given dictionary context //- Construct for the given dictionary context.
// Allow implicit conversion
Searcher(dict_pointer dict) Searcher(dict_pointer dict)
: :
dict_(dict), dict_(dict),
@ -196,62 +197,62 @@ public:
//- True if entry was found //- True if entry was found
inline bool good() const bool good() const noexcept
{ {
return eptr_; return eptr_;
} }
//- True if entry was found //- True if entry was found
inline bool found() const bool found() const noexcept
{ {
return eptr_; return eptr_;
} }
//- The containing dictionary context //- The containing dictionary context
inline dict_reference context() const dict_reference context() const
{ {
return *dict_; return *dict_;
} }
//- A pointer to the entry (nullptr if not found) //- A pointer to the entry (nullptr if not found)
inline pointer ptr() const pointer ptr() const noexcept
{ {
return eptr_; return eptr_;
} }
//- A reference to the entry (Error if not found) //- A reference to the entry (Error if not found)
inline reference ref() const reference ref() const
{ {
return *eptr_; return *eptr_;
} }
//- True if found entry is a dictionary. //- True if found entry is a dictionary.
inline bool isDict() const bool isDict() const noexcept
{ {
return eptr_ && eptr_->isDict(); return (eptr_ && eptr_->dictPtr());
} }
//- Pointer to the found entry as a dictionary or nullptr otherwise. //- Pointer to the found entry as a dictionary, nullptr otherwise
inline dict_pointer dictPtr() const dict_pointer dictPtr() const noexcept
{ {
return eptr_ && eptr_->isDict() ? eptr_->dictPtr() : nullptr; return eptr_ ? eptr_->dictPtr() : nullptr;
} }
//- Reference the found entry as a dictionary. //- Reference the found entry as a dictionary.
// (Error if not found, or not a dictionary). // (Error if not found, or not a dictionary).
inline dict_reference dict() const dict_reference dict() const
{ {
return eptr_->dict(); return eptr_->dict();
} }
//- Permit an explicit cast to the other (const/non-const) searcher //- Permit an explicit cast to the other (const/non-const) searcher
inline explicit operator const Searcher<!Const>&() const explicit operator const Searcher<!Const>&() const
{ {
return *reinterpret_cast<const Searcher<!Const>*>(this); return *reinterpret_cast<const Searcher<!Const>*>(this);
} }
//- A pointer to the entry (nullptr if not found) //- A pointer to the entry (nullptr if not found)
pointer operator->() const pointer operator->() const noexcept
{ {
return eptr_; return eptr_;
} }
@ -359,9 +360,6 @@ private:
//- Emit IOError about bad input for the entry //- Emit IOError about bad input for the entry
void raiseBadInput(const ITstream& is, const word& keyword) const; void raiseBadInput(const ITstream& is, const word& keyword) const;
//- The case-relative dictionary name. Uses FOAM_CASE
fileName relativeName(const bool caseTag=false) const;
//- Report (on stderr) that the keyword default value was used //- Report (on stderr) that the keyword default value was used
template<class T> template<class T>
void reportDefault void reportDefault
@ -379,7 +377,7 @@ public:
//- Report optional keywords and values if not present in dictionary //- Report optional keywords and values if not present in dictionary
// For value greater than 1: fatal. // For value greater than 1: fatal.
// Set/unset via an InfoSwitch // Set/unset via an InfoSwitch or -info-switch at the command-line
static int writeOptionalEntries; static int writeOptionalEntries;
//- An empty dictionary, which is also the parent for all dictionaries //- An empty dictionary, which is also the parent for all dictionaries
@ -445,13 +443,13 @@ public:
// Access // Access
//- The dictionary name //- The dictionary name
const fileName& name() const const fileName& name() const noexcept
{ {
return name_; return name_;
} }
//- The dictionary name for modification (use with caution). //- The dictionary name for modification (use with caution).
fileName& name() fileName& name() noexcept
{ {
return name_; return name_;
} }
@ -470,8 +468,16 @@ public:
return scopedName.substr(i+1); return scopedName.substr(i+1);
} }
//- The dictionary name relative to the case.
// Uses argList::envRelativePath to obtain FOAM_CASE
//
// \param caseTag replace globalPath with \<case\> for later
// use with expand(), or prefix \<case\> if the file name was
// not an absolute location
fileName relativeName(const bool caseTag = false) const;
//- Return the parent dictionary //- Return the parent dictionary
const dictionary& parent() const const dictionary& parent() const noexcept
{ {
return parent_; return parent_;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,25 +87,25 @@ Foam::ITstream& Foam::dictionaryEntry::stream() const
} }
const Foam::dictionary* Foam::dictionaryEntry::dictPtr() const const Foam::dictionary* Foam::dictionaryEntry::dictPtr() const noexcept
{ {
return this; return this;
} }
Foam::dictionary* Foam::dictionaryEntry::dictPtr() Foam::dictionary* Foam::dictionaryEntry::dictPtr() noexcept
{ {
return this; return this;
} }
const Foam::dictionary& Foam::dictionaryEntry::dict() const const Foam::dictionary& Foam::dictionaryEntry::dict() const noexcept
{ {
return *this; return *this;
} }
Foam::dictionary& Foam::dictionaryEntry::dict() Foam::dictionary& Foam::dictionaryEntry::dict() noexcept
{ {
return *this; return *this;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -137,16 +137,16 @@ public:
//- Return pointer to this dictionary //- Return pointer to this dictionary
virtual const dictionary* dictPtr() const; virtual const dictionary* dictPtr() const noexcept;
//- Return non-const pointer to this dictionary //- Return non-const pointer to this dictionary
virtual dictionary* dictPtr(); virtual dictionary* dictPtr() noexcept;
//- Return dictionary //- Return dictionary (ie, this)
virtual const dictionary& dict() const; virtual const dictionary& dict() const noexcept;
//- Return non-const access to dictionary //- Return non-const access to dictionary
virtual dictionary& dict(); virtual dictionary& dict() noexcept;
//- Write //- Write
@ -160,7 +160,7 @@ public:
} }
// Ostream operator // Ostream Operator
friend Ostream& operator<<(Ostream& os, const dictionaryEntry& e); friend Ostream& operator<<(Ostream& os, const dictionaryEntry& e);
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,7 +40,7 @@ void Foam::dictionary::reportDefault
) const ) const
{ {
InfoErr InfoErr
<< "Dictionary: " << relativeName(true).c_str() << "Dictionary: " << this->relativeName().c_str()
<< " Entry: " << keyword; << " Entry: " << keyword;
if (added) if (added)

View File

@ -210,7 +210,7 @@ public:
//- Return true if this entry is a stream //- Return true if this entry is a stream
virtual bool isStream() const virtual bool isStream() const noexcept
{ {
return false; return false;
} }
@ -220,21 +220,21 @@ public:
//- Return true if this entry is a dictionary //- Return true if this entry is a dictionary
virtual bool isDict() const virtual bool isDict() const noexcept
{ {
return this->dictPtr(); return this->dictPtr();
} }
//- Return pointer to dictionary, if entry is a dictionary. //- Return pointer to dictionary, if entry is a dictionary.
// Return nullptr if the entry is not a dictionary. // Return nullptr if the entry is not a dictionary.
virtual const dictionary* dictPtr() const virtual const dictionary* dictPtr() const noexcept
{ {
return nullptr; return nullptr;
} }
//- Return non-const pointer to dictionary, if entry is a dictionary //- Return non-const pointer to dictionary, if entry is a dictionary
// Return nullptr if the entry is not a dictionary. // Return nullptr if the entry is not a dictionary.
virtual dictionary* dictPtr() virtual dictionary* dictPtr() noexcept
{ {
return nullptr; return nullptr;
} }

View File

@ -162,7 +162,7 @@ public:
virtual label endLineNumber() const; virtual label endLineNumber() const;
//- Return true - this entry is a stream //- Return true - this entry is a stream
virtual bool isStream() const virtual bool isStream() const noexcept
{ {
return true; return true;
} }