Wrapper class for GValue.
More...
#include <QGlib/Value>
List of all members.
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.
- Examples:
-
recorder/main.cpp.
Definition at line 73 of file value.h.
Constructor & Destructor Documentation
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:
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 |
) |
[inline, static] |
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 290 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 299 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:
but not this:
GstObject *object = value.get<GstObject*>();
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 305 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 322 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 193 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 196 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 199 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 202 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 205 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 208 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 211 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 214 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 217 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 220 of file value.h.
QString QGlib::Value::toString |
( |
bool * |
ok = NULL |
) |
const [inline] |
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] |
The documentation for this class was generated from the following files: