diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C index 17aad06a00..da7c1766cd 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.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) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,7 @@ License #include "dlLibraryTable.H" #include "PstreamReduceOps.H" #include "OSspecific.H" +#include "Ostream.H" #include "regIOobject.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -42,6 +43,45 @@ namespace Foam // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +namespace Foam +{ +//! \cond fileScope +static inline void writeEntryIfPresent +( + Ostream& os, + const dictionary& dict, + const word& key +) +{ + // non-recursive like dictionary::found, but no pattern-match either + const entry* ptr = dict.lookupEntryPtr(key,false,false); + + if (ptr) + { + os.writeKeyword(key) + << token::HASH << token::BEGIN_BLOCK; + + os.writeQuoted(string(ptr->stream()), false) + << token::HASH << token::END_BLOCK + << token::END_STATEMENT << nl; + } +} +//! \endcond +} + + +void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict) +{ + writeEntryIfPresent(os, dict, "codeInclude"); + writeEntryIfPresent(os, dict, "localCode"); + writeEntryIfPresent(os, dict, "code"); + writeEntryIfPresent(os, dict, "codeOptions"); + writeEntryIfPresent(os, dict, "codeLibs"); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + void* Foam::codedBase::loadLibrary ( const fileName& libPath, @@ -165,8 +205,6 @@ void Foam::codedBase::unloadLibrary } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - void Foam::codedBase::createLibrary ( dynamicCode& dynCode, diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H index 8ac7114ce6..1c03e71c09 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H @@ -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) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,7 @@ namespace Foam { // Forward declaration of classes +class Ostream; class dynamicCode; class dynamicCodeContext; class dlLibraryTable; @@ -83,14 +84,17 @@ class codedBase void createLibrary(dynamicCode&, const dynamicCodeContext&) const; //- Disallow default bitwise copy construct - codedBase(const codedBase&); + codedBase(const codedBase&) = delete; //- Disallow default bitwise assignment - void operator=(const codedBase&); + void operator=(const codedBase&) = delete; protected: + //- Write code-dictionary contents + static void writeCodeDict(Ostream&, const dictionary&); + //- Update library as required void updateLibrary ( diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index f56a8cf1e7..a840d79482 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -331,55 +331,7 @@ void Foam::codedFixedValuePointPatchField::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index cfd6945420..5771972313 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -329,55 +329,7 @@ void Foam::codedFixedValueFvPatchField::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index d1b53e144d..450aa8b9e6 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -341,55 +341,7 @@ void Foam::codedMixedFvPatchField::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); }