diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C index 9ffe101620..6167956e70 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C @@ -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; diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index c2d552b775..06976c789b 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.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) 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); }; diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index 5a4feda30e..d2cdd07fd9 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -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; } diff --git a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntry.H b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntry.H index 389e79c7a3..2e575713b9 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntry.H @@ -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 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&); +Ostream& operator<<(Ostream& os, const InfoProxy& ip); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C index c368e68035..53399cc543 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C @@ -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; } diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index f71a60d123..82311e5356 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.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) 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 diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C index b36c7d4770..37cc203083 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C @@ -32,9 +32,9 @@ License void Foam::primitiveEntry::append(const UList& varTokens) { - forAll(varTokens, i) + for (const token& tok : varTokens) { - newElmt(tokenIndex()++) = varTokens[i]; + newElmt(tokenIndex()++) = tok; } } diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index b5cebed502..38e9412a8d 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -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, diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 1b9870347b..96a20c0cc0 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -227,9 +227,15 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const os.writeKeyword(keyword()); } - for (label i=0; i