Refine the interactions between the hooks provided by the different modules.
[lttv.git] / ltt / branches / poly / include / lttv / iattribute.h
CommitLineData
dc877563 1#ifndef IATTRIBUTE_H
2#define IATTRIBUTE_H
3
4
5#include <glib-object.h>
6#include <time.h>
7
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. */
12
13typedef GQuark LttvAttributeName;
14
15typedef struct timespec LttvTime;
16
17typedef 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
20} LttvAttributeType;
21
22typedef union LttvAttributeValue {
23 int *v_int;
24 unsigned *v_uint;
25 long *v_long;
26 unsigned long *v_ulong;
27 float *v_float;
28 double *v_double;
29 timespec *v_timespec;
30 gpointer *v_pointer;
31 char **v_string;
32 gobject **v_gobject;
33} LttvAttributeValue;
34
35
36/* GObject interface type macros */
37
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))
44
45
46typedef struct _LttvIattribute LttvIAttribute; /* dummy object */
47typedef struct _LttvIAttributeClass LttvIAttributeClass;
48
49
50struct _LttvIAttributeClass {
51 GTypeInterface parent;
52
53 unsigned int (*get_number) (LttvIAttribute *self);
54
55 gboolean (*named) (LttvIAttribute *self, gboolean *homogeneous);
56
57 LttvAttributeType (*get) (LttvIAttribute *self, unsigned i,
58 LttvAttributeName *name, LttvAttributeValue *v);
59
60 LttvAttributeType (*get_by_name) (LttvIAttribute *self,
61 LttvAttributeName name, LttvAttributeValue *v);
62
63 LttvAttributeValue (*add) (LttvIAttribute *self, LttvAttributeName name,
64 LttvAttributeType t);
65
66 void (*remove) (LttvIAttribute *self, unsigned i);
67
68 void (*remove_by_name) (LttvIAttribute *self,
69 LttvAttributeName name);
70
71 LttvIAttribute* (*create_subdir) (LttvIAttribute *self,
72 LttvAttributeName name);
73};
74
75
76GType lttv_iattribute_get_type(void);
77
78
79/* Total number of attributes */
80
81unsigned int lttv_iattribute_get_number(LttvIAttribute *self);
82
83
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. */
86
87gboolean lttv_iattribute_named(LttvIAttribute *self, gboolean *homogeneous);
88
89
90/* Get the i th attribute along with its type and a pointer to its value. */
91
92LttvAttributeType lttv_iattribute_get(LttvIAttribute *self, unsigned i,
93 LttvAttributeName *name, LttvAttributeValue *v);
94
95
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. */
98
99LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self,
100 LttvAttributeName name, LttvAttributeValue *v);
101
102
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. */
106
107LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self,
108 LttvAttributeName name, LttvAttributeType t);
109
110
111/* Remove an attribute */
112
113void lttv_iattribute_remove(LttvIAttribute *self, unsigned i);
114
115void lttv_iattribute_remove_by_name(LttvIAttribute *self,
116 LttvAttributeName name);
117
118
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. */
123
124LttvIAttribute* lttv_iattribute_create_subdir(LttvIAttribute *self,
125 LttvAttributeName name);
126
127
128/* The remaining utility functions are not part of the LttvIAttribute
129 interface but operate on objects implementing it. */
130
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. */
136
137gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name,
138 LttvAttributeType t, LttvAttributeValue *v);
139
140
141/* Trees of attribute tables may be accessed using a hierarchical path with
142 components separated by /, like in filesystems */
143
144gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, char *path,
145 LttvAttributeType t, LttvAttributeValue *v);
146
147
148/* Shallow and deep copies */
149
150void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest,
151 LttvAttributeValue src);
152
153LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self);
154
155LttvIAttribute *lttv_iattribute_deep_copy(LttvIAttribute *self);
156
157#endif // IATTRIBUTE_H
This page took 0.027696 seconds and 4 git commands to generate.