Scope path: split dynamic scope path
[babeltrace.git] / types / types.c
index 227a1e5e3125976730b79197a987e291e82a1714..e57624fb707b73225b2400d4b8f29d192e828132 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <babeltrace/format.h>
+#include <limits.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -446,17 +447,50 @@ struct definition_scope *
 }
 
 /*
- * Same as new_definition_scope, but reset the scope path.
+ * in: path, out: q (GArray of GQuark)
  */
-struct definition_scope *
-       new_dynamic_definition_scope(struct definition_scope *parent_scope,
-                                    GQuark field_name)
+static
+void append_scope_path(const char *path, GArray *q)
 {
-       struct definition_scope *scope;
+       const char *ptrbegin, *ptrend = path;
+       GQuark quark;
+
+       for (;;) {
+               char *str;
+               size_t len;
+
+               ptrbegin = ptrend;
+               ptrend = strchr(ptrbegin, '.');
+               if (!ptrend)
+                       break;
+               len = ptrend - ptrbegin;
+               /* Don't accept two consecutive dots */
+               assert(len != 0);
+               str = g_new(char, len + 1);     /* include \0 */
+               memcpy(str, ptrbegin, len);
+               str[len] = '\0';
+               quark = g_quark_from_string(str);
+               g_array_append_val(q, quark);
+               g_free(str);
+       }
+       /* last. Check for trailing dot (and discard). */
+       if (ptrbegin[0] != '\0') {
+               quark = g_quark_from_string(ptrbegin);
+               g_array_append_val(q, quark);
+       }
+}
 
-       scope = _new_definition_scope(parent_scope, 1);
-       g_array_index(scope->scope_path, GQuark, 0) = field_name;
-       return scope;
+void set_dynamic_definition_scope(struct definition *definition,
+                                 struct definition_scope *scope,
+                                 const char *root_name)
+{
+       g_array_set_size(scope->scope_path, 0);
+       append_scope_path(root_name, scope->scope_path);
+       /*
+        * Use INT_MAX order to ensure that all fields of the parent
+        * scope are seen as being prior to this scope.
+        */
+       definition->index = INT_MAX;
 }
 
 void free_definition_scope(struct definition_scope *scope)
This page took 0.022918 seconds and 4 git commands to generate.