5 #include <glib-object.h>
8 /* The content of a data structure may be seen as an array of pairs of
9 attribute name and value. This simple model allows generic navigation
10 and access functions over a wide range of structures. The names are
11 represented by unique integer identifiers, GQuarks. */
13 typedef GQuark LttvAttributeName
;
15 typedef enum _LttvAttributeType
{
16 LTTV_INT
, LTTV_UINT
, LTTV_LONG
, LTTV_ULONG
, LTTV_FLOAT
, LTTV_DOUBLE
,
17 LTTV_TIME
, LTTV_POINTER
, LTTV_STRING
, LTTV_GOBJECT
, LTTV_NONE
20 typedef union LttvAttributeValue
{
24 unsigned long *v_ulong
;
34 /* GObject interface type macros */
36 #define LTTV_IATTRIBUTE_TYPE (lttv_iattribute_get_type ())
37 #define LTTV_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_IATTRIBUTE_TYPE, LttvIAttribute))
38 #define LTTV_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
39 #define LTTV_IS_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_IATTRIBUTE_TYPE))
40 #define LTTV_IS_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_IATTRIBUTE_TYPE))
41 #define LTTV_IATTRIBUTE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
44 typedef struct _LttvIattribute LttvIAttribute
; /* dummy object */
45 typedef struct _LttvIAttributeClass LttvIAttributeClass
;
48 struct _LttvIAttributeClass
{
49 GTypeInterface parent
;
51 unsigned int (*get_number
) (LttvIAttribute
*self
);
53 gboolean (*named
) (LttvIAttribute
*self
, gboolean
*homogeneous
);
55 LttvAttributeType (*get
) (LttvIAttribute
*self
, unsigned i
,
56 LttvAttributeName
*name
, LttvAttributeValue
*v
);
58 LttvAttributeType (*get_by_name
) (LttvIAttribute
*self
,
59 LttvAttributeName name
, LttvAttributeValue
*v
);
61 LttvAttributeValue (*add
) (LttvIAttribute
*self
, LttvAttributeName name
,
64 void (*remove
) (LttvIAttribute
*self
, unsigned i
);
66 void (*remove_by_name
) (LttvIAttribute
*self
,
67 LttvAttributeName name
);
69 LttvIAttribute
* (*find_subdir
) (LttvIAttribute
*self
,
70 LttvAttributeName name
);
74 GType
lttv_iattribute_get_type(void);
77 /* Total number of attributes */
79 unsigned int lttv_iattribute_get_number(LttvIAttribute
*self
);
82 /* Container type. Named (fields in struct or elements in a hash table)
83 or unnamed (elements in an array) attributes, homogeneous type or not. */
85 gboolean
lttv_iattribute_named(LttvIAttribute
*self
, gboolean
*homogeneous
);
88 /* Get the i th attribute along with its type and a pointer to its value. */
90 LttvAttributeType
lttv_iattribute_get(LttvIAttribute
*self
, unsigned i
,
91 LttvAttributeName
*name
, LttvAttributeValue
*v
);
94 /* Get the named attribute in the table along with its type and a pointer to
95 its value. If the named attribute does not exist, the type is LTTV_NONE. */
97 LttvAttributeType
lttv_iattribute_get_by_name(LttvIAttribute
*self
,
98 LttvAttributeName name
, LttvAttributeValue
*v
);
101 /* Add an attribute, which must not exist. The name is an empty string for
102 containers with unnamed attributes. Its value is initialized to 0 or NULL
103 and its pointer returned. */
105 LttvAttributeValue
lttv_iattribute_add(LttvIAttribute
*self
,
106 LttvAttributeName name
, LttvAttributeType t
);
109 /* Remove an attribute */
111 void lttv_iattribute_remove(LttvIAttribute
*self
, unsigned i
);
113 void lttv_iattribute_remove_by_name(LttvIAttribute
*self
,
114 LttvAttributeName name
);
117 /* Create an empty iattribute object and add it as an attribute under the
118 specified name, or return an existing iattribute attribute. If an
119 attribute of that name already exists but is not a GObject supporting the
120 iattribute interface, return NULL. */
122 LttvIAttribute
* lttv_iattribute_find_subdir(LttvIAttribute
*self
,
123 LttvAttributeName name
);
126 /* The remaining utility functions are not part of the LttvIAttribute
127 interface but operate on objects implementing it. */
129 /* Find the named attribute in the table, which must be of the specified type.
130 If it does not exist, it is created with a default value of 0 (NULL for
131 pointer types). Since the address of the value is obtained, it may be
132 changed easily afterwards. The function returns false when the attribute
133 exists but is of incorrect type. */
135 gboolean
lttv_iattribute_find(LttvIAttribute
*self
, LttvAttributeName name
,
136 LttvAttributeType t
, LttvAttributeValue
*v
);
139 /* Trees of attribute tables may be accessed using a hierarchical path with
140 components separated by /, like in filesystems */
142 gboolean
lttv_iattribute_find_by_path(LttvIAttribute
*self
, char *path
,
143 LttvAttributeType t
, LttvAttributeValue
*v
);
146 /* Shallow and deep copies */
148 void lttv_iattribute_copy_value(LttvAttributeType t
, LttvAttributeValue dest
,
149 LttvAttributeValue src
);
151 LttvIAttribute
*lttv_iattribute_shallow_copy(LttvIAttribute
*self
);
153 LttvIAttribute
*lttv_iattribute_deep_copy(LttvIAttribute
*self
);
155 #endif // IATTRIBUTE_H