9 #include <hilti/rt/exception.h>
10 #include <hilti/rt/type-info.h>
11 #include <hilti/rt/types/reference.h>
19 HILTI_EXCEPTION(ContextMismatch, UsageError)
38 : _object(std::move(obj)), _type_info(ti) {}
45 template<
typename Context>
47 if ( ti != _type_info )
48 throw ContextMismatch(
hilti::rt::fmt(
"context mismatch between related units: expected %s, but got %s",
49 _type_info->display, ti->
display));
51 return hilti::rt::any_cast<hilti::rt::StrongReference<Context>>(_object);
63 hilti::rt::any _object;
75 template<
typename Context>
77 if ( ti->
tag == hilti::rt::TypeInfo::Tag::StrongReference )
80 return UnitContext(std::move(ctx), ti);
92 template<
typename Context>
96 context = new_ctx->as<Context>(ti);
105 namespace hilti::rt::detail::adl {
108 return "<unit context>";
Definition: reference.h:376
const TypeInfo * valueType() const
Definition: type-info.h:206
Definition: unit-context.h:28
UnitContext(hilti::rt::StrongReference< T > obj, const hilti::rt::TypeInfo *ti)
Definition: unit-context.h:37
hilti::rt::StrongReference< Context > as(const hilti::rt::TypeInfo *ti) const
Definition: unit-context.h:46
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13
std::string to_string(T &&x)
Definition: extension-points.h:26
Definition: type-info.h:1273
const char * display
Definition: type-info.h:1275
Tag tag
Tag indicating which field of below union is set.
Definition: type-info.h:1333