Class Value
- All Implemented Interfaces:
Proxy
The data within the structure has protected scope: it is accessible only
to functions within a GTypeValueTable
structure, or implementations of
the g_value_*() API. That is, code portions which implement new fundamental
types.
GValue
users cannot make any assumptions about how data is stored
within the 2 element data
union, and the gType
member should
only be accessed through the G_VALUE_TYPE() macro.
-
Constructor Summary
ConstructorDescriptionValue()
Allocate a new Value.Allocate a new Value.Value
(MemorySegment address) Create a Value proxy instance for the provided memory address.Value
(Type gType, ValueDataUnion[] data) Allocate a new Value with the fields set to the provided values.Value
(Type gType, ValueDataUnion[] data, Arena arena) Allocate a new Value with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Copies the value of this Value intodestValue
.dupBoxed()
Get the contents of aG_TYPE_BOXED
derivedGValue
.Get the contents of aG_TYPE_OBJECT
derivedGValue
, increasing its reference count.dupParam()
Get the contents of aG_TYPE_PARAM
GValue
, increasing its reference count.Get a copy the contents of aG_TYPE_STRING
GValue
.Get the contents of a variantGValue
, increasing its refcount.boolean
Determines if this Value will fit inside the size of a pointer value.boolean
Get the contents of aG_TYPE_BOOLEAN
GValue
.getBoxed()
Get the contents of aG_TYPE_BOXED
derivedGValue
.byte
getChar()
Deprecated.This function's return type is broken, see g_value_get_schar()double
Get the contents of aG_TYPE_DOUBLE
GValue
.int
getEnum()
Get the contents of aG_TYPE_ENUM
GValue
.int
getFlags()
Get the contents of aG_TYPE_FLAGS
GValue
.float
getFloat()
Get the contents of aG_TYPE_FLOAT
GValue
.getGtype()
Get the contents of aG_TYPE_GTYPE
GValue
.int
getInt()
Get the contents of aG_TYPE_INT
GValue
.long
getInt64()
Get the contents of aG_TYPE_INT64
GValue
.int
getLong()
Get the contents of aG_TYPE_LONG
GValue
.static MemoryLayout
The memory layout of the native struct.Get the contents of aG_TYPE_OBJECT
derivedGValue
.getParam()
Get the contents of aG_TYPE_PARAM
GValue
.Get the contents of a pointerGValue
.byte
getSchar()
Get the contents of aG_TYPE_CHAR
GValue
.Get the contents of aG_TYPE_STRING
GValue
.static Type
getType()
Get the GType of the Value classbyte
getUchar()
Get the contents of aG_TYPE_UCHAR
GValue
.int
getUint()
Get the contents of aG_TYPE_UINT
GValue
.long
Get the contents of aG_TYPE_UINT64
GValue
.int
getUlong()
Get the contents of aG_TYPE_ULONG
GValue
.Get the contents of a variantGValue
.Initializes this Value with the default value oftype
.void
initFromInstance
(TypeInstance instance) Initializes and sets this Value from an instantiatable type via the value_table's collect_value() function.Returns the value contents as pointer.readData()
Read the value of the fielddata
.Read the value of the fieldg_type
.static void
registerTransformFunc
(Type srcType, Type destType, ValueTransform transformFunc) Registers a value transformation function for use in g_value_transform().reset()
Clears the current value in this Value and resets it to the default value (as if the value had just been initialized).void
setBoolean
(boolean vBoolean) Set the contents of aG_TYPE_BOOLEAN
GValue
tovBoolean
.void
setBoxed
(@Nullable MemorySegment vBoxed) Set the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
.void
setBoxedTakeOwnership
(@Nullable MemorySegment vBoxed) Deprecated.Use g_value_take_boxed() instead.void
setChar
(byte vChar) Deprecated.This function's input type is broken, see g_value_set_schar()void
setDouble
(double vDouble) Set the contents of aG_TYPE_DOUBLE
GValue
tovDouble
.void
setEnum
(int vEnum) Set the contents of aG_TYPE_ENUM
GValue
tovEnum
.void
setFlags
(int vFlags) Set the contents of aG_TYPE_FLAGS
GValue
tovFlags
.void
setFloat
(float vFloat) Set the contents of aG_TYPE_FLOAT
GValue
tovFloat
.void
Set the contents of aG_TYPE_GTYPE
GValue
tovGtype
.void
setInstance
(@Nullable MemorySegment instance) Sets this Value from an instantiatable type via the value_table's collect_value() function.void
setInt
(int vInt) Set the contents of aG_TYPE_INT
GValue
tovInt
.void
setInt64
(long vInt64) Set the contents of aG_TYPE_INT64
GValue
tovInt64
.void
setInternedString
(@Nullable String vString) Set the contents of aG_TYPE_STRING
GValue
tovString
.void
setLong
(int vLong) Set the contents of aG_TYPE_LONG
GValue
tovLong
.void
Set the contents of aG_TYPE_OBJECT
derivedGValue
tovObject
.void
setObjectTakeOwnership
(@Nullable MemorySegment vObject) Deprecated.Use g_value_take_object() instead.void
Set the contents of aG_TYPE_PARAM
GValue
toparam
.void
setParamTakeOwnership
(@Nullable ParamSpec param) Deprecated.Use g_value_take_param() instead.void
setPointer
(@Nullable MemorySegment vPointer) Set the contents of a pointerGValue
tovPointer
.void
setSchar
(byte vChar) Set the contents of aG_TYPE_CHAR
GValue
tovChar
.void
setStaticBoxed
(@Nullable MemorySegment vBoxed) Set the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
.void
setStaticString
(@Nullable String vString) Set the contents of aG_TYPE_STRING
GValue
tovString
.void
Set the contents of aG_TYPE_STRING
GValue
to a copy ofvString
.void
setStringTakeOwnership
(@Nullable String vString) Deprecated.Use g_value_take_string() instead.void
setUchar
(byte vUchar) Set the contents of aG_TYPE_UCHAR
GValue
tovUchar
.void
setUint
(int vUint) Set the contents of aG_TYPE_UINT
GValue
tovUint
.void
setUint64
(long vUint64) Set the contents of aG_TYPE_UINT64
GValue
tovUint64
.void
setUlong
(int vUlong) Set the contents of aG_TYPE_ULONG
GValue
tovUlong
.void
setVariant
(@Nullable Variant variant) Set the contents of a variantGValue
tovariant
.Steal ownership on contents of aG_TYPE_STRING
GValue
.void
takeBoxed
(@Nullable MemorySegment vBoxed) Sets the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
and takes over the ownership of the caller’s reference tovBoxed
; the caller doesn’t have to unref it any more.void
takeObject
(@Nullable MemorySegment vObject) Sets the contents of aG_TYPE_OBJECT
derivedGValue
tovObject
and takes over the ownership of the caller’s reference tovObject
; the caller doesn’t have to unref it any more (i.e.void
Sets the contents of aG_TYPE_PARAM
GValue
toparam
and takes over the ownership of the caller’s reference toparam
; the caller doesn’t have to unref it any more.void
takeString
(@Nullable String vString) Sets the contents of aG_TYPE_STRING
GValue
tovString
.void
takeVariant
(@Nullable Variant variant) Set the contents of a variantGValue
tovariant
, and takes over the ownership of the caller's reference tovariant
; the caller doesn't have to unref it any more (i.e.toString()
Return a newly allocated String usingGObjects.strdupValueContents(Value)
, which describes the contents of aValue
.boolean
Tries to cast the contents of this Value into a type appropriate to store indestValue
, e.g.static boolean
typeCompatible
(Type srcType, Type destType) Returns whether aGValue
of typesrcType
can be copied into aGValue
of typedestType
.static boolean
typeTransformable
(Type srcType, Type destType) Check whether g_value_transform() is able to transform values of typesrcType
into values of typedestType
.void
unset()
Clears the current value in this Value (if any) and "unsets" the type, this releases all resources associated with this GValue.void
writeData
(ValueDataUnion[] data, Arena _arena) Write a value in the fielddata
.void
writeGType
(Type gType) Write a value in the fieldg_type
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Value
Create a Value proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Value
Allocate a new Value.- Parameters:
arena
- to control the memory allocation scope
-
Value
public Value()Allocate a new Value. The memory is allocated withArena.ofAuto()
. -
Value
Allocate a new Value with the fields set to the provided values.- Parameters:
gType
- value for the fieldgType
data
- value for the fielddata
arena
- to control the memory allocation scope
-
Value
Allocate a new Value with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
gType
- value for the fieldgType
data
- value for the fielddata
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readGType
-
writeGType
Write a value in the fieldg_type
.- Parameters:
gType
- The new value for the fieldg_type
-
readData
Read the value of the fielddata
.- Returns:
- The value of the field
data
-
writeData
Write a value in the fielddata
.- Parameters:
data
- The new value for the fielddata
_arena
- to control the memory allocation scope
-
registerTransformFunc
Registers a value transformation function for use in g_value_transform(). A previously registered transformation function forsrcType
anddestType
will be replaced.- Parameters:
srcType
- Source type.destType
- Target type.transformFunc
- a function which transforms values of typesrcType
into value of typedestType
-
typeCompatible
Returns whether aGValue
of typesrcType
can be copied into aGValue
of typedestType
.- Parameters:
srcType
- source type to be copied.destType
- destination type for copying.- Returns:
true
if g_value_copy() is possible withsrcType
anddestType
.
-
typeTransformable
Check whether g_value_transform() is able to transform values of typesrcType
into values of typedestType
. Note that for the types to be transformable, they must be compatible or a transformation function must be registered.- Parameters:
srcType
- Source type.destType
- Target type.- Returns:
true
if the transformation is possible,false
otherwise.
-
copy
Copies the value of this Value intodestValue
.- Parameters:
destValue
- An initializedGValue
structure of the same type as this Value.
-
dupBoxed
Get the contents of aG_TYPE_BOXED
derivedGValue
. Upon getting, the boxed value is duplicated and needs to be later freed with g_boxed_free(), e.g. like: g_boxed_free (G_VALUE_TYPE (this Value), return_value);- Returns:
- boxed contents of this Value
-
dupObject
Get the contents of aG_TYPE_OBJECT
derivedGValue
, increasing its reference count. If the contents of theGValue
arenull
, thennull
will be returned.- Returns:
- object content of this Value, should be unreferenced when no longer needed.
-
dupParam
Get the contents of aG_TYPE_PARAM
GValue
, increasing its reference count.- Returns:
GParamSpec
content of this Value, should be unreferenced when no longer needed.
-
dupString
Get a copy the contents of aG_TYPE_STRING
GValue
.- Returns:
- a newly allocated copy of the string content of this Value
-
dupVariant
Get the contents of a variantGValue
, increasing its refcount. The returnedGVariant
is never floating.- Returns:
- variant contents of this Value (may be
null
); should be unreffed using g_variant_unref() when no longer needed
-
fitsPointer
public boolean fitsPointer()Determines if this Value will fit inside the size of a pointer value. This is an internal function introduced mainly for C marshallers.- Returns:
true
if this Value will fit inside a pointer value.
-
getBoolean
public boolean getBoolean()Get the contents of aG_TYPE_BOOLEAN
GValue
.- Returns:
- boolean contents of this Value
-
getBoxed
Get the contents of aG_TYPE_BOXED
derivedGValue
.- Returns:
- boxed contents of this Value
-
getChar
Deprecated.This function's return type is broken, see g_value_get_schar()Do not use this function; it is broken on platforms where thechar
type is unsigned, such as ARM and PowerPC. See g_value_get_schar().Get the contents of a
G_TYPE_CHAR
GValue
.- Returns:
- character contents of this Value
-
getDouble
public double getDouble()Get the contents of aG_TYPE_DOUBLE
GValue
.- Returns:
- double contents of this Value
-
getEnum
public int getEnum()Get the contents of aG_TYPE_ENUM
GValue
.- Returns:
- enum contents of this Value
-
getFlags
public int getFlags()Get the contents of aG_TYPE_FLAGS
GValue
.- Returns:
- flags contents of this Value
-
getFloat
public float getFloat()Get the contents of aG_TYPE_FLOAT
GValue
.- Returns:
- float contents of this Value
-
getGtype
Get the contents of aG_TYPE_GTYPE
GValue
.- Returns:
- the
GType
stored in this Value
-
getInt
public int getInt()Get the contents of aG_TYPE_INT
GValue
.- Returns:
- integer contents of this Value
-
getInt64
public long getInt64()Get the contents of aG_TYPE_INT64
GValue
.- Returns:
- 64bit integer contents of this Value
-
getLong
public int getLong()Get the contents of aG_TYPE_LONG
GValue
.- Returns:
- long integer contents of this Value
-
getObject
Get the contents of aG_TYPE_OBJECT
derivedGValue
.- Returns:
- object contents of this Value
-
getParam
Get the contents of aG_TYPE_PARAM
GValue
.- Returns:
GParamSpec
content of this Value
-
getPointer
Get the contents of a pointerGValue
.- Returns:
- pointer contents of this Value
-
getSchar
public byte getSchar()Get the contents of aG_TYPE_CHAR
GValue
.- Returns:
- signed 8 bit integer contents of this Value
-
getString
Get the contents of aG_TYPE_STRING
GValue
.- Returns:
- string content of this Value
-
getUchar
public byte getUchar()Get the contents of aG_TYPE_UCHAR
GValue
.- Returns:
- unsigned character contents of this Value
-
getUint
public int getUint()Get the contents of aG_TYPE_UINT
GValue
.- Returns:
- unsigned integer contents of this Value
-
getUint64
public long getUint64()Get the contents of aG_TYPE_UINT64
GValue
.- Returns:
- unsigned 64bit integer contents of this Value
-
getUlong
public int getUlong()Get the contents of aG_TYPE_ULONG
GValue
.- Returns:
- unsigned long integer contents of this Value
-
getVariant
Get the contents of a variantGValue
.- Returns:
- variant contents of this Value (may be
null
)
-
init
-
initFromInstance
Initializes and sets this Value from an instantiatable type via the value_table's collect_value() function.Note: The this Value will be initialised with the exact type of
instance
. If you wish to set the this Value's type to a different GType (such as a parent class GType), you need to manually call g_value_init() and g_value_set_instance().- Parameters:
instance
- the instance
-
peekPointer
Returns the value contents as pointer. This function asserts that g_value_fits_pointer() returnedtrue
for the passed in value. This is an internal function introduced mainly for C marshallers.- Returns:
- the value contents as pointer
-
reset
Clears the current value in this Value and resets it to the default value (as if the value had just been initialized).- Returns:
- the
GValue
structure that has been passed in
-
setBoolean
public void setBoolean(boolean vBoolean) Set the contents of aG_TYPE_BOOLEAN
GValue
tovBoolean
.- Parameters:
vBoolean
- boolean value to be set
-
setBoxed
Set the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
.- Parameters:
vBoxed
- boxed value to be set
-
setBoxedTakeOwnership
Deprecated.Use g_value_take_boxed() instead.This is an internal function introduced mainly for C marshallers.- Parameters:
vBoxed
- duplicated unowned boxed value to be set
-
setChar
Deprecated.This function's input type is broken, see g_value_set_schar()Set the contents of aG_TYPE_CHAR
GValue
tovChar
.- Parameters:
vChar
- character value to be set
-
setDouble
public void setDouble(double vDouble) Set the contents of aG_TYPE_DOUBLE
GValue
tovDouble
.- Parameters:
vDouble
- double value to be set
-
setEnum
public void setEnum(int vEnum) Set the contents of aG_TYPE_ENUM
GValue
tovEnum
.- Parameters:
vEnum
- enum value to be set
-
setFlags
public void setFlags(int vFlags) Set the contents of aG_TYPE_FLAGS
GValue
tovFlags
.- Parameters:
vFlags
- flags value to be set
-
setFloat
public void setFloat(float vFloat) Set the contents of aG_TYPE_FLOAT
GValue
tovFloat
.- Parameters:
vFloat
- float value to be set
-
setGtype
Set the contents of aG_TYPE_GTYPE
GValue
tovGtype
.- Parameters:
vGtype
-GType
to be set
-
setInstance
Sets this Value from an instantiatable type via the value_table's collect_value() function.- Parameters:
instance
- the instance
-
setInt
public void setInt(int vInt) Set the contents of aG_TYPE_INT
GValue
tovInt
.- Parameters:
vInt
- integer value to be set
-
setInt64
public void setInt64(long vInt64) Set the contents of aG_TYPE_INT64
GValue
tovInt64
.- Parameters:
vInt64
- 64bit integer value to be set
-
setInternedString
Set the contents of aG_TYPE_STRING
GValue
tovString
. The string is assumed to be static and interned (canonical, for example from g_intern_string()), and is thus not duplicated when setting theGValue
.- Parameters:
vString
- static string to be set
-
setLong
public void setLong(int vLong) Set the contents of aG_TYPE_LONG
GValue
tovLong
.- Parameters:
vLong
- long integer value to be set
-
setObject
Set the contents of aG_TYPE_OBJECT
derivedGValue
tovObject
.g_value_set_object() increases the reference count of
vObject
(theGValue
holds a reference tovObject
). If you do not wish to increase the reference count of the object (i.e. you wish to pass your current reference to theGValue
because you no longer need it), use g_value_take_object() instead.It is important that your
GValue
holds a reference tovObject
(either its own, or one it has taken) to ensure that the object won't be destroyed while theGValue
still exists).- Parameters:
vObject
- object value to be set
-
setObjectTakeOwnership
Deprecated.Use g_value_take_object() instead.This is an internal function introduced mainly for C marshallers.- Parameters:
vObject
- object value to be set
-
setParam
Set the contents of aG_TYPE_PARAM
GValue
toparam
.- Parameters:
param
- theGParamSpec
to be set
-
setParamTakeOwnership
Deprecated.Use g_value_take_param() instead.This is an internal function introduced mainly for C marshallers.- Parameters:
param
- theGParamSpec
to be set
-
setPointer
Set the contents of a pointerGValue
tovPointer
.- Parameters:
vPointer
- pointer value to be set
-
setSchar
public void setSchar(byte vChar) Set the contents of aG_TYPE_CHAR
GValue
tovChar
.- Parameters:
vChar
- signed 8 bit integer to be set
-
setStaticBoxed
Set the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
.The boxed value is assumed to be static, and is thus not duplicated when setting the
GValue
.- Parameters:
vBoxed
- static boxed value to be set
-
setStaticString
Set the contents of aG_TYPE_STRING
GValue
tovString
. The string is assumed to be static, and is thus not duplicated when setting theGValue
.If the the string is a canonical string, using g_value_set_interned_string() is more appropriate.
- Parameters:
vString
- static string to be set
-
setString
Set the contents of aG_TYPE_STRING
GValue
to a copy ofvString
.- Parameters:
vString
- caller-owned string to be duplicated for theGValue
-
setStringTakeOwnership
Deprecated.Use g_value_take_string() instead.This is an internal function introduced mainly for C marshallers.- Parameters:
vString
- duplicated unowned string to be set
-
setUchar
public void setUchar(byte vUchar) Set the contents of aG_TYPE_UCHAR
GValue
tovUchar
.- Parameters:
vUchar
- unsigned character value to be set
-
setUint
public void setUint(int vUint) Set the contents of aG_TYPE_UINT
GValue
tovUint
.- Parameters:
vUint
- unsigned integer value to be set
-
setUint64
public void setUint64(long vUint64) Set the contents of aG_TYPE_UINT64
GValue
tovUint64
.- Parameters:
vUint64
- unsigned 64bit integer value to be set
-
setUlong
public void setUlong(int vUlong) Set the contents of aG_TYPE_ULONG
GValue
tovUlong
.- Parameters:
vUlong
- unsigned long integer value to be set
-
setVariant
Set the contents of a variantGValue
tovariant
. If the variant is floating, it is consumed.- Parameters:
variant
- aGVariant
, ornull
-
stealString
Steal ownership on contents of aG_TYPE_STRING
GValue
. As a result of this operation the value's contents will be reset tonull
.The purpose of this call is to provide a way to avoid an extra copy when some object have been serialized into string through
GValue
API.NOTE: for safety and compatibility purposes, if
GValue
contains static string, or an interned one, this function will return a copy of the string. Otherwise the transfer notation would be ambiguous.- Returns:
- string content of this Value; Should be freed with g_free() when no longer needed.
-
takeBoxed
Sets the contents of aG_TYPE_BOXED
derivedGValue
tovBoxed
and takes over the ownership of the caller’s reference tovBoxed
; the caller doesn’t have to unref it any more.- Parameters:
vBoxed
- duplicated unowned boxed value to be set
-
takeObject
Sets the contents of aG_TYPE_OBJECT
derivedGValue
tovObject
and takes over the ownership of the caller’s reference tovObject
; the caller doesn’t have to unref it any more (i.e. the reference count of the object is not increased).If you want the
GValue
to hold its own reference tovObject
, use g_value_set_object() instead.- Parameters:
vObject
- object value to be set
-
takeParam
Sets the contents of aG_TYPE_PARAM
GValue
toparam
and takes over the ownership of the caller’s reference toparam
; the caller doesn’t have to unref it any more.- Parameters:
param
- theGParamSpec
to be set
-
takeString
Sets the contents of aG_TYPE_STRING
GValue
tovString
.- Parameters:
vString
- string to take ownership of
-
takeVariant
Set the contents of a variantGValue
tovariant
, and takes over the ownership of the caller's reference tovariant
; the caller doesn't have to unref it any more (i.e. the reference count of the variant is not increased).If
variant
was floating then its floating reference is converted to a hard reference.If you want the
GValue
to hold its own reference tovariant
, use g_value_set_variant() instead.This is an internal function introduced mainly for C marshallers.
- Parameters:
variant
- aGVariant
, ornull
-
transform
Tries to cast the contents of this Value into a type appropriate to store indestValue
, e.g. to transform aG_TYPE_INT
value into aG_TYPE_FLOAT
value. Performing transformations between value types might incur precision lossage. Especially transformations into strings might reveal seemingly arbitrary results and shouldn't be relied upon for production code (such as rcfile value or object property serialization).- Parameters:
destValue
- Target value.- Returns:
- Whether a transformation rule was found and could be applied.
Upon failing transformations,
destValue
is left untouched.
-
unset
public void unset()Clears the current value in this Value (if any) and "unsets" the type, this releases all resources associated with this GValue. An unset value is the same as an uninitialized (zero-filled)GValue
structure. -
toString
Return a newly allocated String usingGObjects.strdupValueContents(Value)
, which describes the contents of aValue
. The main purpose of this function is to describeValue
contents for debugging output, the way in which the contents are described may change between different GLib versions.
-