Commit 1e7c6ea2 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: mutable libs() access in Time and other classes (#1737)

- This reflects the pre-existing coding situation where const_cast was
  used throughout to effect the same.

STYLE: fix private/protected access

- CodedField, codedMixedFvPatchField
parent 41d3e6f1
......@@ -130,14 +130,14 @@ public:
private:
// Private data
// Private Data
//- Profiling trigger for time-loop (for run, loop)
mutable std::unique_ptr<profilingTrigger> loopProfiling_;
//- Any loaded dynamic libraries. Make sure to construct before
// reading controlDict.
dlLibraryTable libs_;
//- Any loaded dynamic libraries
// Construct before reading controlDict
mutable dlLibraryTable libs_;
//- The controlDict
unwatchedIOdictionary controlDict_;
......@@ -145,7 +145,7 @@ private:
protected:
// Protected data
// Protected Data
label startTimeIndex_;
......@@ -502,14 +502,8 @@ public:
return functionObjects_;
}
//- External access to the loaded libraries
const dlLibraryTable& libs() const
{
return libs_;
}
//- External access to the loaded libraries
dlLibraryTable& libs()
//- Mutable access to the loaded dynamic libraries
dlLibraryTable& libs() const
{
return libs_;
}
......
......@@ -73,7 +73,7 @@ Foam::dlLibraryTable& Foam::functionEntries::codeStream::libs
(
dict.topDict()
);
return const_cast<Time&>(d.time()).libs();
return d.time().libs();
}
......
......@@ -49,6 +49,7 @@ SourceFiles
#include "dictionary.H"
#include "dynamicCodeContext.H"
#include "fileName.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -100,12 +101,6 @@ class codedBase
const dynamicCodeContext& context
) const;
//- No copy construct
codedBase(const codedBase&) = delete;
//- No copy assignment
void operator=(const codedBase&) = delete;
protected:
......@@ -141,7 +136,7 @@ protected:
//- or use the codeDict() to generate one
void updateLibrary(const word& name) const;
//- Get the loaded dynamic libraries
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const = 0;
//- Adapt the context for the current object
......@@ -161,6 +156,13 @@ protected:
virtual const dictionary& codeDict() const = 0;
//- No copy construct
codedBase(const codedBase&) = delete;
//- No copy assignment
void operator=(const codedBase&) = delete;
public:
//- Runtime type information
......@@ -169,7 +171,7 @@ public:
// Constructors
//- Construct null
//- Default construct
codedBase() = default;
......
......@@ -141,7 +141,7 @@ bool Foam::dynamicCode::resolveTemplates
DynamicList<fileName>& badFiles
)
{
// Try to get template from FOAM_CODESTREAM_TEMPLATES
// Try to get template from FOAM_CODE_TEMPLATES
const fileName templateDir(Foam::getEnv(codeTemplateEnvName));
bool allOkay = true;
......
......@@ -83,7 +83,7 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
if (finder.found())
{
const_cast<Time&>(runTime).libs().open
runTime.libs().open
(
dict,
finder.ref().keyword(),
......@@ -93,7 +93,7 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
}
// This is the simplified version without compatibility messages
// const_cast<Time&>(runTime).libs().open
// runTime.libs().open
// (
// dict,
// "libs",
......
......@@ -771,7 +771,7 @@ bool Foam::functionObjectList::read()
addProfiling(fo, "functionObjects::read");
const_cast<Time&>(time_).libs().open
time_.libs().open
(
functionsDict,
"libs",
......
......@@ -66,7 +66,7 @@ const
template<class Type>
Foam::dlLibraryTable& Foam::codedFixedValuePointPatchField<Type>::libs() const
{
return const_cast<dlLibraryTable&>(this->db().time().libs());
return this->db().time().libs();
}
......
......@@ -106,7 +106,7 @@ class codedFixedValuePointPatchField
public fixedValuePointPatchField<Type>,
protected codedBase
{
// Private data
// Private Data
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
......@@ -120,7 +120,7 @@ class codedFixedValuePointPatchField
const IOdictionary& dict() const;
//- Get the loaded dynamic libraries
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
......
......@@ -854,8 +854,8 @@ Foam::argList::argList
if (strcmp(optName, "lib") == 0)
{
// The '-lib' option:
// Append name(s) to libs_ for later opening
libs_.append(this->getList<fileName>(argi));
// Append name(s) to libs for later opening
libs().append(this->getList<fileName>(argi));
}
else if (strcmp(optName, "debug-switch") == 0)
{
......@@ -1066,8 +1066,8 @@ void Foam::argList::parse
jobInfo.add("foamBuild", build);
}
// Load additional libraries
libs_.open(bannerEnabled());
// Load additional libraries (verbosity according to banner setting)
libs().open(bannerEnabled());
}
......@@ -1253,7 +1253,7 @@ void Foam::argList::parse
// Disable any parallel comms happening inside the fileHandler
// since we are on master. This can happen e.g. inside
// the masterUncollated/collated handler.
// the masterUncollated/collated handler.
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
......
......@@ -142,7 +142,7 @@ class argList
HashTable<string> options_;
//- Additional libraries
dlLibraryTable libs_;
mutable dlLibraryTable libs_;
word executable_;
fileName rootPath_;
......@@ -346,11 +346,8 @@ public:
//- Return the ParRunControl
inline const ParRunControl& parRunControl() const;
//- Access to the loaded libraries
inline const dlLibraryTable& libs() const;
//- Access to the loaded libraries
inline dlLibraryTable& libs();
//- Mutable access to the loaded dynamic libraries
inline dlLibraryTable& libs() const;
//- The number of arguments
inline label size() const noexcept;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -112,13 +112,7 @@ inline const Foam::ParRunControl& Foam::argList::parRunControl() const
}
inline const Foam::dlLibraryTable& Foam::argList::libs() const
{
return libs_;
}
inline Foam::dlLibraryTable& Foam::argList::libs()
inline Foam::dlLibraryTable& Foam::argList::libs() const
{
return libs_;
}
......
......@@ -308,7 +308,7 @@ const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
controlDict.getOrDefault<word>("agglomerator", "faceAreaPair")
);
const_cast<Time&>(mesh.thisDb().time()).libs().open
mesh.thisDb().time().libs().open
(
controlDict,
"geometricGAMGAgglomerationLibs",
......@@ -362,7 +362,7 @@ const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
controlDict.getOrDefault<word>("agglomerator", "faceAreaPair")
);
const_cast<Time&>(mesh.thisDb().time()).libs().open
mesh.thisDb().time().libs().open
(
controlDict,
"algebraicGAMGAgglomerationLibs",
......@@ -408,7 +408,7 @@ Foam::autoPtr<Foam::GAMGAgglomeration> Foam::GAMGAgglomeration::New
controlDict.getOrDefault<word>("agglomerator", "faceAreaPair")
);
const_cast<Time&>(mesh.thisDb().time()).libs().open
mesh.thisDb().time().libs().open
(
controlDict,
"geometricGAMGAgglomerationLibs",
......
......@@ -58,7 +58,7 @@ Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New(const IOobject& io)
Info<< "Selecting dynamicFvMesh " << modelType << endl;
const_cast<Time&>(io.time()).libs().open
io.time().libs().open
(
dict,
"dynamicFvMeshLibs",
......
......@@ -89,7 +89,7 @@ void Foam::codedPoints0MotionSolver::prepare
Foam::dlLibraryTable& Foam::codedPoints0MotionSolver::libs() const
{
return const_cast<Time&>(mesh().time()).libs();
return mesh().time().libs();
}
......
......@@ -103,7 +103,7 @@ protected:
// Protected Member Functions
//- Get the loaded dynamic libraries
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
......
......@@ -94,7 +94,7 @@ Foam::displacementMotionSolver::New
{
Info<< "Selecting motion solver: " << solverTypeName << endl;
const_cast<Time&>(mesh.time()).libs().open
mesh.time().libs().open
(
solverDict,
"motionSolverLibs",
......
......@@ -116,7 +116,7 @@ Foam::autoPtr<Foam::motionSolver> Foam::motionSolver::New
Info<< "Selecting motion solver: " << solverName << nl;
const_cast<Time&>(mesh.time()).libs().open
mesh.time().libs().open
(
solverDict,
"motionSolverLibs",
......
......@@ -79,7 +79,7 @@ Foam::autoPtr<Foam::fv::option> Foam::fv::option::New
Info<< indent
<< "Selecting finite volume options type " << modelType << endl;
const_cast<Time&>(mesh.time()).libs().open
mesh.time().libs().open
(
coeffs,
"libs",
......
......@@ -112,7 +112,6 @@ Foam::expressions::fvExprDriver::fvExprDriver
storedVariables_(),
specialVariablesIndex_(-1),
otherMeshName_(),
libs_(),
writer_(nullptr)
{}
......@@ -128,7 +127,6 @@ Foam::expressions::fvExprDriver::fvExprDriver
storedVariables_(rhs.storedVariables_),
specialVariablesIndex_(rhs.specialVariablesIndex_),
otherMeshName_(),
libs_(),
writer_(nullptr)
{}
......@@ -165,12 +163,15 @@ bool Foam::expressions::fvExprDriver::readDict
{
expressions::exprDriver::readDict(dict);
// wordList plugins;
// fileNameList plugins;
// if (dict.readIfPresent("functionPlugins", plugins))
// {
// for (const word& plugin : plugins)
// for (const fileName& libName : plugins)
// {
// libs_.open("libswak" + plugin + "FunctionPlugin.so");
// this->runTime().libs().open
// (
// "libswak" + libName + "FunctionPlugin" // verbose = true
// );
// }
// }
......
......@@ -69,7 +69,6 @@ SourceFiles
#include "pointMesh.H"
#include "volFields.H"
#include "topoSetSource.H"
#include "dlLibraryTable.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -118,9 +117,6 @@ class fvExprDriver
//- The name of the other mesh (if it is to be required)
word otherMeshName_;
//- Additional libraries
dlLibraryTable libs_;
//- Writing and restoring
autoPtr<exprDriverWriter> writer_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment