mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide direct pointer access to dictionaryEntry
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -88,6 +88,18 @@ Foam::ITstream& Foam::dictionaryEntry::stream() const
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary* Foam::dictionaryEntry::dictPtr() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Foam::dictionary* Foam::dictionaryEntry::dictPtr()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary& Foam::dictionaryEntry::dict() const
|
||||
{
|
||||
return *this;
|
||||
|
||||
@ -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) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -52,10 +52,8 @@ namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class dictionaryEntry;
|
||||
|
||||
Ostream& operator<<(Ostream& os, const dictionaryEntry& de);
|
||||
Ostream& operator<<(Ostream& os, const dictionaryEntry& e);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -111,13 +109,13 @@ public:
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Return the dictionary name (scoped, e.g. dictA::dictB::dictC)
|
||||
//- Return the scoped dictionary name (eg, dictA.dictB.dictC)
|
||||
const fileName& name() const
|
||||
{
|
||||
return dictionary::name();
|
||||
}
|
||||
|
||||
//- Return the dictionary name (scoped, e.g. dictA::dictB::dictC)
|
||||
//- Return the scoped dictionary name (eg, dictA.dictB.dictC)
|
||||
fileName& name()
|
||||
{
|
||||
return dictionary::name();
|
||||
@ -133,11 +131,12 @@ public:
|
||||
// calling this function generates a FatalError
|
||||
ITstream& stream() const;
|
||||
|
||||
//- Return true because this entry is a dictionary
|
||||
bool isDict() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//- Return pointer to this dictionary
|
||||
virtual const dictionary* dictPtr() const;
|
||||
|
||||
//- Return non-const pointer to this dictionary
|
||||
virtual dictionary* dictPtr();
|
||||
|
||||
//- Return dictionary
|
||||
const dictionary& dict() const;
|
||||
@ -159,7 +158,7 @@ public:
|
||||
|
||||
// Ostream operator
|
||||
|
||||
friend Ostream& operator<<(Ostream& os, const dictionaryEntry& de);
|
||||
friend Ostream& operator<<(Ostream& os, const dictionaryEntry& e);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -23,7 +23,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "keyType.H"
|
||||
#include "dictionaryEntry.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
@ -66,9 +65,9 @@ void Foam::dictionaryEntry::write(Ostream& os) const
|
||||
|
||||
// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& de)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& e)
|
||||
{
|
||||
de.write(os);
|
||||
e.write(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -52,8 +52,7 @@ namespace Foam
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class dictionaryListEntry;
|
||||
|
||||
Ostream& operator<<(Ostream&, const dictionaryListEntry&);
|
||||
Ostream& operator<<(Ostream& os, const dictionaryListEntry& e);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -66,9 +65,6 @@ class dictionaryListEntry
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Returns size of dictionary without FoamFile
|
||||
static label realSize(const dictionary&);
|
||||
|
||||
//- Disallow bitwise copy
|
||||
dictionaryListEntry(const dictionaryListEntry&) = delete;
|
||||
|
||||
@ -78,13 +74,13 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from the parent dictionary and Istream
|
||||
dictionaryListEntry(const dictionary& parentDict, Istream&);
|
||||
dictionaryListEntry(const dictionary& parentDict, Istream& is);
|
||||
|
||||
//- Construct as copy for the given parent dictionary
|
||||
dictionaryListEntry
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
const dictionaryListEntry&
|
||||
const dictionaryListEntry& dictEnt
|
||||
);
|
||||
|
||||
autoPtr<entry> clone(const dictionary& parentDict) const
|
||||
@ -96,7 +92,7 @@ public:
|
||||
// Member functions
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream&) const;
|
||||
virtual void write(Ostream& os) const;
|
||||
|
||||
//- Return info proxy.
|
||||
// Used to print token information to a stream
|
||||
@ -108,12 +104,12 @@ public:
|
||||
|
||||
// Ostream operator
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const dictionaryListEntry&);
|
||||
friend Ostream& operator<<(Ostream& os, const dictionaryListEntry& e);
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
Ostream& operator<<(Ostream&, const InfoProxy<dictionaryListEntry>&);
|
||||
Ostream& operator<<(Ostream& os, const InfoProxy<dictionaryListEntry>& ip);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -24,12 +24,12 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dictionaryListEntry.H"
|
||||
#include "keyType.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::dictionaryListEntry::realSize(const dictionary& dict)
|
||||
// File-scope: The dictionary size without the "FoamFile" entry
|
||||
static Foam::label realSize(const Foam::dictionary& dict)
|
||||
{
|
||||
if (dict.size() < 1 || dict.first()->keyword() != "FoamFile")
|
||||
{
|
||||
@ -127,9 +127,9 @@ void Foam::dictionaryListEntry::write(Ostream& os) const
|
||||
|
||||
// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryListEntry& de)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryListEntry& e)
|
||||
{
|
||||
de.write(os);
|
||||
e.write(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@ -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) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -153,37 +153,54 @@ public:
|
||||
//- Return line number of last token in dictionary
|
||||
virtual label endLineNumber() const = 0;
|
||||
|
||||
|
||||
//- Return true if this entry is a stream
|
||||
virtual bool isStream() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//- Return token stream if this entry is a primitive entry
|
||||
//- Return token stream, if entry is a primitive entry
|
||||
virtual ITstream& stream() const = 0;
|
||||
|
||||
|
||||
//- Return true if this entry is a dictionary
|
||||
virtual bool isDict() const
|
||||
{
|
||||
return false;
|
||||
return !this->dictPtr();
|
||||
}
|
||||
|
||||
//- Return dictionary if this entry is a dictionary
|
||||
//- Return pointer to dictionary, if entry is a dictionary.
|
||||
// Return nullptr if the entry is not a dictionary.
|
||||
virtual const dictionary* dictPtr() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//- Return non-const pointer to dictionary, if entry is a dictionary
|
||||
// Return nullptr if the entry is not a dictionary.
|
||||
virtual dictionary* dictPtr()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//- Return dictionary, if entry is a dictionary
|
||||
virtual const dictionary& dict() const = 0;
|
||||
|
||||
//- Return non-const access to dictionary if this entry is a dictionary
|
||||
//- Return non-const access to dictionary, if entry is a dictionary
|
||||
virtual dictionary& dict() = 0;
|
||||
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream&) const = 0;
|
||||
virtual void write(Ostream& os) const = 0;
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
void operator=(const entry&);
|
||||
void operator=(const entry& e);
|
||||
|
||||
bool operator==(const entry&) const;
|
||||
bool operator!=(const entry&) const;
|
||||
bool operator==(const entry& e) const;
|
||||
bool operator!=(const entry& e) const;
|
||||
|
||||
|
||||
// Ostream operator
|
||||
|
||||
@ -32,9 +32,9 @@ License
|
||||
|
||||
void Foam::primitiveEntry::append(const UList<token>& varTokens)
|
||||
{
|
||||
forAll(varTokens, i)
|
||||
for (const token& tok : varTokens)
|
||||
{
|
||||
newElmt(tokenIndex()++) = varTokens[i];
|
||||
newElmt(tokenIndex()++) = tok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -160,7 +160,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
//- Return token stream if this entry is a primitive entry
|
||||
//- Return token stream for this primitive entry
|
||||
ITstream& stream() const;
|
||||
|
||||
//- This entry is not a dictionary,
|
||||
|
||||
@ -227,9 +227,15 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
|
||||
os.writeKeyword(keyword());
|
||||
}
|
||||
|
||||
for (label i=0; i<size(); ++i)
|
||||
bool space = false; // Separate from previous tokens with a space
|
||||
for (const token& t : *this)
|
||||
{
|
||||
const token& t = operator[](i);
|
||||
if (space)
|
||||
{
|
||||
os << token::SPACE;
|
||||
}
|
||||
space = true; // Prefix any following tokens
|
||||
|
||||
if (t.type() == token::VERBATIMSTRING)
|
||||
{
|
||||
// Bypass token output operator to avoid losing verbatimness.
|
||||
@ -240,11 +246,6 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
|
||||
{
|
||||
os << t;
|
||||
}
|
||||
|
||||
if (i < size()-1)
|
||||
{
|
||||
os << token::SPACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!contentsOnly)
|
||||
|
||||
Reference in New Issue
Block a user