typeGlobal, typeGlobalFile: Changed to trait structure

This allows for partial specialisation, so the different variants of the
global IO containers do not need the function to be overloaded for each
contained type. This also fixes an ommission in providing overloads of
these functions for some of the global IO containers.

Resolves bug report https://bugs.openfoam.org/view.php?id=3890
This commit is contained in:
Will Bainbridge
2022-09-20 16:32:29 +01:00
parent 8b557d128c
commit 50aac13df5
15 changed files with 82 additions and 64 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -196,14 +196,15 @@ int main(int argc, char *argv[])
if (dictIO.headerOk())
{
Info<< "Refining according to "
<< dictIO.path(typeGlobalFile<IOdictionary>()) << nl << endl;
<< dictIO.path(typeGlobalFile<IOdictionary>::global)
<< nl << endl;
refineDict = IOdictionary(dictIO);
}
else
{
FatalErrorInFunction
<< "Cannot open specified refinement dictionary "
<< dictIO.path(typeGlobalFile<IOdictionary>())
<< dictIO.path(typeGlobalFile<IOdictionary>::global)
<< exit(FatalError);
}
}
@ -212,14 +213,15 @@ int main(int argc, char *argv[])
if (dictIO.headerOk())
{
Info<< "Refining according to "
<< dictIO.path(typeGlobalFile<IOdictionary>()) << nl << endl;
<< dictIO.path(typeGlobalFile<IOdictionary>::global)
<< nl << endl;
refineDict = IOdictionary(dictIO);
}
else
{
Info<< "Refinement dictionary "
<< dictIO.path(typeGlobalFile<IOdictionary>()) << " not found"
<< nl << endl;
<< dictIO.path(typeGlobalFile<IOdictionary>::global)
<< " not found" << nl << endl;
}
}

View File

@ -500,19 +500,19 @@ public:
template<>
Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);
//- Template function for obtaining global status
//- Trait for obtaining global status
template<class Type>
inline bool typeGlobal()
struct typeGlobal
{
return false;
}
static const bool global = false;
};
//- Template function for obtaining global write status
//- Trait for obtaining global write status
template<class Type>
inline bool typeGlobalFile()
struct typeGlobalFile
{
return typeGlobal<Type>();
}
static const bool global = typeGlobal<Type>::global;
};
inline IOobject unregister(const IOobject& io)
{
@ -556,7 +556,7 @@ public:
//- Return the object path for this Type
inline fileName objectPath() const
{
return objectPath(typeGlobalFile<Type>());
return objectPath(typeGlobalFile<Type>::global);
}
using IOobject::filePath;
@ -564,7 +564,7 @@ public:
//- Return the path for the file for this Type
inline fileName filePath() const
{
return filePath(Type::typeName, typeGlobalFile<Type>());
return filePath(Type::typeName, typeGlobalFile<Type>::global);
}
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,7 +38,7 @@ bool Foam::IOobject::typeHeaderOk(const bool checkType)
// Everyone check or just master
const bool masterOnly =
typeGlobal<Type>()
typeGlobal<Type>::global
&& (
IOobject::fileModificationChecking == timeStampMaster
|| IOobject::fileModificationChecking == inotifyMaster
@ -51,7 +51,7 @@ bool Foam::IOobject::typeHeaderOk(const bool checkType)
{
const fileName fName
(
filePath(Type::typeName, typeGlobalFile<Type>())
filePath(Type::typeName, typeGlobalFile<Type>::global)
);
ok = fp.readHeader(*this, fName, Type::typeName);

View File

@ -69,6 +69,14 @@ public:
};
//- Trait for obtaining global status
template<class Type>
struct typeGlobal<GlobalIOField<Type>>
{
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -142,6 +142,14 @@ public:
};
//- Trait for obtaining global status
template<class Type>
struct typeGlobal<GlobalIOList<Type>>
{
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -124,12 +124,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<IOdictionary>()
struct typeGlobal<IOdictionary>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -79,12 +79,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<localIOdictionary>()
struct typeGlobal<localIOdictionary>
{
return false;
}
static const bool global = false;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -77,12 +77,12 @@ public:
};
//- Template function for obtaining global write status
//- Trait for obtaining global write status
template<>
inline bool typeGlobalFile<timeIOdictionary>()
struct typeGlobalFile<timeIOdictionary>
{
return false;
}
static const bool global = false;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -179,12 +179,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<fvConstraints>()
struct typeGlobal<fvConstraints>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -288,12 +288,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<fvModels>()
struct typeGlobal<fvModels>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -156,7 +156,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
inline bool typeGlobal
struct typeGlobal
<
MeshObject
<
@ -164,10 +164,10 @@ inline bool typeGlobal
GeometricMeshObject,
coordinateSystems::coordinateSystems
>
>()
>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -143,12 +143,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<extendedFeatureEdgeMesh>()
struct typeGlobal<extendedFeatureEdgeMesh>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -94,12 +94,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<featureEdgeMesh>()
struct typeGlobal<featureEdgeMesh>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -374,12 +374,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<triSurfaceMesh>()
struct typeGlobal<triSurfaceMesh>
{
return true;
}
static const bool global = true;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -469,12 +469,12 @@ public:
};
//- Template function for obtaining global status
//- Trait for obtaining global status
template<>
inline bool typeGlobal<distributedTriSurfaceMesh>()
struct typeGlobal<distributedTriSurfaceMesh>
{
return false;
}
static const bool global = false;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //