Files
OpenFOAM-12/src/OpenFOAM/primitives/nullObject/nullObject.H
Will Bainbridge c11a2415d2 typeInfo: Added dynamicCastNull and refCastNull
These functions dynamic cast a reference to a type, and return a null
object reference if the cast fails. The standard dynamicCast and refCast
functions, by contrast, throw an error if the cast fails.
2024-04-05 14:21:22 +01:00

132 lines
3.6 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2014-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::NullObject
Description
Singleton null-object class and instance
SourceFiles
nullObjectI.H
nullObject.C
\*---------------------------------------------------------------------------*/
#ifndef nullObject_H
#define nullObject_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class nullObject Declaration
\*---------------------------------------------------------------------------*/
class NullObject
{
//- Private constructor
NullObject()
{}
public:
//- The unique null object
static const NullObject nullObject;
//- Disallow default bitwise copy construction
NullObject(const NullObject&) = delete;
//- Disallow default bitwise assignment
void operator=(const NullObject&) = delete;
};
//- Pointer to the unique nullObject
extern const NullObject* nullObjectPtr;
//- Return const reference to the nullObject of type T
template<class T>
inline const T& NullObjectRef();
//- Return non-const reference to the nullObject of type T
template<class T>
inline T& NullObjectNonConstRef();
//- Return const pointer to the nullObject of type T
template<class T>
inline const T* NullObjectConstPtr();
//- Return pointer to the nullObject of type T
template<class T>
inline T* NullObjectPtr();
//- Return reference to the nullObject of type T
template<class T>
inline T&& NullObjectMove();
//- Return true if t is a reference to the nullObject of type T
template<class T>
inline bool isNull(const T& t);
//- Return true if t is not a reference to the nullObject of type T
template<class T>
inline bool notNull(const T& t);
//- Return true if t is a pointer to the nullObject of type T
template<class T>
inline bool isNull(const T* t);
//- Return true if t is not a pointer to the nullObject of type T
template<class T>
inline bool notNull(const T* t);
//- Return true if t is a pointer to the nullObject of type T
template<class T>
inline bool isNull(T* t);
//- Return true if t is not a pointer to the nullObject of type T
template<class T>
inline bool notNull(T* t);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "nullObjectI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //