libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
qi::detail::AnyReferenceBase Class Reference

#include <anyreference.hpp>

Public Member Functions

qi::Signature signature (bool resolveDynamic=false) const
 
TypeKind kind () const
 
void update (const AutoAnyReference &b)
 
template<typename T >
void set (const T &val)
 Update the value to val, which will be converted if required. More...
 
void set (int64_t v)
 
void set (int32_t v)
 
void set (uint64_t v)
 
void set (uint32_t v)
 
void set (float v)
 
void set (double v)
 
void set (const std::string &v)
 
void setInt (int64_t v)
 
void setUInt (uint64_t v)
 
void setFloat (float v)
 
void setDouble (double v)
 
void setString (const std::string &v)
 
void setDynamic (const AnyReference &value)
 
void setRaw (const char *buffer, size_t size)
 
void setTuple (const AnyReferenceVector &values)
 
TypeInterface * type () const
 
std::vector< TypeInterface * > membersType () const
 
void * rawValue () const
 
template<>
void to () const
 
template<typename T >
T to () const
 Convert to anything or throw trying. More...
 
template<typename T >
T to (const T &) const
 Similar to previous method, but uses a dummy value to get the target type. More...
 
int64_t toInt () const
 
uint64_t toUInt () const
 
float toFloat () const
 
double toDouble () const
 
std::string toString () const
 
template<typename T >
std::vector< T > toList () const
 
template<typename K , typename V >
std::map< K, V > toMap () const
 
AnyObject toObject () const
 
AnyValue toTuple (bool homogeneous) const
 
template<typename T >
T & as ()
 
int64_t & asInt64 ()
 
uint64_t & asUInt64 ()
 
int32_t & asInt32 ()
 
uint32_t & asUInt32 ()
 
int16_t & asInt16 ()
 
uint16_t & asUInt16 ()
 
int8_t & asInt8 ()
 
uint8_t & asUInt8 ()
 
double & asDouble ()
 
float & asFloat ()
 
std::string & asString ()
 
std::pair< char *, size_t > asRaw () const
 
AnyReference content () const
 
AnyReferenceVector asTupleValuePtr ()
 
AnyReferenceVector asListValuePtr ()
 
std::map< AnyReference,
AnyReference > 
asMapValuePtr ()
 
template<typename K >
AnyReference operator[] (const K &key)
 
template<typename E , typename K >
E & element (const K &key)
 Call operator[](key).as<E>, element type must match E. More...
 
size_t size () const
 
template<typename T >
void append (const T &element)
 
template<typename K , typename V >
void insert (const K &key, const V &val)
 
template<typename K >
AnyReference find (const K &key)
 
AnyIterator begin () const
 Return an iterator on the beginning of the container. More...
 
AnyIterator end () const
 Return an iterator on the end of the container. More...
 
AnyReference operator* () const
 Dereference pointer, iterator or dynamic. More...
 

Protected Member Functions

 AnyReferenceBase ()
 

Protected Attributes

TypeInterface * _type
 
void * _value
 
 AnyReferenceBase (TypeInterface *type)
 
 AnyReferenceBase (TypeInterface *type, void *value)
 
