QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
QGlib::Value Class Reference

#include <QGlib/Value>

Public Member Functions

 Value ()
 
 Value (const GValue *gvalue)
 
 Value (Type type)
 
 Value (bool val)
 
 Value (char val)
 
 Value (uchar val)
 
 Value (int val)
 
 Value (uint val)
 
 Value (long val)
 
 Value (ulong val)
 
 Value (qint64 val)
 
 Value (quint64 val)
 
 Value (float val)
 
 Value (double val)
 
 Value (const char *val)
 
 Value (const QByteArray &val)
 
 Value (const QString &val)
 
 Value (const Value &other)
 
Valueoperator= (const Value &other)
 
void init (Type type)
 
template<typename T >
void init ()
 
bool isValid () const
 
Type type () const
 
bool canTransformTo (Type type) const
 
Value transformTo (Type type) const
 
void clear ()
 
template<typename T >
get (bool *ok=NULL) const
 
template<typename T >
void set (const T &data)
 
bool toBool (bool *ok=NULL) const
 
char toChar (bool *ok=NULL) const
 
uchar toUChar (bool *ok=NULL) const
 
int toInt (bool *ok=NULL) const
 
uint toUInt (bool *ok=NULL) const
 
long toLong (bool *ok=NULL) const
 
ulong toULong (bool *ok=NULL) const
 
qint64 toInt64 (bool *ok=NULL) const
 
quint64 toUInt64 (bool *ok=NULL) const
 
QByteArray toByteArray (bool *ok=NULL) const
 
QString toString (bool *ok=NULL) const
 
Error toError (bool *ok=NULL) const
 
 operator GValue * ()
 
 operator const GValue * () const
 

Static Public Member Functions

template<typename T >
static Value create (const T &data)
 
static void registerValueVTable (Type type, const ValueVTable &vtable)
 

Related Functions

(Note that these are not member functions.)

QDebug operator<< (QDebug debug, const Value &value)
 

Detailed Description

Wrapper class for GValue.

This class serves as a wrapper for GValue. GValue is a data type that can hold different types of values inside, like a QVariant.

A Value object holds a single value of a single type() at a time. To create a new Value, use the static create() method or one of the constructors. To get the held value, use the template get() method or one of the toT() functions (ex. toInt()).

To set a value to an invalid Value (on which isValid() returns false), you must first initialize this Value using one of the init() methods (preferably the template one) in order to tell it what kind of value it is going to hold. Once initialized to hold a specific type, you can use the set() method to set a value. To change the type that this value holds, you can call the init() method again at any time. In this case, though, any previously held value will be lost.

Note
This class is implicitly shared.

Definition at line 74 of file value.h.

Constructor & Destructor Documentation

QGlib::Value::Value ( )

Creates a new invalid Value

See also
isValid()

Definition at line 175 of file value.cpp.

QGlib::Value::Value ( const GValue *  gvalue)
explicit

Creates a new Value that holds a copy of the given gvalue

Definition at line 180 of file value.cpp.

QGlib::Value::Value ( Type  type)
explicit

Creates a new Value and initializes it to hold values of the given type. This is equivalent to:

Value v;
v.init(type);

Definition at line 189 of file value.cpp.

QGlib::Value::Value ( bool  val)

Creates a new Value of Type::Bool and sets it to hold val.

QGlib::Value::Value ( char  val)

Creates a new Value of Type::Char and sets it to hold val.

QGlib::Value::Value ( uchar  val)

Creates a new Value of Type::Uchar and sets it to hold val.

QGlib::Value::Value ( int  val)

Creates a new Value of Type::Int and sets it to hold val.

QGlib::Value::Value ( uint  val)

Creates a new Value of Type::Uint and sets it to hold val.

QGlib::Value::Value ( long  val)

Creates a new Value of Type::Long and sets it to hold val.

QGlib::Value::Value ( ulong  val)

Creates a new Value of Type::Ulong and sets it to hold val.

QGlib::Value::Value ( qint64  val)

Creates a new Value of Type::Int64 and sets it to hold val.

QGlib::Value::Value ( quint64  val)

Creates a new Value of Type::Uint64 and sets it to hold val.

QGlib::Value::Value ( float  val)

Creates a new Value of Type::Float and sets it to hold val.

QGlib::Value::Value ( double  val)

Creates a new Value of Type::Double and sets it to hold val.

QGlib::Value::Value ( const char *  val)

Creates a new Value of Type::String and sets it to hold val.

QGlib::Value::Value ( const QByteArray &  val)

Creates a new Value of Type::String and sets it to hold val.

QGlib::Value::Value ( const QString &  val)

Creates a new Value of Type::String and sets it to hold val.

Member Function Documentation

template<typename T >
Value QGlib::Value::create ( const T &  data)
inlinestatic

Creates a new Value that is intialized to hold data of type T and sets it to hold data.

Note
T must be a type registered with the QtGLib type system. Attempting to use a type that is not properly registered will fail to compile.

Definition at line 293 of file value.h.

void QGlib::Value::init ( Type  type)

Initializes or re-initializes this Value to hold data of the given type. If this Value was previously holding any data, this data will be freed.

Definition at line 239 of file value.cpp.

template<typename T >
void QGlib::Value::init ( )
inline

Initializes or re-initializes this Value to hold data of type T. If this Value was previously holding any data, this data will be freed.

Note
T must be a type registered with the QtGLib type system. Attempting to use a type that is not properly registered will fail to compile.

Definition at line 302 of file value.h.

