ENH: added FatalErrorInLookup, FatalIOErrorInLookup macros (#1362)

- to simplify/unify error handling

STYLE: use NotImplemented instead of longer notImplemented(...)
This commit is contained in:
Mark Olesen
2019-07-12 18:00:00 +02:00
committed by Andrew Heather
parent bbc2d4a8b0
commit ba3f0734c0
7 changed files with 32 additions and 23 deletions

View File

@ -524,7 +524,7 @@ public:
//- Return the name of the thermo physics //- Return the name of the thermo physics
virtual word thermoName() const virtual word thermoName() const
{ {
NotImplemented NotImplemented;
return word(); return word();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -353,6 +353,14 @@ extern IOerror FatalIOError;
// for FUNCTION_NAME in file __FILE__ at line __LINE__ // for FUNCTION_NAME in file __FILE__ at line __LINE__
#define FatalErrorInFunction FatalErrorIn(FUNCTION_NAME) #define FatalErrorInFunction FatalErrorIn(FUNCTION_NAME)
//- Report an error message using Foam::FatalError
// about unknown lookup type in table
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable) \
::Foam::FatalError(FUNCTION_NAME, __FILE__, __LINE__) \
<< "Unknown " << (lookupTag) << " type " << (lookupName) \
<< "\n\nValid " << (lookupTag) << " types :\n" \
<< ((lookupTable).sortedToc()) << '\n'
//- Report an error message using Foam::FatalIOError //- Report an error message using Foam::FatalIOError
// for functionName in file __FILE__ at line __LINE__ // for functionName in file __FILE__ at line __LINE__
@ -366,6 +374,15 @@ extern IOerror FatalIOError;
#define FatalIOErrorInFunction(ios) FatalIOErrorIn(FUNCTION_NAME, ios) #define FatalIOErrorInFunction(ios) FatalIOErrorIn(FUNCTION_NAME, ios)
//- Report an error message using Foam::FatalIOError
// about unknown lookup type in table
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable) \
::Foam::FatalIOError(FUNCTION_NAME, __FILE__, __LINE__, (ios)) \
<< "Unknown " << (lookupTag) << " type " << (lookupName) \
<< "\n\nValid " << (lookupTag) << " types :\n" \
<< ((lookupTable).sortedToc()) << '\n'
//- Report an error message using Foam::FatalIOError //- Report an error message using Foam::FatalIOError
// (or cerr if FatalIOError not yet constructed) // (or cerr if FatalIOError not yet constructed)
// for functionName in file __FILE__ at line __LINE__ // for functionName in file __FILE__ at line __LINE__

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2016-2017 Wikki Ltd | Copyright (C) 2016-2017 Wikki Ltd
@ -366,7 +366,7 @@ public:
//- Return patchField on the opposite patch of a coupled patch //- Return patchField on the opposite patch of a coupled patch
virtual tmp<Field<Type>> patchNeighbourField() const virtual tmp<Field<Type>> patchNeighbourField() const
{ {
notImplemented(type() + "patchNeighbourField()"); NotImplemented;
return *this; return *this;
} }
@ -393,11 +393,7 @@ public:
const tmp<Field<scalar>>& const tmp<Field<scalar>>&
) const ) const
{ {
notImplemented NotImplemented;
(
type()
+ "::valueInternalCoeffs(const tmp<Field<scalar>>&)"
);
return *this; return *this;
} }
@ -408,11 +404,7 @@ public:
const tmp<Field<scalar>>& const tmp<Field<scalar>>&
) const ) const
{ {
notImplemented NotImplemented;
(
type()
+ "::valueBoundaryCoeffs(const tmp<Field<scalar>>&)"
);
return *this; return *this;
} }
@ -420,7 +412,7 @@ public:
// evaluation of the gradient of this patchField // evaluation of the gradient of this patchField
virtual tmp<Field<Type>> gradientInternalCoeffs() const virtual tmp<Field<Type>> gradientInternalCoeffs() const
{ {
notImplemented(type() + "::gradientInternalCoeffs()"); NotImplemented;
return *this; return *this;
} }
@ -428,7 +420,7 @@ public:
// evaluation of the gradient of this patchField // evaluation of the gradient of this patchField
virtual tmp<Field<Type>> gradientBoundaryCoeffs() const virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
{ {
notImplemented(type() + "::gradientBoundaryCoeffs()"); NotImplemented;
return *this; return *this;
} }

View File

@ -79,8 +79,8 @@ public:
//- Return clone //- Return clone
autoPtr<optionAdjoint> clone() const autoPtr<optionAdjoint> clone() const
{ {
notImplemented("autoPtr<optionAdjoint> clone() const"); NotImplemented;
return autoPtr<optionAdjoint>(nullptr); return nullptr;
} }

View File

@ -99,8 +99,8 @@ Foam::diameterModels::sizeGroup::~sizeGroup()
Foam::autoPtr<Foam::diameterModels::sizeGroup> Foam::autoPtr<Foam::diameterModels::sizeGroup>
Foam::diameterModels::sizeGroup::clone() const Foam::diameterModels::sizeGroup::clone() const
{ {
notImplemented("sizeGroup::clone() const"); NotImplemented;
return autoPtr<sizeGroup>(nullptr); return nullptr;
} }

View File

@ -120,7 +120,7 @@ public:
autoPtr<breakupModel> clone() const autoPtr<breakupModel> clone() const
{ {
NotImplemented; NotImplemented;
return autoPtr<breakupModel>(nullptr); return nullptr;
} }

View File

@ -1143,8 +1143,8 @@ Foam::diameterModels::populationBalanceModel::~populationBalanceModel()
Foam::autoPtr<Foam::diameterModels::populationBalanceModel> Foam::autoPtr<Foam::diameterModels::populationBalanceModel>
Foam::diameterModels::populationBalanceModel::clone() const Foam::diameterModels::populationBalanceModel::clone() const
{ {
notImplemented("populationBalance::clone() const"); NotImplemented;
return autoPtr<populationBalanceModel>(nullptr); return nullptr;
} }