7 #ifndef _QI_TYPE_DETAIL_ANYREFERENCE_HXX_
8 #define _QI_TYPE_DETAIL_ANYREFERENCE_HXX_
47 , _value(type->initializeStorage())
56 t = typeOf<typename boost::remove_const<T>::type>();
66 QI_ONCE( t =
typeOf<
typename boost::remove_const<T>::type>());
73 throw std::runtime_error(
"Can't take the kind of an invalid value");
90 #define TYPE_OF_KIND(k, t) template<> struct TypeOfKind<k> { using type = t;}
98 template<
typename T, TypeKind k>
102 return static_cast<T>(
123 throw std::runtime_error(
"Type mismatch");
140 std::pair<AnyReference, bool> conv =
convert(targetType);
141 if (!conv.first._type)
145 T result = *conv.first.ptr<T>(
false);
147 conv.first.destroy();
152 inline void AnyReferenceBase::to<void>()
const
169 return detail::valueAs<int64_t, TypeKind_Int>(*this);
174 return detail::valueAs<uint64_t, TypeKind_Int>(*this);
179 return detail::valueAs<float, TypeKind_Float>(*this);
184 return detail::valueAs<double, TypeKind_Float>(*this);
189 return to<std::string>();
195 return to<std::vector<T> >();
198 template<
typename K,
typename V>
201 return to<std::map<K, V> >();
220 template<
typename E,
typename K>
223 return (*
this)[key].template as<E>();
270 template<
typename K,
typename V>
virtual void * ptrFromStorage(void **)=0
std::pair< AnyReference, bool > convert(TypeInterface *targetType) const
void update(const AutoAnyReference &b)
#define QI_NORETURN
Portable noreturn attribute, used to declare that a function does not return.
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)
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)
void append(const T &element)
virtual void * initializeStorage(void *ptr=0)=0
AnyReference unwrap() const
qi::Signature signature(void *storage=0, bool resolveDynamic=false)