Loading...
Searching...
No Matches
typeInfo.H File Reference

Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to cover I/O. More...

Include dependency graph for typeInfo.H:

Go to the source code of this file.

Classes

struct  isAOp< Type >
 Test if dynamic_cast to Type is possible, as a functor. More...
struct  isTypeOp< Type >
 Test if typeid is identical to the Type, as a functor. More...

Namespaces

namespace  Foam
 Namespace for OpenFOAM.

Macros

#define TypeNameNoDebug(TypeNameString)
 Declare a ClassNameNoDebug() with extra virtual type info.
#define TypeName(TypeNameString)
 Declare a ClassName() with extra virtual type info.

Functions

template<class Type, class U>
const Type * isA (const U &obj)
 Attempt dynamic_cast to Type.
template<class Type, class U>
Type * isA_constCast (const U &obj)
 Attempt dynamic_cast to Type followed by a const_cast of the result.
template<class Type, class U>
bool isType (const U &obj)
 Check if typeid of the object and Type are identical.
template<class Type, class U>
Type & dynamicCast (U &obj)
 A dynamic_cast (for references) that generates FatalError on failed casts.
template<class Type, class U>
Type & dynamicCast (U &obj, const dictionary &dict)
 A dynamic_cast (for references) that generates FatalIOError on failed casts.
template<class Type, class U>
Type & refCast (U &obj)
 A dynamic_cast (for references) to Type reference.
template<class Type, class U>
Type & refConstCast (const U &obj)
 A dynamic_cast (for const references) to Type reference, followed by a const_cast of the result.
template<class Type, class U>
Type & refCast (U &obj, const dictionary &dict)
 A dynamic_cast (for references) that generates FatalIOError on failed casts, uses the virtual type() method for error messages.
template<class Type, class U>
Type & refCast (U &obj, const label index)
 A dynamic_cast (for references) that generates FatalError on failed casts, uses the virtual type() method for error messages. The index can be used to convey additional context.

Detailed Description

Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to cover I/O.

Original source file typeInfo.H

The user can get the type's type name using the type info access function

type()

The isA functions:

isA<Type>(obj)
isA_constCast<Type>(obj)

which return const or non-const pointers to the cast object, nullptr if cast is not possible (can be tested as a bool).

The reference type cast template function:

refCast<Type>(obj)
refConstCast<Type>(obj)

wraps dynamic_cast to handle failed casts and generate a FatalError.

Definition in file typeInfo.H.

Macro Definition Documentation

◆ TypeNameNoDebug

#define TypeNameNoDebug ( TypeNameString)
Value:
ClassNameNoDebug(TypeNameString); \
virtual const word& type() const { return typeName; }
#define ClassNameNoDebug(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:39

Declare a ClassNameNoDebug() with extra virtual type info.

Definition at line 61 of file typeInfo.H.

◆ TypeName

#define TypeName ( TypeNameString)
Value:
ClassName(TypeNameString); \
virtual const word& type() const { return typeName; }
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74

Declare a ClassName() with extra virtual type info.

Definition at line 68 of file typeInfo.H.