59 #include <type_traits>
67 #define TypeNameNoDebug(TypeNameString) \
68 ClassNameNoDebug(TypeNameString); \
69 virtual const word& type() const { return typeName; } \
70 template<class Name> \
71 word typedName(Name name) const { return (type() + ':') + name; }
74 #define TypeName(TypeNameString) \
75 ClassName(TypeNameString); \
76 virtual const word& type() const { return typeName; } \
77 template<class Name> \
78 word typedName(Name name) const { return (type() + ':') + name; }
90 template<
class To,
class From>
95 return dynamic_cast<To&
>(r);
97 catch (
const std::bad_cast&)
100 <<
"Attempt to cast type " <<
typeid(r).
name()
101 <<
" to type " <<
typeid(To).
name()
104 return dynamic_cast<To&
>(r);
112 template<
class To,
class From>
117 return dynamic_cast<To&
>(r);
119 catch (
const std::bad_cast&)
121 return NullObjectNonConstRef<To>();
128 template<
class To,
class From>
133 return dynamic_cast<To&
>(r);
135 catch (
const std::bad_cast&)
138 <<
"Attempt to cast type " << r.type()
139 <<
" to type " << To::typeName
142 return dynamic_cast<To&
>(r);
149 template<
class To,
class From>
152 return dynamicCastNull<To, From>(r);
157 template<
class TestType,
class Type>
160 return typeid(t) ==
typeid(TestType);
165 template<
class TestType,
class Type>
166 inline bool isA(
const Type& t)
168 const Type* tPtr = &t;
169 return dynamic_cast<const TestType*
>(tPtr);
175 template<
class TypeName,
class Name>
178 return (TypeName::typeName +
':') +
name;
184 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 & refCastNull(From &r)
Reference type cast template function,.
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.
To & dynamicCastNull(From &r)
Reference type cast template function,.