![]() |
![]() |
Gwyddion Library Reference Manual | ![]() |
|
---|---|---|---|---|
GwyResource; GwyResourceClass; const gchar* gwy_resource_get_name (GwyResource *resource); gboolean gwy_resource_get_is_modifiable (GwyResource *resource); gboolean gwy_resource_get_is_preferred (GwyResource *resource); void gwy_resource_set_is_preferred (GwyResource *resource, gboolean is_preferred); const gchar* gwy_resource_class_get_name (GwyResourceClass *klass); GwyInventory* gwy_resource_class_get_inventory (GwyResourceClass *klass); const GwyInventoryItemType* gwy_resource_class_get_item_type (GwyResourceClass *klass); void gwy_resource_use (GwyResource *resource); void gwy_resource_release (GwyResource *resource); gboolean gwy_resource_is_used (GwyResource *resource); void gwy_resource_data_changed (GwyResource *resource); gchar* gwy_resource_build_filename (GwyResource *resource); GString* gwy_resource_dump (GwyResource *resource); GwyResource* gwy_resource_parse (const gchar *text, GType expected_type); void gwy_resource_class_load (GwyResourceClass *klass); gboolean gwy_resource_class_mkdir (GwyResourceClass *klass);
"is-const" gboolean : Read / Write / Construct Only "is-preferred" gboolean : Read / Write "name" gchararray : Read
GwyResource is a base class for various application resources. It defines
common interface: questioning resource name (gwy_resource_get_name()
),
modifiability (gwy_resource_get_is_modifiable()
), loading resources from
files and saving them.
typedef struct _GwyResource GwyResource;
The GwyResource struct contains private data only and should be accessed using the functions below.
typedef struct { GObjectClass parent_class; GwyInventory *inventory; const gchar *name; /* Traits */ GwyInventoryItemType item_type; /* Signals */ void (*data_changed)(GwyResource *resource); /* Virtual table */ void (*use)(GwyResource *resource); void (*release)(GwyResource *resource); void (*dump)(GwyResource *resource, GString *string); GwyResource* (*parse)(const gchar *text, gboolean is_const); void (*reserved1)(void); void (*reserved2)(void); } GwyResourceClass;
Resource class.
GObjectClass parent_class ; |
|
GwyInventory *inventory ; |
Inventory with resources. |
const gchar *name ; |
Resource class name, usable as resource directory name for on-disk resources. |
GwyInventoryItemType item_type ; |
Inventory item type. Most fields are pre-filled, but namely
type and copy must be filled by particular resource type.
|
data_changed () |
"data-changed" signal method. |
use () |
gwy_resource_use() virtual method.
|
release () |
gwy_resource_release() virtual method.
|
dump () |
gwy_resource_dump() virtual method, it only cares about resource
data itself, the envelope is handled by GwyResource.
|
parse () |
gwy_resource_parse() virtual method, in only cares about resource
data itself, the envelope is handled by GwyResource.
|
reserved1 () |
|
reserved2 () |
const gchar* gwy_resource_get_name (GwyResource *resource);
Returns resource name.
resource : |
A resource. |
Returns : | Name of resource . The string is owned by resource and must not
be modfied or freed.
|
gboolean gwy_resource_get_is_modifiable (GwyResource *resource);
Returns whether a resource is modifiable.
gboolean gwy_resource_get_is_preferred (GwyResource *resource);
Returns whether a resource is preferred.
void gwy_resource_set_is_preferred (GwyResource *resource, gboolean is_preferred);
Sets preferability of a resource.
const gchar* gwy_resource_class_get_name (GwyResourceClass *klass);
Gets the name of resource class.
This is an simple identifier usable for example as directory name.
klass : |
A resource class. |
Returns : | Resource class name, as a constant string that must not be modified nor freed. |
GwyInventory* gwy_resource_class_get_inventory (GwyResourceClass *klass);
Gets inventory which holds resources of a resource class.
klass : |
A resource class. |
Returns : | Resource class inventory. |
const GwyInventoryItemType* gwy_resource_class_get_item_type (GwyResourceClass *klass);
Gets inventory item type for a resource class.
klass : |
A resource class. |
Returns : | Inventory item type. |
void gwy_resource_use (GwyResource *resource);
Starts using a resource.
Call to this function is necessary to use a resource properly. It makes the resource to create any auxiliary structures that consume considerable amount of memory and perform other initialization to ready-to-use form.
When a resource is no longer used, it should be released with
gwy_resource_release()
.
In addition, it calls g_object_ref()
on the resource.
Resources usually exist through almost whole program lifetime from
GObject perspective, but from the viewpoint of use this method is the
constructor and gwy_resource_release()
is the destructor.
resource : |
A resource. |
void gwy_resource_release (GwyResource *resource);
Releases a resource.
When the number of resource uses drops to zero, it frees all auxiliary data
and returns back to `latent' form. In addition, it calls g_object_unref()
on it. See gwy_resource_use()
for more.
resource : |
A resource. |
gboolean gwy_resource_is_used (GwyResource *resource);
Tells whether a resource is currently in use.
See gwy_resource_use()
for details.
void gwy_resource_data_changed (GwyResource *resource);
Emits signal "data-changed" on a resource.
Mostly useful in resource implementation.
resource : |
A resource. |
gchar* gwy_resource_build_filename (GwyResource *resource);
Builds file name a resource should be saved to.
If the resource has not been newly created, renamed, or system it was probably loaded from file of the same name.
resource : |
A resource. |
Returns : | Resource file name as a newly allocated string that must be freed by caller. |
GString* gwy_resource_dump (GwyResource *resource);
Dumps a resource to a textual (human readable) form.
resource : |
A resource. |
Returns : | Textual resource representation. |
GwyResource* gwy_resource_parse (const gchar *text, GType expected_type);
Reconstructs a resource from human readable form.
text : |
Textual resource representation. |
expected_type : |
Resource object type. If not 0, only resources of give type are allowed. Zero value means any GwyResource is allowed. |
Returns : | Newly created resource (or NULL ).
|
void gwy_resource_class_load (GwyResourceClass *klass);
Loads resources of a resources class from disk.
Resources are loaded from system directory (and marked constant) and from user directory (marked modifiable).
klass : |
A resource class. |
gboolean gwy_resource_class_mkdir (GwyResourceClass *klass);
Creates directory for user resources if it does not exist.
is-const
" property"is-const" gboolean : Read / Write / Construct Only
Whether a resource is constant (system).
Default value: FALSE
is-preferred
" property"is-preferred" gboolean : Read / Write
Whether a resource is preferred.
Default value: FALSE
void user_function (GwyResource *gwyresource, gpointer user_data) : Run First
The ::data-changed signal is emitted when resource data changes.
gwyresource : |
The GwyResource which received the signal. |
user_data : |
user data set when the signal handler was connected. |