bool QGlib::Value::isValid ( ) const
Returns
whether this Value instance is initialized to hold a certain type
See also
init()

Definition at line 247 of file value.cpp.

Type QGlib::Value::type ( ) const
Returns
the type that this Value instance has been initialized to hold

Definition at line 252 of file value.cpp.

bool QGlib::Value::canTransformTo ( Type  type) const
Returns
whether it is possible to transform this Value to a Value of another type

Definition at line 257 of file value.cpp.

Value QGlib::Value::transformTo ( Type  type) const

Transforms the current value into a value of the specified type, if possible. Possible transformations are, for example, int to float, int to string, etc... The original Value remains unaffected and the transformed Value is returned.

Definition at line 262 of file value.cpp.

void QGlib::Value::clear ( )

Clears the current value in this Value instance and resets it to the default value (as if the Value had just been initialized).

Definition at line 272 of file value.cpp.

template<typename T >
T QGlib::Value::get ( bool *  ok = NULL) const

Retrieves the value stored in this Value instance, as the specified type T. The bindings take care of calling the appropriate g_value_get_* method depending on the type T. Note though that this is only meant to be used with the types of the bindings, not their C types. This means that if for example the Value has been initialized to hold a GstObject pointer, you can use:

QGst::ObjectPtr object = value.get<QGst::ObjectPtr>();

but not this:

GstObject *object = value.get<GstObject*>(); //will cause compilation error

If the underlying stored value is not of the type T, this method will attempt to convert it to type T. If this is not possible, a default constructed value will be returned.

If ok has been specified, it is set to true if the value was retrieved successfully or false if there was an error (probably conversion error) and a default constructed value has been returned.

Definition at line 308 of file value.h.

template<typename T >
void QGlib::Value::set ( const T &  data)

Sets this Value instance to hold the specified data. As with get(), the bindings take care of calling the appropriate g_value_set_* method depending on the type T, but note that this is only meant to be used with the types of the bindings.

If this Value instance has been initialized to hold a different type of data than T, a conversion to the correct type() will be attempted. If the conversion fails, the Value will remain unaffected and a warning will be printed.

See also
get()

Definition at line 325 of file value.h.

bool QGlib::Value::toBool ( bool *  ok = NULL) const
inline

Returns the held value as a bool. Equivalent to get<bool>(ok);

See also
get()

Definition at line 194 of file value.h.

char QGlib::Value::toChar ( bool *  ok = NULL) const
inline

Returns the held value as a char. Equivalent to get<char>(ok);

See also
get()

Definition at line 197 of file value.h.

uchar QGlib::Value::toUChar ( bool *  ok = NULL) const
inline

Returns the held value as a uchar. Equivalent to get<uchar>(ok);

See also
get()

Definition at line 200 of file value.h.

int QGlib::Value::toInt ( bool *  ok = NULL) const
inline

Returns the held value as an int. Equivalent to get<int>(ok);

See also
get()

Definition at line 203 of file value.h.

uint QGlib::Value::toUInt ( bool *  ok = NULL) const
inline

Returns the held value as a uint. Equivalent to get<uint>(ok);

See also
get()

Definition at line 206 of file value.h.

long QGlib::Value::toLong ( bool *  ok = NULL) const
inline

Returns the held value as a long. Equivalent to get<long>(ok);

See also
get()

Definition at line 209 of file value.h.

ulong QGlib::Value::toULong ( bool *  ok = NULL) const
inline

Returns the held value as a ulong. Equivalent to get<ulong>(ok);

See also
get()

Definition at line 212 of file value.h.

qint64 QGlib::Value::toInt64 ( bool *  ok = NULL) const
inline

Returns the held value as a qint64. Equivalent to get<qint64>(ok);

See also
get()

Definition at line 215 of file value.h.

quint64 QGlib::Value::toUInt64 ( bool *  ok = NULL) const
inline

Returns the held value as a quint64. Equivalent to get<quint64>(ok);

See also
get()

Definition at line 218 of file value.h.

QByteArray QGlib::Value::toByteArray ( bool *  ok = NULL) const
inline

Returns the held value as a QByteAray. Equivalent to get<QByteArray>(ok);

See also
get()

Definition at line 221 of file value.h.

QString QGlib::Value::toString ( bool *  ok = NULL) const
inline

Returns the held value as a QString. Equivalent to get<QString>(ok);

See also
get()

Definition at line 224 of file value.h.

Error QGlib::Value::toError ( bool *  ok = NULL) const
inline

Returns the held value as a QGlib::Error. Equivalent to get<QGlib::Error>(ok);

See also
get()

Definition at line 227 of file value.h.

QGlib::Value::operator GValue * ( )

This is a cast operator that gives access to the underlying GValue instance. It is provided for convenience, to be able to pass this Value as argument to C functions that expect a GValue pointer. Use this feature with care. Do not store the pointer, as it may go away at any time. This Value instance keeps control of this pointer. If you need to store it, use g_value_copy() to copy it first.

Definition at line 279 of file value.cpp.

QGlib::Value::operator const GValue * ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 284 of file value.cpp.

void QGlib::Value::registerValueVTable ( Type  type,
const ValueVTable vtable 
)
static

Registers the given ValueVTable vtable for the given type. This is provided to let you add support for a custom type, if necessary. You should normally not need to do that, as most types are handled by the handlers of their parent types.

See also
Value Design

Definition at line 290 of file value.cpp.

Friends And Related Function Documentation

QDebug operator<< ( QDebug  debug,
const Value value 
)
related

Definition at line 359 of file value.cpp.


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