std::pair< AnyReference, bool > convert (TypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (ListTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (StructTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (MapTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (IntTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (FloatTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (RawTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (StringTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (PointerTypeInterface *targetType) const
 
std::pair< AnyReference, bool > convert (DynamicTypeInterface *targetType) const
 
template<typename T >
T * ptr (bool check=true)
 
bool isValid () const
 
bool isValue () const
 
AnyReference convertCopy (TypeInterface *targetType) const
 Helper function that converts and always clone. More...
 
AnyReference _element (const AnyReference &key, bool throwOnFailure)
 
void _append (const AnyReference &element)
 
void _insert (const AnyReference &key, const AnyReference &val)
 
AnyReference clone () const
 
void destroy ()
 Deletes storage. More...
 
template<typename T >
static AnyReference from (const T &ref)
 
template<typename T >
static AnyReference fromPtr (const T *ptr)
 

Detailed Description

Class that holds any value, with informations to manipulate it. operator=() makes a shallow copy.

Warning
AnyReference should not be used directly as call arguments. Use qi::AnyValue which has value semantics instead.

Definition at line 35 of file anyreference.hpp.

Constructor & Destructor Documentation

qi::detail::AnyReferenceBase::AnyReferenceBase ( )
inlineprotected

Definition at line 39 of file anyreference.hxx.

qi::detail::AnyReferenceBase::AnyReferenceBase ( TypeInterface *  type)
inlineexplicitprotected

Low level Internal API Store type and allocate storage of value.

Parameters
typeuse this type for initialization

Definition at line 45 of file anyreference.hxx.

qi::detail::AnyReferenceBase::AnyReferenceBase ( TypeInterface *  type,
void *  value 
)
inlineprotected

Create a generic value with type and a value who should have already been allocated.

Parameters
typetype of this generic value
valuean already alloc place to store value

Definition at line 53 of file anyreference.hpp.

Member Function Documentation

void qi::detail::AnyReferenceBase::_append ( const AnyReference &  element)
AnyReference qi::detail::AnyReferenceBase::_element ( const AnyReference &  key,
bool  throwOnFailure 
)
void qi::detail::AnyReferenceBase::_insert ( const AnyReference &  key,
const AnyReference &  val 
)
template<typename T >
void qi::detail::AnyReferenceBase::append ( const T &  element)

Definition at line 223 of file anyreference.hxx.

template<typename T >
T & qi::detail::AnyReferenceBase::as ( )
inline

Read and update functions The following functions access or modify the existing value. They never change the storage location or type. They will fail by throwing an exception if the requested operation is incompatible with the current value type.

Warning
a AnyReference refering to a container element will become invalid as soon as the container is modified.
Returns
a typed reference to the underlying value
Warning
This method will only succeed if T exactly matches the type of the value stored. No conversion will be performed. So if you only want a value and not a reference, use to() instead.

Definition at line 109 of file anyreference.hxx.

double& qi::detail::AnyReferenceBase::asDouble ( )
inline

Definition at line 182 of file anyreference.hpp.

float& qi::detail::AnyReferenceBase::asFloat ( )
inline

Definition at line 183 of file anyreference.hpp.

int16_t& qi::detail::AnyReferenceBase::asInt16 ( )
inline

Definition at line 178 of file anyreference.hpp.

int32_t& qi::detail::AnyReferenceBase::asInt32 ( )
inline

Definition at line 176 of file anyreference.hpp.

int64_t& qi::detail::AnyReferenceBase::asInt64 ( )
inline

Definition at line 174 of file anyreference.hpp.

int8_t& qi::detail::AnyReferenceBase::asInt8 ( )
inline

Definition at line 180 of file anyreference.hpp.

AnyReferenceVector qi::detail::AnyReferenceBase::asListValuePtr ( )
inline

Definition at line 194 of file anyreference.hxx.

std::map<AnyReference, AnyReference> qi::detail::AnyReferenceBase::asMapValuePtr ( )
std::pair<char*, size_t> qi::detail::AnyReferenceBase::asRaw ( ) const
Returns
a pair of (char*, size) corresponding to the raw buffer. No copy made.
std::string& qi::detail::AnyReferenceBase::asString ( )
inline

Definition at line 184 of file anyreference.hpp.

AnyReferenceVector qi::detail::AnyReferenceBase::asTupleValuePtr ( )

Container partial unboxing. The following functions unbox the container-part of the value. The values in the contairer are exposed as AnyReference. The values can be modified using the set and as function families, But the container itself is a copy.

Warning
for better performances use the begin() and end() iterator API
uint16_t& qi::detail::AnyReferenceBase::asUInt16 ( )
inline

Definition at line 179 of file anyreference.hpp.

uint32_t& qi::detail::AnyReferenceBase::asUInt32 ( )
inline

Definition at line 177 of file anyreference.hpp.

uint64_t& qi::detail::AnyReferenceBase::asUInt64 ( )
inline

Definition at line 175 of file anyreference.hpp.

uint8_t& qi::detail::AnyReferenceBase::asUInt8 ( )
inline

Definition at line 181 of file anyreference.hpp.

AnyIterator qi::detail::AnyReferenceBase::begin ( ) const

Return an iterator on the beginning of the container.

AnyReference qi::detail::AnyReferenceBase::clone ( ) const
inline

Definition at line 16 of file anyreference.hxx.

AnyReference qi::detail::AnyReferenceBase::content ( ) const
Returns
contained AnyValue or throw if type is not dynamic.
Note
Returned AnyReference might be empty.
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( TypeInterface *  targetType) const
Returns
the pair (convertedValue, trueIfCopiedAndNeedsDestroy)
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( ListTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( StructTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( MapTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( IntTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( FloatTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( RawTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( StringTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( PointerTypeInterface *  targetType) const
std::pair<AnyReference, bool> qi::detail::AnyReferenceBase::convert ( DynamicTypeInterface *  targetType) const
AnyReference qi::detail::AnyReferenceBase::convertCopy ( TypeInterface *  targetType) const

Helper function that converts and always clone.

void qi::detail::AnyReferenceBase::destroy ( )
inline

Deletes storage.

Definition at line 32 of file anyreference.hxx.

template<typename E , typename K >
E & qi::detail::AnyReferenceBase::element ( const K &  key)

Call operator[](key).as<E>, element type must match E.

Definition at line 211 of file anyreference.hxx.

AnyIterator qi::detail::AnyReferenceBase::end ( ) const

Return an iterator on the end of the container.

template<typename K >
AnyReference qi::detail::AnyReferenceBase::find ( const K &  key)

Similar to operator[](), but return an empty AnyValue If the key is not present.

Definition at line 235 of file anyreference.hxx.

template<typename T >
AnyReference qi::detail::AnyReferenceBase::from ( const T &  ref)
static

Construction and assign. Construct a AnyValue with storage pointing to ptr.

Warning
the AnyReference will become invalid if ptr is destroyed (if it gets deleted or points to the stack and goes out of scope).

Definition at line 62 of file anyreference.hxx.

template<typename T >
AnyReference qi::detail::AnyReferenceBase::fromPtr ( const T *  ptr)
static

Definition at line 52 of file anyreference.hxx.

template<typename K , typename V >
void qi::detail::AnyReferenceBase::insert ( const K &  key,
const V &  val 
)

Definition at line 229 of file anyreference.hxx.

bool qi::detail::AnyReferenceBase::isValid ( ) const
inline

Definition at line 147 of file anyreference.hxx.

bool qi::detail::AnyReferenceBase::isValue ( ) const
inline
Returns
true if value is valid and not void

Definition at line 152 of file anyreference.hxx.

TypeKind qi::detail::AnyReferenceBase::kind ( ) const
inline

Definition at line 70 of file anyreference.hxx.

std::vector<TypeInterface*> qi::detail::AnyReferenceBase::membersType ( ) const
Returns
list of tuple elements type, or throw if not a tuple
AnyReference qi::detail::AnyReferenceBase::operator* ( ) const

Dereference pointer, iterator or dynamic.

template<typename K >
AnyReference qi::detail::AnyReferenceBase::operator[] ( const K &  key)

In-place container manipulation. Return a reference to container element at index or key idx. Use set methods on the result for inplace modification. Behavior depends on the container kind:

  • List or tuple: The key must be of integral type. Boundary checks are performed.
  • Map: The key must be of a convertible type to the container key type. If the key is not found in the container, a new default-valued Element will be created, inserted. and returned.
    Warning
    the returned value is only valid until owning container is changed.

Definition at line 217 of file anyreference.hxx.

template<typename T >
T * qi::detail::AnyReferenceBase::ptr ( bool  check = true)
inline

Return the typed pointer behind a AnyReference. T must be the type of the value.

Returns
a pointer to the value as a T or 0 if value is not a T.
Parameters
checkif false, does not validate type before converting

Definition at line 100 of file anyreference.hxx.

void* qi::detail::AnyReferenceBase::rawValue ( ) const
inline

Definition at line 288 of file anyreference.hpp.

template<typename T >
void qi::detail::AnyReferenceBase::set ( const T &  val)

Update the value to val, which will be converted if required.

Definition at line 200 of file anyreference.hxx.

void qi::detail::AnyReferenceBase::set ( int64_t  v)
inline

Definition at line 215 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( int32_t  v)
inline

Definition at line 216 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( uint64_t  v)
inline

Definition at line 217 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( uint32_t  v)
inline

Definition at line 218 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( float  v)
inline

Definition at line 219 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( double  v)
inline

Definition at line 220 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::set ( const std::string &  v)
inline

Definition at line 221 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::setDouble ( double  v)
void qi::detail::AnyReferenceBase::setDynamic ( const AnyReference &  value)
void qi::detail::AnyReferenceBase::setFloat ( float  v)
inline

Definition at line 205 of file anyreference.hxx.

void qi::detail::AnyReferenceBase::setInt ( int64_t  v)
void qi::detail::AnyReferenceBase::setRaw ( const char *  buffer,
size_t  size 
)

set the value of the raw buffer, a copy will be made.

Exceptions
std::runtime_errorwhen kind is not Raw
void qi::detail::AnyReferenceBase::setString ( const std::string &  v)
void qi::detail::AnyReferenceBase::setTuple ( const AnyReferenceVector &  values)

set the values of the tuple. A copy will be made.

Exceptions
std::runtime_errorwhen kind is not Tuple
void qi::detail::AnyReferenceBase::setUInt ( uint64_t  v)
qi::Signature qi::detail::AnyReferenceBase::signature ( bool  resolveDynamic = false) const
inline

Definition at line 24 of file anyreference.hxx.

size_t qi::detail::AnyReferenceBase::size ( ) const
template<typename T >
T qi::detail::AnyReferenceBase::to ( ) const
inline

Convert to anything or throw trying.

The following methods return a typed copy of the stored value, converting if necessary. They throw in case of conversion failure.

Definition at line 127 of file anyreference.hxx.

template<typename T >
T qi::detail::AnyReferenceBase::to ( const T &  ) const
inline

Similar to previous method, but uses a dummy value to get the target type.

Definition at line 118 of file anyreference.hxx.

template<>
void qi::detail::AnyReferenceBase::to ( ) const
inline

Definition at line 142 of file anyreference.hxx.

double qi::detail::AnyReferenceBase::toDouble ( ) const
inline

Definition at line 172 of file anyreference.hxx.

float qi::detail::AnyReferenceBase::toFloat ( ) const
inline

Definition at line 167 of file anyreference.hxx.

int64_t qi::detail::AnyReferenceBase::toInt ( ) const
inline

Definition at line 157 of file anyreference.hxx.

template<typename T >
std::vector< T > qi::detail::AnyReferenceBase::toList ( ) const
inline

Definition at line 183 of file anyreference.hxx.

template<typename K , typename V >
std::map< K, V > qi::detail::AnyReferenceBase::toMap ( ) const
inline

Definition at line 189 of file anyreference.hxx.

AnyObject qi::detail::AnyReferenceBase::toObject ( ) const
std::string qi::detail::AnyReferenceBase::toString ( ) const
inline

Definition at line 177 of file anyreference.hxx.

AnyValue qi::detail::AnyReferenceBase::toTuple ( bool  homogeneous) const

Convert the value to a tuple. If value is currently a tuple, it will be returned. If value is a list its elements will become the tuple components.

Parameters
homogeneousif true, all tuple elements will be of the type of the list element type. If false, the effective type of elements of kind dynamic will be used.
uint64_t qi::detail::AnyReferenceBase::toUInt ( ) const
inline

Definition at line 162 of file anyreference.hxx.

TypeInterface* qi::detail::AnyReferenceBase::type ( ) const
inline

Definition at line 285 of file anyreference.hpp.

void qi::detail::AnyReferenceBase::update ( const AutoAnyReference &  b)

TODO: update == set (remove one) Update the value with the one in b

Member Data Documentation

TypeInterface* qi::detail::AnyReferenceBase::_type
protected

Definition at line 291 of file anyreference.hpp.

void* qi::detail::AnyReferenceBase::_value
protected

Definition at line 292 of file anyreference.hpp.


The documentation for this class was generated from the following files: