Commit f084309b authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add refCast variant with an index to convey the context

- can be helpful, for example, when the refCast has been used on a
  boundary patch. Knowing which patch index triggered the problem
  helps with isolating the issue.
parent 55776069
...@@ -145,6 +145,30 @@ inline To& refCast(From& r) ...@@ -145,6 +145,30 @@ inline To& refCast(From& r)
} }
//- Reference type cast template function.
// As per dynamicCast, but handles type names for the error messages
// via the virtual type() method.
// Can use index to convey the context.
template<class To, class From>
inline To& refCast(From& r, const label index)
{
try
{
return dynamic_cast<To&>(r);
}
catch (const std::bad_cast&)
{
FatalErrorInFunction
<< "Attempt to cast type " << r.type()
<< " to type " << To::typeName
<< " at index " << index
<< abort(FatalError);
return dynamic_cast<To&>(r);
}
}
//- Reference type cast template function. //- Reference type cast template function.
// As per dynamicCast, but handles type names for the error messages // As per dynamicCast, but handles type names for the error messages
// via the virtual type() method. // via the virtual type() method.
......
...@@ -188,7 +188,8 @@ Foam::nutWallFunctionFvPatchScalarField::nutw ...@@ -188,7 +188,8 @@ Foam::nutWallFunctionFvPatchScalarField::nutw
return return
refCast<const nutWallFunctionFvPatchScalarField> refCast<const nutWallFunctionFvPatchScalarField>
( (
turbModel.nut()().boundaryField()[patchi] turbModel.nut()().boundaryField()[patchi],
patchi
); );
} }
......
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