STYLE: noexcept for nullObject functions

STYLE: use nullObject for return values of NotImplemented

STYLE: shallowCopy(nullptr) shortcut
This commit is contained in:
Mark Olesen
2024-01-25 10:02:52 +01:00
parent 0bf39691ff
commit 182afc27ba
54 changed files with 170 additions and 224 deletions

View File

@ -135,14 +135,14 @@ public:
virtual volScalarField& he() virtual volScalarField& he()
{ {
NotImplemented; NotImplemented;
return thermo1_->he(); return const_cast<volScalarField&>(volScalarField::null());
} }
//- Enthalpy/Internal energy [J/kg] //- Enthalpy/Internal energy [J/kg]
virtual const volScalarField& he() const virtual const volScalarField& he() const
{ {
NotImplemented; NotImplemented;
return thermo1_->he(); return volScalarField::null();
} }
//- Enthalpy/Internal energy //- Enthalpy/Internal energy
@ -213,7 +213,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Heat capacity at constant volume [J/kg/K] //- Heat capacity at constant volume [J/kg/K]
@ -236,7 +236,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Gamma = Cp/Cv [] //- Gamma = Cp/Cv []

View File

@ -243,14 +243,14 @@ public:
virtual volScalarField& he() virtual volScalarField& he()
{ {
NotImplemented; NotImplemented;
return phases_[0].thermo().he(); return const_cast<volScalarField&>(volScalarField::null());
} }
//- Enthalpy/Internal energy [J/kg] //- Enthalpy/Internal energy [J/kg]
virtual const volScalarField& he() const virtual const volScalarField& he() const
{ {
NotImplemented; NotImplemented;
return phases_[0].thermo().he(); return volScalarField::null();
} }
//- Enthalpy/Internal energy //- Enthalpy/Internal energy
@ -327,7 +327,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Heat capacity at constant volume [J/kg/K] //- Heat capacity at constant volume [J/kg/K]
@ -350,7 +350,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Gamma = Cp/Cv [] //- Gamma = Cp/Cv []

View File

