Fix: remove unused fts.h include
[babeltrace.git] / types / string.c
index f940155399d9a4df2497489d0dc017c4eebd3096..daaeef5aa7514f00762e08b9cb79835663647645 100644 (file)
@@ -3,7 +3,9 @@
  *
  * BabelTrace - String Type Converter
  *
- * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
 #include <babeltrace/format.h>
+#include <babeltrace/types.h>
 
 static
 struct definition *_string_definition_new(struct declaration *declaration,
                                struct definition_scope *parent_scope,
-                               GQuark field_name, int index);
+                               GQuark field_name, int index,
+                               const char *root_name);
 static
 void _string_definition_free(struct definition *definition);
 
@@ -55,22 +59,34 @@ static
 struct definition *
        _string_definition_new(struct declaration *declaration,
                               struct definition_scope *parent_scope,
-                              GQuark field_name, int index)
+                              GQuark field_name, int index,
+                              const char *root_name)
 {
        struct declaration_string *string_declaration =
                container_of(declaration, struct declaration_string, p);
        struct definition_string *string;
+       int ret;
 
        string = g_new(struct definition_string, 1);
        declaration_ref(&string_declaration->p);
        string->p.declaration = declaration;
        string->declaration = string_declaration;
        string->p.ref = 1;
-       string->p.index = index;
+       /*
+        * Use INT_MAX order to ensure that all fields of the parent
+        * scope are seen as being prior to this scope.
+        */
+       string->p.index = root_name ? INT_MAX : index;
        string->p.name = field_name;
+       string->p.path = new_definition_path(parent_scope, field_name,
+                                       root_name);
+       string->p.scope = NULL;
        string->value = NULL;
        string->len = 0;
        string->alloc_len = 0;
+       ret = register_field_definition(field_name, &string->p,
+                                       parent_scope);
+       assert(!ret);
        return &string->p;
 }
 
@@ -84,3 +100,24 @@ void _string_definition_free(struct definition *definition)
        g_free(string->value);
        g_free(string);
 }
+
+enum ctf_string_encoding get_string_encoding(const struct definition *field)
+{
+       struct definition_string *string_definition;
+       const struct declaration_string *string_declaration;
+
+       string_definition = container_of(field, struct definition_string, p);
+       string_declaration = string_definition->declaration;
+
+       return string_declaration->encoding;
+}
+
+char *get_string(const struct definition *field)
+{
+       struct definition_string *string_definition =
+               container_of(field, struct definition_string, p);
+
+       assert(string_definition->value != NULL);
+
+       return string_definition->value;
+}
This page took 0.023136 seconds and 4 git commands to generate.