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 struct timespec LttvTime
;
17 typedef enum _LttvAttributeType
{
18 LTTV_INT
, LTTV_UINT
, LTTV_LONG
, LTTV_ULONG
, LTTV_FLOAT
, LTTV_DOUBLE
,
19 LTTV_TIME
, LTTV_POINTER
, LTTV_STRING
, LTTV_GOBJECT
, LTTV_NONE
22 typedef union LttvAttributeValue
{
26 unsigned long *v_ulong
;
36 /* GObject interface type macros */
38 #define LTTV_IATTRIBUTE_TYPE (lttv_iattribute_get_type ())
39 #define LTTV_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_IATTRIBUTE_TYPE, LttvIAttribute))
40 #define LTTV_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
41 #define LTTV_IS_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_IATTRIBUTE_TYPE))
42 #define LTTV_IS_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_IATTRIBUTE_TYPE))
43 #define LTTV_IATTRIBUTE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
46 typedef struct _LttvIattribute LttvIAttribute
; /* dummy object */
47 typedef struct _LttvIAttributeClass LttvIAttributeClass
;
50 struct _LttvIAttributeClass
{
51 GTypeInterface parent
;
53 unsigned int (*get_number
) (LttvIAttribute
*self
);
55 gboolean (*named
) (LttvIAttribute
*self
, gboolean
*homogeneous
);
57 LttvAttributeType (*get
) (LttvIAttribute
*self
, unsigned i
,
58 LttvAttributeName
*name
, LttvAttributeValue
*v
);
60 LttvAttributeType (*get_by_name
) (LttvIAttribute
*self
,
61 LttvAttributeName name
, LttvAttributeValue
*v
);
63 LttvAttributeValue (*add
) (LttvIAttribute
*self
, LttvAttributeName name
,
66 void (*remove
) (LttvIAttribute
*self
, unsigned i
);
68 void (*remove_by_name
) (LttvIAttribute
*self
,
69 LttvAttributeName name
);
71 LttvIAttribute
* (*create_subdir
) (LttvIAttribute
*self
,
72 LttvAttributeName name
);
76 GType
lttv_iattribute_get_type(void);
79 /* Total number of attributes */
81 unsigned int lttv_iattribute_get_number(LttvIAttribute
*self
);
84 /* Container type. Named (fields in struct or elements in a hash table)
85 or unnamed (elements in an array) attributes, homogeneous type or not. */
87 gboolean
lttv_iattribute_named(LttvIAttribute
*self
, gboolean
*homogeneous
);
90 /* Get the i th attribute along with its type and a pointer to its value. */
92 LttvAttributeType
lttv_iattribute_get(LttvIAttribute
*self
, unsigned i
,
93 LttvAttributeName
*name
, LttvAttributeValue
*v
);
96 /* Get the named attribute in the table along with its type and a pointer to
97 its value. If the named attribute does not exist, the type is LTTV_NONE. */
99 LttvAttributeType
lttv_iattribute_get_by_name(LttvIAttribute
*self
,
100 LttvAttributeName name
, LttvAttributeValue
*v
);
103 /* Add an attribute, which must not exist. The name is an empty string for
104 containers with unnamed attributes. Its value is initialized to 0 or NULL
105 and its pointer returned. */
107 LttvAttributeValue
lttv_iattribute_add(LttvIAttribute
*self
,
108 LttvAttributeName name
, LttvAttributeType t
);
111 /* Remove an attribute */
113 void lttv_iattribute_remove(LttvIAttribute
*self
, unsigned i
);
115 void lttv_iattribute_remove_by_name(LttvIAttribute
*self
,
116 LttvAttributeName name
);
119 /* Create an empty iattribute object and add it as an attribute under the
120 specified name, or return an existing iattribute attribute. If an
121 attribute of that name already exists but is not a GObject supporting the
122 iattribute interface, return NULL. */
124 LttvIAttribute
* lttv_iattribute_create_subdir(LttvIAttribute
*self
,
125 LttvAttributeName name
);
128 /* The remaining utility functions are not part of the LttvIAttribute
129 interface but operate on objects implementing it. */
131 /* Find the named attribute in the table, which must be of the specified type.
132 If it does not exist, it is created with a default value of 0 (NULL for
133 pointer types). Since the address of the value is obtained, it may be
134 changed easily afterwards. The function returns false when the attribute
135 exists but is of incorrect type. */
137 gboolean
lttv_iattribute_find(LttvIAttribute
*self
, LttvAttributeName name
,
138 LttvAttributeType t
, LttvAttributeValue
*v
);
141 /* Trees of attribute tables may be accessed using a hierarchical path with
142 components separated by /, like in filesystems */
144 gboolean
lttv_iattribute_find_by_path(LttvIAttribute
*self
, char *path
,
145 LttvAttributeType t
, LttvAttributeValue
*v
);
148 /* Shallow and deep copies */
150 void lttv_iattribute_copy_value(LttvAttributeType t
, LttvAttributeValue dest
,
151 LttvAttributeValue src
);
153 LttvIAttribute
*lttv_iattribute_shallow_copy(LttvIAttribute
*self
);
155 LttvIAttribute
*lttv_iattribute_deep_copy(LttvIAttribute
*self
);
157 #endif // IATTRIBUTE_H