58 #include <type_traits>
66 #define TypeNameNoDebug(TypeNameString) \
67 ClassNameNoDebug(TypeNameString); \
68 virtual const word& type() const { return typeName; } \
69 template<class Name> \
70 word typedName(Name name) const { return (type() + ':') + name; }
73 #define TypeName(TypeNameString) \
74 ClassName(TypeNameString); \
75 virtual const word& type() const { return typeName; } \
76 template<class Name> \
77 word typedName(Name name) const { return (type() + ':') + name; }
89 template<
class To,
class From>
94 return dynamic_cast<To&
>(r);
96 catch (
const std::bad_cast&)
99 <<
"Attempt to cast type " <<
typeid(r).
name()
100 <<
" to type " <<
typeid(To).
name()
103 return dynamic_cast<To&
>(r);
110 template<
class To,
class From>
115 return dynamic_cast<To&
>(r);
117 catch (
const std::bad_cast&)
120 <<
"Attempt to cast type " << r.type()
121 <<
" to type " << To::typeName
124 return dynamic_cast<To&
>(r);
130 template<
class TestType,
class Type>
133 return typeid(t) ==
typeid(TestType);
138 template<
class TestType,
class Type>
139 inline bool isA(
const Type& t)
141 const Type* tPtr = &t;
142 return dynamic_cast<const TestType*
>(tPtr);
148 template<
class TypeName,
class Name>
151 return (TypeName::typeName +
':') +
name;
157 constexpr
bool isRef = std::is_reference<Type>::value;
A class for handling words, derived from string.
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
To & refCast(From &r)
Reference type cast template function.
word name(const bool)
Return a word representation of a bool.
errorManip< error > abort(error &err)
bool isType(const Type &t)
Check the typeid.
To & dynamicCast(From &r)
Reference type cast template function,.
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
constexpr bool isRef
Determine whether a type is a reference.
word typedName(Name name)
Return the name of the object within the given type.