@ -86,14 +86,14 @@ public:
virtual volScalarField& he() virtual volScalarField& he()
{ {
NotImplemented; NotImplemented;
return p(); return const_cast<volScalarField&>(volScalarField::null());
} }
//- Return access to the internal energy field [J/Kg] //- Return access to the internal energy field [J/Kg]
virtual const volScalarField& he() const virtual const volScalarField& he() const
{ {
NotImplemented; NotImplemented;
return p(); return volScalarField::null();
} }
//- Enthalpy/Internal energy //- Enthalpy/Internal energy
@ -182,7 +182,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Return Cv of the mixture //- Return Cv of the mixture
@ -205,7 +205,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Gamma = Cp/Cv [] //- Gamma = Cp/Cv []

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -48,7 +48,7 @@ class SimpleClass
public: public:
//- Default construct //- Default construct
SimpleClass() {} SimpleClass() = default;
}; };
@ -73,9 +73,8 @@ void printInfo(const UList<T>& list)
int main() int main()
{ {
// Test pointer and reference to a class // Test pointer and reference to a class
auto ptrToClass = autoPtr<SimpleClass>::New();
SimpleClass* ptrToClass = new SimpleClass; auto& refToClass = ptrToClass.ref();
SimpleClass& refToClass(*ptrToClass);
std::cout std::cout
<< "nullObject addr=" << name(&(nullObjectPtr)) << nl << "nullObject addr=" << name(&(nullObjectPtr)) << nl
@ -89,13 +88,13 @@ int main()
<< " pointer:" << name(nullObjectPtr->pointer()) << nl << " pointer:" << name(nullObjectPtr->pointer()) << nl
<< " value:" << nullObjectPtr->value() << nl << nl; << " value:" << nullObjectPtr->value() << nl << nl;
if (notNull(ptrToClass)) if (notNull(ptrToClass.get()))
{ {
Info<< "Pass: ptrToClass is not null" << nl; Info<< "Pass: ptrToClass is not null" << nl;
} }
else else
{ {
Info<< "FAIL: refToClass is null" << nl; Info<< "FAIL: ptrToClass is null" << nl;
} }
if (notNull(refToClass)) if (notNull(refToClass))
@ -110,8 +109,8 @@ int main()
// Test pointer and reference to the nullObject // Test pointer and reference to the nullObject
const SimpleClass* ptrToNull(NullObjectPtr<SimpleClass>()); const SimpleClass* ptrToNull = NullObjectPtr<SimpleClass>();
const SimpleClass& refToNull(*ptrToNull); const SimpleClass& refToNull = (*ptrToNull);
if (isNull(ptrToNull)) if (isNull(ptrToNull))
{ {
@ -131,9 +130,6 @@ int main()
Info<< "FAIL: refToNull is not null" << nl; Info<< "FAIL: refToNull is not null" << nl;
} }
// Clean-up
delete ptrToClass;
// Test List casting // Test List casting
{ {
@ -152,7 +148,7 @@ int main()
// Looks pretty ugly though! // Looks pretty ugly though!
NullObject::nullObject = "hello world"; NullObject::nullObject = "hello world";
NullObject::nullObject = labelList({1, 2, 3}); NullObject::nullObject = Foam::identity(5);
Info<< nl; Info<< nl;

View File

@ -120,8 +120,11 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null bitSet reference //- Return a null bitSet (reference to a nullObject).
inline static const bitSet& null(); static const bitSet& null() noexcept
{
return NullObjectRef<bitSet>();
}
//- Declare type-name (with debug switch) //- Declare type-name (with debug switch)

View File

@ -405,12 +405,6 @@ inline Foam::label Foam::bitSet::find_next(label pos) const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::bitSet& Foam::bitSet::null()
{
return NullObjectRef<bitSet>();
}
inline bool Foam::bitSet::all() const inline bool Foam::bitSet::all() const
{ {
if (empty()) return true; // SIC. boost convention if (empty()) return true; // SIC. boost convention

View File

@ -138,8 +138,11 @@ public:
// Static Member Functions // Static Member Functions
//- Return a CompactListList reference to a nullObject //- Return a null CompactListList (reference to a nullObject).
inline static const CompactListList<T>& null(); static const CompactListList<T>& null() noexcept
{
return NullObjectRef<CompactListList<T>>();
}
//- Construct by packing together the list of lists //- Construct by packing together the list of lists
template<class SubListType = List<T>> template<class SubListType = List<T>>

View File

@ -29,15 +29,6 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "SubList.H" #include "SubList.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
{
return NullObjectRef<CompactListList<T>>();
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class T> template<class T>

View File

@ -46,9 +46,10 @@ SourceFiles
#include "zero.H" #include "zero.H"
#include "contiguous.H" #include "contiguous.H"
#include "stdFoam.H" #include "stdFoam.H"
#include "autoPtr.H" #include "nullObject.H"
#include "Hash.H" #include "Hash.H"
#include "ListPolicy.H" #include "ListPolicy.H"
#include "autoPtr.H"
// <algorithm> already included by stdFoam.H // <algorithm> already included by stdFoam.H
#include <iterator> #include <iterator>
@ -139,8 +140,12 @@ public:
// Static Functions // Static Functions
//- Return a null FixedList //- Return a null FixedList (reference to a nullObject).
inline static const FixedList<T, N>& null(); //- Read/write access is questionable
static const FixedList<T, N>& null() noexcept
{
return NullObjectRef<FixedList<T, N>>();
}
// Constructors // Constructors

View File

@ -28,15 +28,6 @@ License
#include "UList.H" #include "UList.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T, unsigned N>
inline const Foam::FixedList<T, N>& Foam::FixedList<T, N>::null()
{
return NullObjectRef<FixedList<T, N>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, unsigned N> template<class T, unsigned N>

View File

@ -129,8 +129,12 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null List //- Return a null List (reference to a nullObject).
inline static const List<T>& null(); //- Behaves like an empty List.
static const List<T>& null() noexcept
{
return NullObjectRef<List<T>>();
}
// Constructors // Constructors

View File

@ -133,13 +133,6 @@ inline Foam::autoPtr<Foam::List<T>> Foam::List<T>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::List<T>& Foam::List<T>::null()
{
return NullObjectRef<List<T>>();
}
template<class T> template<class T>
inline void Foam::List<T>::clear() inline void Foam::List<T>::clear()
{ {

View File

@ -73,8 +73,12 @@ public:
// Static Functions // Static Functions
//- Return a null SubList //- Return a null SubList (reference to a nullObject).
inline static const SubList<T>& null(); //- Behaves like an empty SubList.
static const SubList<T>& null() noexcept
{
return NullObjectRef<SubList<T>>();
}
// Generated Methods // Generated Methods

View File

@ -28,15 +28,6 @@ License
#include "FixedList.H" #include "FixedList.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
inline const Foam::SubList<T>& Foam::SubList<T>::null()
{
return NullObjectRef<SubList<T>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
@ -124,7 +115,7 @@ inline Foam::SubList<T>::SubList
template<class T> template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept
{ {
UList<T>::shallowCopy(nullptr, 0); UList<T>::shallowCopy(nullptr);
return *this; return *this;
} }

View File

@ -183,8 +183,12 @@ public:
// Static Functions // Static Functions
//- Return a UList reference to a nullObject //- Return a null UList (reference to a nullObject).
inline static const UList<T>& null(); //- Behaves like an empty UList.
static const UList<T>& null() noexcept
{
return NullObjectRef<UList<T>>();
}
// Public Classes // Public Classes
@ -367,6 +371,9 @@ public:
//- Copy the pointer and size //- Copy the pointer and size
inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept; inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
//- Copy nullptr and zero size
inline void shallowCopy(std::nullptr_t) noexcept;
//- Copy the pointer and size held by the given UList //- Copy the pointer and size held by the given UList
inline void shallowCopy(const UList<T>& list) noexcept; inline void shallowCopy(const UList<T>& list) noexcept;

View File

@ -93,13 +93,6 @@ inline void Foam::UList<T>::fill_uniform(const Foam::zero)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::UList<T>& Foam::UList<T>::null()
{
return NullObjectRef<UList<T>>();
}
template<class T> template<class T>
inline Foam::label Foam::UList<T>::fcIndex(const label i) const noexcept inline Foam::label Foam::UList<T>::fcIndex(const label i) const noexcept
{ {
@ -330,6 +323,14 @@ inline void Foam::UList<T>::shallowCopy
} }
template<class T>
inline void Foam::UList<T>::shallowCopy(std::nullptr_t) noexcept
{
size_ = 0;
v_ = nullptr;
}
template<class T> template<class T>
inline void Foam::UList<T>::shallowCopy(const UList<T>& list) noexcept inline void Foam::UList<T>::shallowCopy(const UList<T>& list) noexcept
{ {

View File

@ -116,7 +116,7 @@ Foam::labelListList Foam::invertOneToMany
const labelUList& map const labelUList& map
) )
{ {
labelList sizes(len, Zero); labelList sizes(len, Foam::zero{});
for (const label newIdx : map) for (const label newIdx : map)
{ {

View File

@ -707,7 +707,7 @@ void Foam::invertManyToMany
) )
{ {
// The output list sizes // The output list sizes
labelList sizes(len, Zero); labelList sizes(len, Foam::zero{});
for (const InputIntListType& sublist : input) for (const InputIntListType& sublist : input)
{ {

View File

@ -115,7 +115,7 @@ Type Foam::Function1Types::Function1Expression<Type>::integrate
) const ) const
{ {
NotImplemented; NotImplemented;
return Zero; return Type();
} }

View File

@ -137,8 +137,11 @@ public:
// Static Member Functions // Static Member Functions
//- Return a NullObjectRef DimensionedField //- Return a null DimensionedField (reference to a nullObject).
inline static const DimensionedField<Type, GeoMesh>& null(); static const DimensionedField<Type, GeoMesh>& null() noexcept
{
return NullObjectRef<DimensionedField<Type, GeoMesh>>();
}
// Constructors // Constructors

View File

@ -28,14 +28,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
inline const Foam::DimensionedField<Type, GeoMesh>&
Foam::DimensionedField<Type, GeoMesh>::null()
{
return NullObjectRef<DimensionedField<Type, GeoMesh>>();
}
template<class Type, class GeoMesh> template<class Type, class GeoMesh>
inline const typename GeoMesh::Mesh& inline const typename GeoMesh::Mesh&
Foam::DimensionedField<Type, GeoMesh>::mesh() const noexcept Foam::DimensionedField<Type, GeoMesh>::mesh() const noexcept

View File

@ -85,7 +85,7 @@ public:
~SlicedDimensionedField() ~SlicedDimensionedField()
{ {
// Set internalField to nullptr to avoid deletion of underlying field // Set internalField to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }
}; };

View File

@ -97,8 +97,8 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null field //- Return a null DynamicField (reference to a nullObject).
inline static const DynamicField<T, SizeMin>& null() static const DynamicField<T, SizeMin>& null() noexcept
{ {
return NullObjectRef<DynamicField<T, SizeMin>>(); return NullObjectRef<DynamicField<T, SizeMin>>();
} }

View File

@ -122,8 +122,12 @@ public:
// Static Member Functions // Static Member Functions
//- Return nullObject reference Field //- Return a null Field (reference to a nullObject).
inline static const Field<Type>& null(); //- Behaves like an empty Field.
static const Field<Type>& null() noexcept
{
return NullObjectRef<Field<Type>>();
}
// Constructors // Constructors

View File

@ -25,15 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
inline const Foam::Field<Type>& Foam::Field<Type>::null()
{
return NullObjectRef<Field<Type>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

@ -69,8 +69,12 @@ public:
// Static Member Functions // Static Member Functions
//- Return nullObject reference SubField //- Return a null SubField (reference to a nullObject).
inline static const SubField<Type>& null(); //- Behaves like an empty SubField.
static const SubField<Type>& null() noexcept
{
return NullObjectRef<SubField<Type>>();
}
// Constructors // Constructors

View File

@ -26,15 +26,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
inline const Foam::SubField<Type>& Foam::SubField<Type>::null()
{
return NullObjectRef<SubField<Type>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

@ -154,8 +154,11 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null geometric field //- Return a null GeometricField (reference to a nullObject).
inline static const GeometricField<Type, PatchField, GeoMesh>& null(); static const GeometricField<Type, PatchField, GeoMesh>& null() noexcept
{
return NullObjectRef<GeometricField<Type, PatchField, GeoMesh>>();
}
// Constructors // Constructors

View File

@ -28,14 +28,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
inline const Foam::GeometricField<Type, PatchField, GeoMesh>&
Foam::GeometricField<Type, PatchField, GeoMesh>::null()
{
return NullObjectRef<GeometricField<Type, PatchField, GeoMesh>>();
}
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
inline const typename inline const typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Internal& Foam::GeometricField<Type, PatchField, GeoMesh>::Internal&

View File

@ -368,7 +368,7 @@ Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
~SlicedGeometricField() ~SlicedGeometricField()
{ {
// Set internalField to nullptr to avoid deletion of underlying field // Set internalField to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }

View File

@ -114,8 +114,12 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null Matrix //- Return a null Matrix (reference to a nullObject).
inline static const Matrix<Form, Type>& null(); //- Behaves like a empty Matrix.
static const Matrix<Form, Type>& null() noexcept
{
return NullObjectRef<Matrix<Form, Type>>();
}
// Iterators // Iterators

View File

@ -85,13 +85,6 @@ Foam::Matrix<Form, Type>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Form, class Type>
inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
{
return NullObjectRef<Matrix<Form, Type>>();
}
template<class Form, class Type> template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::size() const inline Foam::label Foam::Matrix<Form, Type>::size() const
{ {

View File

@ -102,7 +102,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return autoPtr<GAMGInterfaceField>(nullptr); return nullptr;
} }

View File

@ -42,8 +42,7 @@ namespace Foam
const Foam::objectRegistry& Foam::lduMesh::thisDb() const const Foam::objectRegistry& Foam::lduMesh::thisDb() const
{ {
NotImplemented; NotImplemented;
const objectRegistry* orPtr_ = nullptr; return NullObjectRef<objectRegistry>();
return *orPtr_;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -158,7 +158,7 @@ extern const NullObject* nullObjectPtr;
// IOstream Operators // IOstream Operators
//- Read from Istream consumes no content //- Read from Istream consumes no content, does not change NullObject
inline Istream& operator>>(Istream& is, const NullObject&) noexcept inline Istream& operator>>(Istream& is, const NullObject&) noexcept
{ {
return is; return is;
@ -173,31 +173,48 @@ inline Ostream& operator<<(Ostream& os, const NullObject&) noexcept
// Global Functions // Global Functions
//- Pointer (of type T) to the nullObject //- Const pointer (of type T) to the nullObject
template<class T> template<class T>
inline const T* NullObjectPtr() inline const T* NullObjectPtr() noexcept
{ {
return reinterpret_cast<const T*>(nullObjectPtr); return reinterpret_cast<const T*>(nullObjectPtr);
} }
//- Reference (of type T) to the nullObject //- Non-const pointer (of type T) to the nullObject.
//- Only use when nothing will be written into it!
template<class T> template<class T>
inline const T& NullObjectRef() inline T* NullObjectPtr_constCast() noexcept
{
return reinterpret_cast<T*>(const_cast<NullObject*>(nullObjectPtr));
}
//- Const reference (of type T) to the nullObject
template<class T>
inline const T& NullObjectRef() noexcept
{ {
return *reinterpret_cast<const T*>(nullObjectPtr); return *reinterpret_cast<const T*>(nullObjectPtr);
} }
//- Non-const reference (of type T) to the nullObject
//- Only use when nothing will be written into it!
template<class T>
inline T& NullObjectRef_constCast() noexcept
{
return *reinterpret_cast<T*>(const_cast<NullObject*>(nullObjectPtr));
}
//- True if ptr is a pointer (of type T) to the nullObject //- True if ptr is a pointer (of type T) to the nullObject
template<class T> template<class T>
inline bool isNull(const T* ptr) inline bool isNull(const T* ptr) noexcept
{ {
return ptr == NullObjectPtr<T>(); return ptr == NullObjectPtr<T>();
} }
//- True if obj is a reference (of type T) to the nullObject //- True if obj is a reference (of type T) to the nullObject
template<class T> template<class T>
inline bool isNull(const T& obj) inline bool isNull(const T& obj) noexcept
{ {
return &obj == NullObjectPtr<T>(); return &obj == NullObjectPtr<T>();
} }
@ -205,14 +222,14 @@ inline bool isNull(const T& obj)
//- True if ptr is not a pointer (of type T) to the nullObject //- True if ptr is not a pointer (of type T) to the nullObject
template<class T> template<class T>
inline bool notNull(const T* ptr) inline bool notNull(const T* ptr) noexcept
{ {
return ptr != NullObjectPtr<T>(); return ptr != NullObjectPtr<T>();
} }
//- True if obj is not a reference (of type T) to the nullObject //- True if obj is not a reference (of type T) to the nullObject
template<class T> template<class T>
inline bool notNull(const T& obj) inline bool notNull(const T& obj) noexcept
{ {
return &obj != NullObjectPtr<T>(); return &obj != NullObjectPtr<T>();
} }

View File

@ -86,8 +86,12 @@ public:
// Static Data / Methods // Static Data / Methods
//- Return a null wordRes - a reference to the NullObject //- Return a null wordRes (reference to a nullObject).
inline static const wordRes& null(); //- Behaves like a empty wordRes.
static const wordRes& null() noexcept
{
return NullObjectRef<wordRes>();
}
//- Return a wordRes with duplicate entries filtered out. //- Return a wordRes with duplicate entries filtered out.
// No distinction made between literals and regular expressions. // No distinction made between literals and regular expressions.

View File

@ -27,12 +27,6 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline const Foam::wordRes& Foam::wordRes::null()
{
return NullObjectRef<wordRes>();
}
inline Foam::label Foam::wordRes::first_match inline Foam::label Foam::wordRes::first_match
( (
const UList<wordRe>& selectors, const UList<wordRe>& selectors,

View File

@ -92,7 +92,7 @@ public:
// Static Functions // Static Functions
//- Return a null ensightFile //- Return a null ensightFile
static const ensightFile& null() static const ensightFile& null() noexcept
{ {
return NullObjectRef<ensightFile>(); return NullObjectRef<ensightFile>();
} }

View File

@ -72,7 +72,7 @@ public:
// Static Functions // Static Functions
//- Return a null ensightGeoFile //- Return a null ensightGeoFile
static const ensightGeoFile& null() static const ensightGeoFile& null() noexcept
{ {
return NullObjectRef<ensightGeoFile>(); return NullObjectRef<ensightGeoFile>();
} }

View File

@ -127,7 +127,7 @@ template<class Type>
Foam::slicedFaPatchField<Type>::~slicedFaPatchField() Foam::slicedFaPatchField<Type>::~slicedFaPatchField()
{ {
// Set to nullptr to avoid deletion of underlying field // Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }

View File

@ -127,7 +127,7 @@ template<class Type>
Foam::slicedFaePatchField<Type>::~slicedFaePatchField() Foam::slicedFaePatchField<Type>::~slicedFaePatchField()
{ {
// Set to nullptr to avoid deletion of underlying field // Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }

View File

@ -127,7 +127,7 @@ template<class Type>
Foam::slicedFvPatchField<Type>::~slicedFvPatchField() Foam::slicedFvPatchField<Type>::~slicedFvPatchField()
{ {
// Set to nullptr to avoid deletion of underlying field // Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }

View File

@ -127,7 +127,7 @@ template<class Type>
Foam::slicedFvsPatchField<Type>::~slicedFvsPatchField() Foam::slicedFvsPatchField<Type>::~slicedFvsPatchField()
{ {
// Set to nullptr to avoid deletion of underlying field // Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>()); UList<Type>::shallowCopy(nullptr);
} }

View File

@ -96,11 +96,7 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> ddtScheme<Type>::fvcDdt
) )
{ {
NotImplemented; NotImplemented;
return nullptr;
return tmp<GeometricField<Type, fvPatchField, volMesh>>
(
GeometricField<Type, fvPatchField, volMesh>::null()
);
} }
@ -113,13 +109,7 @@ tmp<fvMatrix<Type>> ddtScheme<Type>::fvmDdt
) )
{ {
NotImplemented; NotImplemented;
return nullptr;
return tmp<fvMatrix<Type>>::New
(
vf,
alpha.dimensions()*rho.dimensions()
*vf.dimensions()*dimVol/dimTime
);
} }
@ -130,15 +120,10 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> ddtScheme<Type>::fvcDdt
) )
{ {
NotImplemented; NotImplemented;
return nullptr;
return tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
(
GeometricField<Type, fvsPatchField, surfaceMesh>::null()
);
} }
template<class Type> template<class Type>
tmp<surfaceScalarField> ddtScheme<Type>::fvcDdtPhiCoeff tmp<surfaceScalarField> ddtScheme<Type>::fvcDdtPhiCoeff
( (

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2023 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -894,13 +894,13 @@ void Foam::fvMatrix<Type>::transferFvMatrixCoeffs()
template<class Type> template<class Type>
Foam::lduPrimitiveMeshAssembly* Foam::fvMatrix<Type>::lduMeshPtr() Foam::lduPrimitiveMeshAssembly* Foam::fvMatrix<Type>::lduMeshPtr()
{ {
const lduPrimitiveMeshAssembly* lduAssemMeshPtr = return
psi_.mesh().thisDb().objectRegistry::template findObject (
psi_.mesh().thisDb().objectRegistry::template getObjectPtr
< <
lduPrimitiveMeshAssembly lduPrimitiveMeshAssembly
> (lduAssemblyName_); > (lduAssemblyName_)
);
return const_cast<lduPrimitiveMeshAssembly*>(lduAssemMeshPtr);
} }

View File

@ -106,12 +106,6 @@ bool Foam::PDRblock::checkMonotonic
} }
const Foam::PDRblock& Foam::PDRblock::null()
{
return NullObjectRef<PDRblock>();
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::PDRblock::addDefaultPatches() void Foam::PDRblock::addDefaultPatches()

View File

@ -429,8 +429,11 @@ public:
// Static Member Functions // Static Member Functions
//- Return a PDRblock reference to a nullObject //- Return a null PDRblock (reference to a nullObject).
static const PDRblock& null(); static const PDRblock& null() noexcept
{
return NullObjectRef<PDRblock>();
}
// Constructors // Constructors

View File

@ -144,7 +144,7 @@ tmp<fvPatchScalarField>
boundaryAdjointContribution::turbulentDiffusivity() const boundaryAdjointContribution::turbulentDiffusivity() const
{ {
NotImplemented; NotImplemented;
return tmp<fvPatchScalarField>(nullptr); return nullptr;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -133,7 +133,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return autoPtr<GAMGInterfaceField>(nullptr); return nullptr;
} }

View File

@ -105,7 +105,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return autoPtr<GAMGInterfaceField>(nullptr); return nullptr;
} }

View File

@ -367,7 +367,7 @@ public:
) const ) const
{ {
NotImplemented; NotImplemented;
return tmp<scalarField>::New(p); return nullptr;
} }
//- Return Cv of the mixture //- Return Cv of the mixture

View File

@ -88,7 +88,7 @@ Foam::PurePhaseModel<BasePhaseModel>::Y(const word& name) const
<< "Cannot get a species fraction by name from a pure phase" << "Cannot get a species fraction by name from a pure phase"
<< exit(FatalError); << exit(FatalError);
return NullObjectRef<volScalarField>(); return volScalarField::null();
} }

View File

@ -59,7 +59,7 @@ const Foam::DimensionedField<Foam::scalar, Foam::volMesh>&
Foam::basicSolidChemistryModel::RR(const label i) const Foam::basicSolidChemistryModel::RR(const label i) const
{ {
NotImplemented; NotImplemented;
return (volScalarField::Internal::null()); return volScalarField::Internal::null();
} }
@ -67,13 +67,10 @@ Foam::DimensionedField<Foam::scalar, Foam::volMesh>&
Foam::basicSolidChemistryModel::RR(const label i) Foam::basicSolidChemistryModel::RR(const label i)
{ {
NotImplemented; NotImplemented;
return
return dynamic_cast<volScalarField::Internal&>
(
const_cast<volScalarField::Internal&> const_cast<volScalarField::Internal&>
( (
volScalarField::Internal::null() volScalarField::Internal::null()
)
); );
} }
@ -86,14 +83,7 @@ Foam::basicSolidChemistryModel::calculateRR
) const ) const
{ {
NotImplemented; NotImplemented;
return nullptr;
return dynamic_cast<tmp<volScalarField::Internal>&>
(
const_cast<volScalarField::Internal&>
(
volScalarField::Internal::null()
)
);
} }

View File

@ -441,7 +441,7 @@ const Foam::List<typename Foam::Reaction<ReactionThermo>::specieCoeffs>&
Foam::Reaction<ReactionThermo>::glhs() const Foam::Reaction<ReactionThermo>::glhs() const
{ {
NotImplemented; NotImplemented;
return NullObjectRef<List<specieCoeffs>>(); return List<specieCoeffs>::null();
} }
@ -450,7 +450,7 @@ const Foam::List<typename Foam::Reaction<ReactionThermo>::specieCoeffs>&
Foam::Reaction<ReactionThermo>::grhs() const Foam::Reaction<ReactionThermo>::grhs() const
{ {
NotImplemented; NotImplemented;
return NullObjectRef<List<specieCoeffs>>(); return List<specieCoeffs>::null();
} }