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