From 23dd3e072b3d2088a1153cb7f0d736b3de057190 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Wed, 23 Feb 2011 13:02:36 +0100 Subject: [PATCH] ENH: provide for writing contents only from dictionary entries --- src/OpenFOAM/db/dictionary/dictionary.H | 3 ++- .../dictionaryEntry/dictionaryEntry.H | 4 +-- .../dictionaryEntry/dictionaryEntryIO.C | 2 +- .../primitiveEntry/primitiveEntry.H | 5 +++- .../primitiveEntry/primitiveEntryIO.C | 26 ++++++++++++++----- .../primitives/strings/stringOps/stringOps.H | 4 --- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index f1196852bf1..cb3b03b00fe 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -477,7 +477,8 @@ public: // Write - void write(Ostream&, bool subDict=true) const; + //- Write dictionary, normally with sub-dictionary formatting + void write(Ostream&, const bool subDict=true) const; // Member Operators diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index 050840c5e4c..7713e503af3 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -146,7 +146,7 @@ public: //- Return non-const access to dictionary dictionary& dict(); - // Write + //- Write void write(Ostream&) const; //- Return info proxy. diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index b090188a0de..2477f0450b5 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index 6edf2c621c5..01f08cea5b3 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -168,6 +168,9 @@ public: //- Write void write(Ostream&) const; + //- Write, optionally with contents only (no keyword, etc) + void write(Ostream&, const bool contentsOnly) const; + //- Return info proxy. // Used to print token information to a stream InfoProxy<primitiveEntry> info() const diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index fa9a50efdb1..33c3dc8ff7c 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -210,31 +210,43 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::primitiveEntry::write(Ostream& os) const +void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const { - os.writeKeyword(keyword()); + if (!contentsOnly) + { + os.writeKeyword(keyword()); + } for (label i=0; i<size(); ++i) { const token& t = operator[](i); if (t.type() == token::VERBATIMSTRING) { - os << token::HASH << token::BEGIN_BLOCK; + os << token::HASH << token::BEGIN_BLOCK; os.writeQuoted(t.stringToken(), false); - os << token::HASH << token::END_BLOCK; + os << token::HASH << token::END_BLOCK; } else { - os << t; + os << t; } if (i < size()-1) { - os << token::SPACE; + os << token::SPACE; } } - os << token::END_STATEMENT << endl; + if (!contentsOnly) + { + os << token::END_STATEMENT << endl; + } +} + + +void Foam::primitiveEntry::write(Ostream& os) const +{ + this->write(os, false); } diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index d9756a27056..6d416dd6e81 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -128,19 +128,15 @@ namespace stringOps string& inplaceTrimLeft(string&); //- Return string trimmed of trailing whitespace - // NOT IMPLEMENTED string trimRight(const string&); //- Trim trailing whitespace inplace - // NOT IMPLEMENTED string& inplaceTrimRight(string&); //- Return string trimmed of leading and trailing whitespace - // NOT IMPLEMENTED string trim(const string&); //- Trim leading and trailing whitespace inplace - // NOT IMPLEMENTED string& inplaceTrim(string&); -- GitLab