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");
80 #define TYPE_OF_KIND(k, t) template<> struct TypeOfKind<k> { typedef t type;}
88 template<
typename T, TypeKind k>
92 return static_cast<T>(
113 throw std::runtime_error(
"Type mismatch");
130 std::pair<AnyReference, bool> conv =
convert(targetType);
131 if (!conv.first._type)
135 T result = *conv.first.ptr<T>(
false);
137 conv.first.destroy();
142 inline void AnyReferenceBase::to<void>()
const
159 return detail::valueAs<int64_t, TypeKind_Int>(*this);
164 return detail::valueAs<uint64_t, TypeKind_Int>(*this);
169 return detail::valueAs<float, TypeKind_Float>(*this);
174 return detail::valueAs<double, TypeKind_Float>(*this);
179 return to<std::string>();
185 return to<std::vector<T> >();
188 template<
typename K,
typename V>
191 return to<std::map<K, V> >();
210 template<
typename E,
typename K>
213 return (*
this)[key].template as<E>();
228 template<
typename K,
typename V>
virtual void * ptrFromStorage(void **)=0
std::pair< AnyReference, bool > convert(TypeInterface *targetType) const
void _append(const AnyReference &element)
void update(const AutoAnyReference &b)
#define QI_NORETURN
Portable noreturn attribute, used to declare that a function does not return.
E & element(const K &key)
Call operator[](key).as<E>, element type must match E.
AnyReferenceVector asTupleValuePtr()
AnyReference find(const K &key)
void insert(const K &key, const V &val)
T valueAs(const AnyReferenceBase &v)
void destroy()
Deletes storage.
T to() const
Convert to anything or throw trying.
qi::Signature signature(bool resolveDynamic=false) const
AnyReference _element(const AnyReference &key, bool throwOnFailure)
QI_NORETURN void throwConversionFailure(TypeInterface *from, TypeInterface *to)
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.
uint64_t uint64_t
Cross-platform unsigned integer of length 64 bits (8 bytes).
AnyReference clone() const
void set(const T &val)
Update the value to val, which will be converted if required.
void _insert(const AnyReference &key, const AnyReference &val)
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)
int64_t int64_t
Cross-platform signed integer of length 64 bits (8 bytes).
void append(const T &element)
virtual void * initializeStorage(void *ptr=0)=0
qi::Signature signature(void *storage=0, bool resolveDynamic=false)