QtGStreamer  1.2.0
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 76 of file value.h.

Constructor & Destructor Documentation

◆ Value() [1/17]

QGlib::Value::Value ( )

Creates a new invalid Value

See also
isValid()

Definition at line 177 of file value.cpp.

◆ Value() [2/17]

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

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

Definition at line 182 of file value.cpp.

◆ Value() [3/17]

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

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

v.init(type);
Type type() const
Definition: value.cpp:254

Definition at line 191 of file value.cpp.

◆ Value() [4/17]

QGlib::Value::Value ( bool  val)

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

◆ Value() [5/17]

QGlib::Value::Value ( char  val)

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

◆ Value() [6/17]

QGlib::Value::Value ( uchar  val)

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

◆ Value() [7/17]

QGlib::Value::Value ( int  val)

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

◆ Value() [8/17]

QGlib::Value::Value ( uint  val)

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

◆ Value() [9/17]

QGlib::Value::Value ( long  val)

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

◆ Value() [10/17]

QGlib::Value::Value ( ulong  val)

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

◆ Value() [11/17]

QGlib::Value::Value ( qint64  val)

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

◆ Value() [12/17]

QGlib::Value::Value ( quint64  val)

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

◆ Value() [13/17]

QGlib::Value::Value ( float  val)

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

◆ Value() [14/17]

QGlib::Value::Value ( double  val)

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

◆ Value() [15/17]

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

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

◆ Value() [16/17]

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

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

◆ Value() [17/17]

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

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

Member Function Documentation

◆ create()

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 295 of file value.h.

◆ init() [1/2]

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 241 of file value.cpp.

◆ init() [2/2]

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 304 of file value.h.

◆ isValid()

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

Definition at line 249 of file value.cpp.

◆ type()

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

Definition at line 254 of file value.cpp.

◆ canTransformTo()

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 259 of file value.cpp.

◆ transformTo()

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 264 of file value.cpp.

◆ clear()

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 274 of file value.cpp.

◆ get()

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>();
Smart pointer class for working with wrapper classes that support reference counting.
Definition: refpointer.h:91

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 310 of file value.h.

◆ set()

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 327 of file value.h.

◆ toBool()

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 196 of file value.h.

◆ toChar()

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 199 of file value.h.

◆ toUChar()

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 202 of file value.h.

◆ toInt()

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 205 of file value.h.

◆ toUInt()

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 208 of file value.h.

◆ toLong()

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 211 of file value.h.

◆ toULong()

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 214 of file value.h.

◆ toInt64()

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 217 of file value.h.

◆ toUInt64()

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 220 of file value.h.

◆ toByteArray()

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 223 of file value.h.

◆ toString()

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 226 of file value.h.

◆ toError()

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 229 of file value.h.

◆ operator GValue *()

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 281 of file value.cpp.

◆ operator const GValue *()

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 286 of file value.cpp.

◆ registerValueVTable()

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 292 of file value.cpp.


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