unnamed attributes not implemented
[lttv.git] / ltt / branches / poly / lttv / lttv / iattribute.h
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 /* FIXME : unnamed attributed not implemented */
20
21 #ifndef IATTRIBUTE_H
22 #define IATTRIBUTE_H
23
24
25 #include <glib-object.h>
26 #include <ltt/time.h>
27
28 /* The content of a data structure may be seen as an array of pairs of
29 attribute name and value. This simple model allows generic navigation
30 and access functions over a wide range of structures. The names are
31 represented by unique integer identifiers, GQuarks. */
32
33 typedef GQuark LttvAttributeName;
34
35 typedef enum _LttvAttributeType {
36 LTTV_INT, LTTV_UINT, LTTV_LONG, LTTV_ULONG, LTTV_FLOAT, LTTV_DOUBLE,
37 LTTV_TIME, LTTV_POINTER, LTTV_STRING, LTTV_GOBJECT, LTTV_NONE
38 } LttvAttributeType;
39
40 typedef union LttvAttributeValue {
41 int *v_int;
42 unsigned *v_uint;
43 long *v_long;
44 unsigned long *v_ulong;
45 float *v_float;
46 double *v_double;
47 LttTime *v_time;
48 gpointer *v_pointer;
49 char **v_string;
50 GObject **v_gobject;
51 } LttvAttributeValue;
52
53
54 /* GObject interface type macros */
55
56 #define LTTV_IATTRIBUTE_TYPE (lttv_iattribute_get_type ())
57 #define LTTV_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_IATTRIBUTE_TYPE, LttvIAttribute))
58 #define LTTV_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
59 #define LTTV_IS_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_IATTRIBUTE_TYPE))
60 #define LTTV_IS_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_IATTRIBUTE_TYPE))
61 #define LTTV_IATTRIBUTE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
62
63
64 typedef struct _LttvIattribute LttvIAttribute; /* dummy object */
65 typedef struct _LttvIAttributeClass LttvIAttributeClass;
66
67
68 struct _LttvIAttributeClass {
69 GTypeInterface parent;
70
71 LttvIAttribute* (*new_attribute) (LttvIAttribute *self);
72
73 unsigned int (*get_number) (LttvIAttribute *self);
74
75 gboolean (*named) (LttvIAttribute *self, gboolean *homogeneous);
76
77 LttvAttributeType (*get) (LttvIAttribute *self, unsigned i,
78 LttvAttributeName *name, LttvAttributeValue *v);
79
80 LttvAttributeType (*get_by_name) (LttvIAttribute *self,
81 LttvAttributeName name, LttvAttributeValue *v);
82
83 LttvAttributeValue (*add) (LttvIAttribute *self, LttvAttributeName name,
84 LttvAttributeType t);
85
86 void (*remove) (LttvIAttribute *self, unsigned i);
87
88 void (*remove_by_name) (LttvIAttribute *self,
89 LttvAttributeName name);
90
91 LttvIAttribute* (*find_subdir) (LttvIAttribute *self,
92 LttvAttributeName name);
93 };
94
95
96 GType lttv_iattribute_get_type(void);
97
98
99 /* Total number of attributes */
100
101 unsigned int lttv_iattribute_get_number(LttvIAttribute *self);
102
103
104 /* Container type. Named (fields in struct or elements in a hash table)
105 or unnamed (elements in an array) attributes, homogeneous type or not. */
106
107 gboolean lttv_iattribute_named(LttvIAttribute *self, gboolean *homogeneous);
108
109
110 /* Get the i th attribute along with its type and a pointer to its value. */
111
112 LttvAttributeType lttv_iattribute_get(LttvIAttribute *self, unsigned i,
113 LttvAttributeName *name, LttvAttributeValue *v);
114
115
116 /* Get the named attribute in the table along with its type and a pointer to
117 its value. If the named attribute does not exist, the type is LTTV_NONE. */
118
119 LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self,
120 LttvAttributeName name, LttvAttributeValue *v);
121
122
123 /* Add an attribute, which must not exist. The name is an empty string for
124 containers with unnamed attributes. Its value is initialized to 0 or NULL
125 and its pointer returned. */
126
127 LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self,
128 LttvAttributeName name, LttvAttributeType t);
129
130
131 /* Remove an attribute */
132
133 void lttv_iattribute_remove(LttvIAttribute *self, unsigned i);
134
135 void lttv_iattribute_remove_by_name(LttvIAttribute *self,
136 LttvAttributeName name);
137
138
139 /* Create an empty iattribute object and add it as an attribute under the
140 specified name, or return an existing iattribute attribute. If an
141 attribute of that name already exists but is not a GObject supporting the
142 iattribute interface, return NULL. */
143
144 LttvIAttribute* lttv_iattribute_find_subdir(LttvIAttribute *self,
145 LttvAttributeName name);
146
147
148 /* The remaining utility functions are not part of the LttvIAttribute
149 interface but operate on objects implementing it. */
150
151 /* Find the named attribute in the table, which must be of the specified type.
152 If it does not exist, it is created with a default value of 0 (NULL for
153 pointer types). Since the address of the value is obtained, it may be
154 changed easily afterwards. The function returns false when the attribute
155 exists but is of incorrect type. */
156
157 gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name,
158 LttvAttributeType t, LttvAttributeValue *v);
159
160
161 /* Trees of attribute tables may be accessed using a hierarchical path with
162 components separated by /, like in filesystems */
163
164 gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, char *path,
165 LttvAttributeType t, LttvAttributeValue *v);
166
167
168 /* Shallow and deep copies */
169
170 void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest,
171 LttvAttributeValue src);
172
173 LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self);
174
175 LttvIAttribute *lttv_iattribute_deep_copy(LttvIAttribute *self);
176
177 #endif // IATTRIBUTE_H
This page took 0.033528 seconds and 4 git commands to generate.