Class Value
- All Implemented Interfaces:
Proxy
Before it can be used, a GValue has to be initialized to a specific type by
calling init(org.gnome.glib.Type) on it.
Many types which are stored within a GValue need to allocate data on the
heap, so unset() must always be called on a GValue to
free any such data once you’re finished with the GValue, even if the
GValue itself is stored on the stack.
The data within the structure has protected scope: it is accessible only
to functions within a GObject.TypeValueTable structure, or
implementations of the g_value_*() API. That is, code which implements 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 GObjects#VALUETYPE macro and related
macros.
-
Constructor Summary
ConstructorsConstructorDescriptionValue()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 TypeMethodDescriptionvoidCopies the value of this Value intodestValue.@Nullable MemorySegmentdupBoxed()Get the contents of aG_TYPE_BOXEDderivedGValue.@Nullable GObjectGet the contents of aG_TYPE_OBJECTderivedGValue, increasing its reference count.dupParam()Get the contents of aG_TYPE_PARAMGValue, increasing its reference count.@Nullable StringGet a copy the contents of aG_TYPE_STRINGGValue.@Nullable VariantGet the contents of a variantGValue, increasing its refcount.booleanDetermines if this Value will fit inside the size of a pointer value.booleanGet the contents of aG_TYPE_BOOLEANGValue.@Nullable MemorySegmentgetBoxed()Get the contents of aG_TYPE_BOXEDderivedGValue.bytegetChar()Deprecated.This function's return type is broken, see g_value_get_schar()doubleGet the contents of aG_TYPE_DOUBLEGValue.intgetEnum()Get the contents of aG_TYPE_ENUMGValue.intgetFlags()Get the contents of aG_TYPE_FLAGSGValue.floatgetFloat()Get the contents of aG_TYPE_FLOATGValue.getGtype()Get the contents of aG_TYPE_GTYPEGValue.intgetInt()Get the contents of aG_TYPE_INTGValue.longgetInt64()Get the contents of aG_TYPE_INT64GValue.intgetLong()Get the contents of aG_TYPE_LONGGValue.static MemoryLayoutThe memory layout of the native struct.@Nullable GObjectGet the contents of aG_TYPE_OBJECTderivedGValue.getParam()Get the contents of aG_TYPE_PARAMGValue.@Nullable MemorySegmentGet the contents of a pointerGValue.bytegetSchar()Get the contents of aG_TYPE_CHARGValue.@Nullable StringGet the contents of aG_TYPE_STRINGGValue.static @Nullable TypegetType()Get the GType of the Value classbytegetUchar()Get the contents of aG_TYPE_UCHARGValue.intgetUint()Get the contents of aG_TYPE_UINTGValue.longGet the contents of aG_TYPE_UINT64GValue.intgetUlong()Get the contents of aG_TYPE_ULONGGValue.@Nullable VariantGet the contents of a variantGValue.Initializes this Value to store values of the giventype,and sets its value to the default fortype.voidinitFromInstance(TypeInstance instance) Initializes and sets this Value from an instantiatable type.@Nullable MemorySegmentReturns the value contents as a pointer.@Nullable _ValueDataUnion @Nullable []readData()Read the value of the fielddata.Read the value of the fieldg_type.static voidregisterTransformFunc(Type srcType, Type destType, @Nullable ValueTransform transformFunc) Registers a value transformation function for use intransform(org.gnome.gobject.Value).reset()Clears the current value in this Value and resets it to the default value (as if the value had just been initialized usinginit(org.gnome.glib.Type)).voidsetBoolean(boolean vBoolean) Set the contents of aG_TYPE_BOOLEANGValuetovBoolean.voidsetBoxed(@Nullable MemorySegment vBoxed) Set the contents of aG_TYPE_BOXEDderivedGValuetovBoxed.voidsetBoxedTakeOwnership(@Nullable MemorySegment vBoxed) Deprecated.Use g_value_take_boxed() instead.voidsetChar(byte vChar) Deprecated.This function's input type is broken, see g_value_set_schar()voidsetDouble(double vDouble) Set the contents of aG_TYPE_DOUBLEGValuetovDouble.voidsetEnum(int vEnum) Set the contents of aG_TYPE_ENUMGValuetovEnum.voidsetFlags(int vFlags) Set the contents of aG_TYPE_FLAGSGValuetovFlags.voidsetFloat(float vFloat) Set the contents of aG_TYPE_FLOATGValuetovFloat.voidSet the contents of aG_TYPE_GTYPEGValuetovGtype.voidsetInstance(@Nullable MemorySegment instance) Sets this Value from an instantiatable type.voidsetInt(int vInt) Set the contents of aG_TYPE_INTGValuetovInt.voidsetInt64(long vInt64) Set the contents of aG_TYPE_INT64GValuetovInt64.voidsetInternedString(@Nullable String vString) Set the contents of aG_TYPE_STRINGGValuetovString.The string is assumed to be static and interned (canonical, for example from g_intern_string()), and is thus not duplicated when setting theGValue.voidsetLong(int vLong) Set the contents of aG_TYPE_LONGGValuetovLong.voidSet the contents of aG_TYPE_OBJECTderivedGValuetovObject.voidsetObjectTakeOwnership(@Nullable MemorySegment vObject) Deprecated.Use g_value_take_object() instead.voidSet the contents of aG_TYPE_PARAMGValuetoparam.voidsetParamTakeOwnership(@Nullable ParamSpec param) Deprecated.Use g_value_take_param() instead.voidsetPointer(@Nullable MemorySegment vPointer) Set the contents of a pointerGValuetovPointer.voidsetSchar(byte vChar) Set the contents of aG_TYPE_CHARGValuetovChar.voidsetStaticBoxed(@Nullable MemorySegment vBoxed) Set the contents of aG_TYPE_BOXEDderivedGValuetovBoxed.voidsetStaticString(@Nullable String vString) Set the contents of aG_TYPE_STRINGGValuetovString.The string is assumed to be static, and is thus not duplicated when setting theGValue.voidSet the contents of aG_TYPE_STRINGGValueto a copy ofvString.voidsetStringTakeOwnership(@Nullable String vString) Deprecated.Use g_value_take_string() instead.voidsetUchar(byte vUchar) Set the contents of aG_TYPE_UCHARGValuetovUchar.voidsetUint(int vUint) Set the contents of aG_TYPE_UINTGValuetovUint.voidsetUint64(long vUint64) Set the contents of aG_TYPE_UINT64GValuetovUint64.voidsetUlong(int vUlong) Set the contents of aG_TYPE_ULONGGValuetovUlong.voidsetVariant(@Nullable Variant variant) Set the contents of a variantGValuetovariant.If the variant is floating, it is consumed.@Nullable StringSteal ownership on contents of aG_TYPE_STRINGGValue.voidtakeBoxed(@Nullable MemorySegment vBoxed) Sets the contents of aG_TYPE_BOXEDderivedGValuetovBoxedand takes over the ownership of the caller’s reference tovBoxed;the caller doesn’t have to unref it any more.voidtakeObject(@Nullable MemorySegment vObject) Sets the contents of aG_TYPE_OBJECTderivedGValuetovObjectand takes over the ownership of the caller’s reference tovObject;the caller doesn’t have to unref it any more (i.e.voidSets the contents of aG_TYPE_PARAMGValuetoparamand takes over the ownership of the caller’s reference toparam;the caller doesn’t have to unref it any more.voidtakeString(@Nullable String vString) Sets the contents of aG_TYPE_STRINGGValuetovString.voidtakeVariant(@Nullable Variant variant) Set the contents of a variantGValuetovariant,and takes over the ownership of the caller's reference tovariant;the caller doesn't have to unref it any more (i.e.toString()Returns a string representation of the object.booleanTries to cast the contents of this Value into a type appropriate to store indestValue.static booleantypeCompatible(Type srcType, Type destType) Checks whether acopy(org.gnome.gobject.Value)is able to copy values of typesrcTypeinto values of typedestType.static booleantypeTransformable(Type srcType, Type destType) Checks whethertransform(org.gnome.gobject.Value)is able to transform values of typesrcTypeinto values of typedestType.voidunset()Clears the current value in this Value (if any) and ‘unsets’ the type.voidwriteData(@Nullable _ValueDataUnion @Nullable [] data, Arena _arena) Write a value in the fielddata.voidwriteGType(Type gType) Write a value in the fieldg_type.Methods inherited from class org.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 fieldgTypedata- value for the fielddataarena- 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 fieldgTypedata- 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
-
registerTransformFunc
public static void registerTransformFunc(Type srcType, Type destType, @Nullable ValueTransform transformFunc) Registers a value transformation function for use intransform(org.gnome.gobject.Value).Any previously registered transformation function for
srcTypeanddestTypewill be replaced.- Parameters:
srcType- source typedestType- target typetransformFunc- a function which transforms values of typesrcTypeinto values of typedestType
-
typeCompatible
Checks whether acopy(org.gnome.gobject.Value)is able to copy values of typesrcTypeinto values of typedestType.- Parameters:
srcType- source type to be copieddestType- destination type for copying- Returns:
- true if the copy is possible; false otherwise
-
typeTransformable
Checks whethertransform(org.gnome.gobject.Value)is able to transform values of typesrcTypeinto values of typedestType.Note that for the types to be transformable, they must be compatible or a transformation function must be registered using
registerTransformFunc(org.gnome.glib.Type, org.gnome.glib.Type, org.gnome.gobject.ValueTransform).- Parameters:
srcType- source typedestType- target type- Returns:
- true if the transformation is possible; false otherwise
-
copy
Copies the value of this Value intodestValue.- Parameters:
destValue- an initializedGObject.Valuestructure of the same type as this Value
-
dupBoxed
Get the contents of aG_TYPE_BOXEDderivedGValue. 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 (value),return_value);- Returns:
- boxed contents of this Value
-
dupObject
Get the contents of aG_TYPE_OBJECTderivedGValue, increasing its reference count. If the contents of theGValuearenull, thennullwill be returned.- Returns:
- object content of
value,should be unreferenced when no longer needed.
-
dupParam
Get the contents of aG_TYPE_PARAMGValue, increasing its reference count.- Returns:
GParamSpeccontent ofvalue,should be unreferenced when no longer needed.
-
dupString
Get a copy the contents of aG_TYPE_STRINGGValue.- Returns:
- a newly allocated copy of the string content of this Value
-
dupVariant
Get the contents of a variantGValue, increasing its refcount. The returnedGVariantis never floating.- Returns:
- variant contents of this Value (may be
null); should be unreffed using g_variant_unref() when no longer needed - Since:
- 2.26
-
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; false otherwise
-
getBoolean
public boolean getBoolean()Get the contents of aG_TYPE_BOOLEANGValue.- Returns:
- boolean contents of this Value
-
getBoxed
Get the contents of aG_TYPE_BOXEDderivedGValue.- 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 thechartype is unsigned, such as ARM and PowerPC. See g_value_get_schar().Get the contents of a
G_TYPE_CHARGValue.- Returns:
- character contents of this Value
-
getDouble
public double getDouble()Get the contents of aG_TYPE_DOUBLEGValue.- Returns:
- double contents of this Value
-
getEnum
public int getEnum()Get the contents of aG_TYPE_ENUMGValue.- Returns:
- enum contents of this Value
-
getFlags
public int getFlags()Get the contents of aG_TYPE_FLAGSGValue.- Returns:
- flags contents of this Value
-
getFloat
public float getFloat()Get the contents of aG_TYPE_FLOATGValue.- Returns:
- float contents of this Value
-
getGtype
Get the contents of aG_TYPE_GTYPEGValue.- Returns:
- the
GTypestored in this Value - Since:
- 2.12
-
getInt
public int getInt()Get the contents of aG_TYPE_INTGValue.- Returns:
- integer contents of this Value
-
getInt64
public long getInt64()Get the contents of aG_TYPE_INT64GValue.- Returns:
- 64bit integer contents of this Value
-
getLong
public int getLong()Get the contents of aG_TYPE_LONGGValue.- Returns:
- long integer contents of this Value
-
getObject
Get the contents of aG_TYPE_OBJECTderivedGValue.- Returns:
- object contents of this Value
-
getParam
Get the contents of aG_TYPE_PARAMGValue.- Returns:
GParamSpeccontent 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_CHARGValue.- Returns:
- signed 8 bit integer contents of this Value
- Since:
- 2.32
-
getString
Get the contents of aG_TYPE_STRINGGValue.- Returns:
- string content of this Value
-
getUchar
public byte getUchar()Get the contents of aG_TYPE_UCHARGValue.- Returns:
- unsigned character contents of this Value
-
getUint
public int getUint()Get the contents of aG_TYPE_UINTGValue.- Returns:
- unsigned integer contents of this Value
-
getUint64
public long getUint64()Get the contents of aG_TYPE_UINT64GValue.- Returns:
- unsigned 64bit integer contents of this Value
-
getUlong
public int getUlong()Get the contents of aG_TYPE_ULONGGValue.- Returns:
- unsigned long integer contents of this Value
-
getVariant
Get the contents of a variantGValue.- Returns:
- variant contents of this Value (may be
null) - Since:
- 2.26
-
init
Initializes this Value to store values of the giventype,and sets its value to the default fortype.This must be called before any other methods on a
GObject.Value, so the value knows what type it’s meant to store.GValue value = G_VALUE_INIT; g_value_init (&value, SOME_G_TYPE); … g_value_unset (&value);- Parameters:
gType- type theGObject.Valueshould hold values of- Returns:
- the
GObject.Valuestructure that has been passed in
-
initFromInstance
Initializes and sets this Value from an instantiatable type.This calls the
GObject.TypeValueCollectFuncfunction for the type theGObject.Valuecontains.Note: The this Value will be initialised with the exact type of
instance.If you wish to set thevalue’stype to a differentGObject.Type(such as a parent class type), you need to manually callinit(org.gnome.glib.Type)andsetInstance(java.lang.foreign.MemorySegment).- Parameters:
instance- the instance- Since:
- 2.42
-
peekPointer
Returns the value contents as a pointer.This function asserts that
fitsPointer()returned true for the passed in value.This is an internal function introduced mainly for C marshallers.
- Returns:
- the value contents as a pointer
-
reset
Clears the current value in this Value and resets it to the default value (as if the value had just been initialized usinginit(org.gnome.glib.Type)).- Returns:
- the
GObject.Valuestructure that has been passed in
-
setBoolean
public void setBoolean(boolean vBoolean) Set the contents of aG_TYPE_BOOLEANGValuetovBoolean.- Parameters:
vBoolean- boolean value to be set
-
setBoxed
Set the contents of aG_TYPE_BOXEDderivedGValuetovBoxed.- Parameters:
vBoxed- caller-owned boxed object to be duplicated for theGValue
-
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_CHARGValuetovChar.- Parameters:
vChar- character value to be set
-
setDouble
public void setDouble(double vDouble) Set the contents of aG_TYPE_DOUBLEGValuetovDouble.- Parameters:
vDouble- double value to be set
-
setEnum
public void setEnum(int vEnum) Set the contents of aG_TYPE_ENUMGValuetovEnum.- Parameters:
vEnum- enum value to be set
-
setFlags
public void setFlags(int vFlags) Set the contents of aG_TYPE_FLAGSGValuetovFlags.- Parameters:
vFlags- flags value to be set
-
setFloat
public void setFloat(float vFloat) Set the contents of aG_TYPE_FLOATGValuetovFloat.- Parameters:
vFloat- float value to be set
-
setGtype
Set the contents of aG_TYPE_GTYPEGValuetovGtype.- Parameters:
vGtype-GTypeto be set- Since:
- 2.12
-
setInstance
Sets this Value from an instantiatable type.This calls the
GObject.TypeValueCollectFuncfunction for the type theGObject.Valuecontains.- Parameters:
instance- the instance
-
setInt
public void setInt(int vInt) Set the contents of aG_TYPE_INTGValuetovInt.- Parameters:
vInt- integer value to be set
-
setInt64
public void setInt64(long vInt64) Set the contents of aG_TYPE_INT64GValuetovInt64.- Parameters:
vInt64- 64bit integer value to be set
-
setInternedString
Set the contents of aG_TYPE_STRINGGValuetovString.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- Since:
- 2.66
-
setLong
public void setLong(int vLong) Set the contents of aG_TYPE_LONGGValuetovLong.- Parameters:
vLong- long integer value to be set
-
setObject
Set the contents of aG_TYPE_OBJECTderivedGValuetovObject.g_value_set_object() increases the reference count of
vObject(theGValueholds 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 theGValuebecause you no longer need it), use g_value_take_object() instead.It is important that your
GValueholds a reference tovObject(either its own, or one it has taken) to ensure that the object won't be destroyed while theGValuestill 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_PARAMGValuetoparam.- Parameters:
param- theGParamSpecto be set
-
setParamTakeOwnership
Deprecated.Use g_value_take_param() instead.This is an internal function introduced mainly for C marshallers.- Parameters:
param- theGParamSpecto be set
-
setPointer
Set the contents of a pointerGValuetovPointer.- Parameters:
vPointer- pointer value to be set
-
setSchar
public void setSchar(byte vChar) Set the contents of aG_TYPE_CHARGValuetovChar.- Parameters:
vChar- signed 8 bit integer to be set- Since:
- 2.32
-
setStaticBoxed
Set the contents of aG_TYPE_BOXEDderivedGValuetovBoxed.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_STRINGGValuetovString.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_STRINGGValueto 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_UCHARGValuetovUchar.- Parameters:
vUchar- unsigned character value to be set
-
setUint
public void setUint(int vUint) Set the contents of aG_TYPE_UINTGValuetovUint.- Parameters:
vUint- unsigned integer value to be set
-
setUint64
public void setUint64(long vUint64) Set the contents of aG_TYPE_UINT64GValuetovUint64.- Parameters:
vUint64- unsigned 64bit integer value to be set
-
setUlong
public void setUlong(int vUlong) Set the contents of aG_TYPE_ULONGGValuetovUlong.- Parameters:
vUlong- unsigned long integer value to be set
-
setVariant
Set the contents of a variantGValuetovariant.If the variant is floating, it is consumed.- Parameters:
variant- aGVariant, ornull- Since:
- 2.26
-
stealString
Steal ownership on contents of aG_TYPE_STRINGGValue. 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
GValueAPI.NOTE: for safety and compatibility purposes, if
GValuecontains 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
value;Should be freed with g_free() when no longer needed. - Since:
- 2.80
-
takeBoxed
Sets the contents of aG_TYPE_BOXEDderivedGValuetovBoxedand 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- Since:
- 2.4
-
takeObject
Sets the contents of aG_TYPE_OBJECTderivedGValuetovObjectand 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
GValueto hold its own reference tovObject,use g_value_set_object() instead.- Parameters:
vObject- object value to be set- Since:
- 2.4
-
takeParam
Sets the contents of aG_TYPE_PARAMGValuetoparamand takes over the ownership of the caller’s reference toparam;the caller doesn’t have to unref it any more.- Parameters:
param- theGParamSpecto be set- Since:
- 2.4
-
takeString
Sets the contents of aG_TYPE_STRINGGValuetovString.- Parameters:
vString- string to take ownership of- Since:
- 2.4
-
takeVariant
Set the contents of a variantGValuetovariant,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
variantwas floating then its floating reference is converted to a hard reference.If you want the
GValueto 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- Since:
- 2.26
-
transform
Tries to cast the contents of this Value into a type appropriate to store indestValue.If a transformation is not possible,
destValueis not modified.For example, this could transform a
G_TYPE_INTvalue into aG_TYPE_FLOATvalue.Performing transformations between value types might incur precision loss. Especially transformations into strings might reveal seemingly arbitrary results and the format of particular transformations to strings is not guaranteed over time.
- Parameters:
destValue- target value- Returns:
- true on success; false otherwise
-
unset
public void unset()Clears the current value in this Value (if any) and ‘unsets’ the type.This releases all resources associated with this
GObject.Value. An unset value is the same as a cleared (zero-filled)GObject.Valuestructure set toG_VALUE_INIT. -
toString
-