| Top |
| void | gwy_fill_serializable_defaults_pspec () |
| void | gwy_deserialize_filter_items () |
| gboolean | gwy_check_object_component () |
| gboolean | gwy_check_double_component () |
| gboolean | gwy_check_int32_component () |
| gboolean | gwy_check_enum_component () |
| gboolean | gwy_check_data_length_multiple () |
| gboolean | gwy_check_data_dimension () |
void gwy_fill_serializable_defaults_pspec (GwySerializableItem *items,gsize n_items,gboolean names_may_differ);
Fills serializable template item values using param specs.
The item type must be compatible with the param spec type. For instance, a 32bit integer item may have param spec of signed or unsigned integer type or it can be an enum.
If both items and properties have names set they should be equal (the function prints a warning unless
names_may_differ
is TRUE). Items that do not have names but have a param spec will have their names set to match
the corresponding properties. In such case the property name must be a static string.
Only atomic items which have aux.pspec
set have the values set.
void gwy_deserialize_filter_items (GwySerializableItem *model,gsize n_items,GwySerializableGroup *group,const gchar *type_name,GwyErrorList **error_list);
Fills the template of expected items with values from received item list.
This is a helper function for use in GwySerializable.construct() method.
Expected values are moved from group
to model
. It means their ownership is transferred from group
to model
.
Unexpected items are left in group
. The owner of group
frees such items. It normally means you do not need to
concern yourself with them because group
is owned by the deserialisation function.
The owner of model
(normally the object being constructed) is, however, responsible for consuming or freeing all
data moved there. Often it means it just takes over the arrays/objects and uses them in its own data structures.
Do not forget to free the data also in the case of failure.
An item template is identified by its name and type Multiple items of the same name are permitted in model
as
long as their types differ (this can be useful e.g. to accept old serialised representations for compatibility).
The concrete type of boxed types is not part of the identification, i.e. only one boxed item of a specific name can
be given in model
and the type, if specified using the aux
field, must match exactly.
model |
List of expected items. Generally, the values should be set to defaults ( |
|
n_items |
The number of items in the template. |
|
group |
Item list passed to |
|
type_name |
Name of the deserialised type for error messages. |
|
error_list |
Location to store the errors occuring, |
[nullable] |
gboolean gwy_check_object_component (const GwySerializableItem *item,const gchar *type_name,GType component_type,GwyErrorList **error_list);
Checks if objects in a deserialised item list match the expected type.
The item must be of type GWY_SERIALIZABLE_OBJECT or GWY_SERIALIZABLE_OBJECT_ARRAY. In the latter case all
elements are checked.
If a single object is NULL (i.e. the corresponding component was not present in the file) the function return
FALSE but does not report any error. This is usually the most useful behaviour. If you need to distinguish missing
and invalid objects, simply check value.v_object
.
An array of objects cannot have holes. So either the array exists and is full of objects or the entire array is
missing. The function returns TRUE only if the array exists and all objects match the type. When the array is
NULL, FALSE is returned, but no errors are set.
gboolean gwy_check_double_component (const GwySerializableItem *item,const gchar *type_name,gdouble min,gdouble max,GwyErrorList **error_list);
Checks if a floating point value in a deserialised item list is normal and within allowed range.
The item must be of type GWY_SERIALIZABLE_DOUBLE.
gboolean gwy_check_int32_component (const GwySerializableItem *item,const gchar *type_name,gint32 min,gint32 max,GwyErrorList **error_list);
Checks if a 32bit integer value in a deserialised item list is within allowed range.
The item must be of type GWY_SERIALIZABLE_INT32.
gboolean gwy_check_enum_component (const GwySerializableItem *item,const gchar *type_name,GType enum_type,GwyErrorList **error_list);
Checks if an enumerated value in a deserialised item list is valid.
The item must be of type GWY_SERIALIZABLE_INT32.
gboolean gwy_check_data_length_multiple (GwyErrorList **error_list,const gchar *type_name,gsize len,guint multiple);
Checks if data length is a multiple of a fixed number.
Zero length is considered valid.
gboolean gwy_check_data_dimension (GwyErrorList **error_list,const gchar *type_name,guint n_dims,gsize expected_size,...);
Checks if deserialised data dimensions are valid.
Any positive dimensions which do not multiply to an integer overflow are currently considered valid, unless
expected_size
is also given. In such case they must multiply exactly to expected_size
. Since individual zero
dimensions are invalid zero is never a valid expected_size
.
A zero-dimensional array always has one element (a scalar). The empty product is equal to 1 by definition. However,
it is usually not meaningful to call this function with n_dims
=0.
error_list |
Location to store the errors occuring, |
|
type_name |
Name of the type being deserialised (used for error messages only). |
|
n_dims |
Number of dimensions. |
|
expected_size |
Expected data size (product of all the dimensions), if known. Pass 0 to not check the total size. |
|
... |
Exactly |