7 #ifndef _QI_TYPE_DETAIL_ANYREFERENCE_HXX_
8 #define _QI_TYPE_DETAIL_ANYREFERENCE_HXX_
49 , _value(type->initializeStorage())
58 t = typeOf<typename boost::remove_const<T>::type>();
67 QI_ONCE( t =
typeOf<
typename boost::remove_const<T>::type>());
74 throw std::runtime_error(
"Can't take the kind of an invalid value");
91 #define TYPE_OF_KIND(k, t) template<> struct TypeOfKind<k> { using type = t;}
99 template<
typename T, TypeKind k>
103 return static_cast<T>(
124 throw std::runtime_error(
"Type mismatch");
141 auto conv =
convert(targetType);
146 T result = *conv->ptr<T>(
false);
151 inline void AnyReferenceBase::to<void>()
const
168 return detail::valueAs<int64_t, TypeKind_Int>(*this);
173 return detail::valueAs<uint64_t, TypeKind_Int>(*this);
178 return detail::valueAs<float, TypeKind_Float>(*this);
183 return detail::valueAs<double, TypeKind_Float>(*this);
188 return to<std::string>();
194 return to<std::vector<T> >();
197 template<
typename K,
typename V>
200 return to<std::map<K, V> >();
203 template <
typename T>
206 return to<boost::optional<T>>();
225 template<
typename E,
typename K>
228 return (*
this)[key].template as<E>();
275 template<
typename K,
typename V>
virtual void * ptrFromStorage(void **)=0
void update(const AutoAnyReference &b)
#define QI_NORETURN
Portable noreturn attribute, used to declare that a function does not return.
UniqueAnyReference convert(TypeInterface *targetType) const
QI_NORETURN void throwConversionFailure(TypeInterface *from, TypeInterface *to, const std::string &additionalMsg)
E & element(const K &key)
Call operator[](key).as<E>, element type must match E.
AnyReferenceVector asTupleValuePtr()
AnyReference find(const K &key)
AnyReferenceBase()
Constructs an invalid reference, pointing to nothing.
qi::Signature signature(void *storage=nullptr, bool resolveDynamic=false)
virtual void * initializeStorage(void *ptr=nullptr)=0
AnyReference _element(const AnyReference &key, bool throwOnFailure, bool autoInsert)
void insert(const K &key, const V &val)
T valueAs(const AnyReferenceBase &v)
AnyReference at(const K &key)
void destroy()
Deletes storage.
T to() const
Convert to anything or throw trying.
qi::Signature signature(bool resolveDynamic=false) const
std::vector< AnyReference > AnyReferenceVector
std::string toString() const
TypeInterface * type() const
AnyReferenceVector asListValuePtr()
std::map< K, V > toMap() const
virtual void destroy(void *)=0
Free all resources of a storage.
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
virtual const TypeInfo & info()=0
Get the TypeInfo corresponding to this type.
AnyReference content() const
AnyReference clone() const
void set(const T &val)
Update the value to val, which will be converted if required.
std::vector< T > toList() const
#define TYPE_OF_KIND(k, t)
static AnyReference from(const T &ref)
static AnyReference fromPtr(const T *ptr)
virtual void * clone(void *)=0
Allocate a storage and copy the value given as an argument.
bool operator!=(const Signature &lhs, const Signature &rhs)
AnyReference operator[](const K &key)
boost::optional< T > toOptional() const
void append(const T &element)
AnyReference unwrap() const