Build fixes.
[babeltrace.git] / types / string.c
index 4d57914112fe3a7aceeed0abda1621168e8d22f5..c6cbb54cbe45ea005c01fd0f4273245f4a5d3847 100644 (file)
@@ -3,7 +3,7 @@
  *
  * BabelTrace - String Type Converter
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010, 2011 - 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/types.h>
+#include <babeltrace/format.h>
+
+static
+struct declaration *_string_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope);
+static
+void _string_declaration_free(struct declaration *declaration);
 
 void string_copy(struct stream_pos *dest, const struct format *fdest, 
                 struct stream_pos *src, const struct format *fsrc,
-                const struct type_class *type_class)
+                struct declaration *declaration)
 {
-       struct type_class_string *string_class =
-               container_of(type_class, struct type_class_string, p);
+       struct declaration_string *string =
+               container_of(declaration, struct declaration_string, p);
+       struct type_string *string_type = string->type;
 
        if (fsrc->string_copy == fdest->string_copy) {
-               fsrc->string_copy(dest, src, string_class);
+               fsrc->string_copy(dest, src, string_type);
        } else {
-               unsigned char *tmp = NULL;
+               char *tmp = NULL;
 
-               fsrc->string_read(&tmp, src, string_class);
-               fdest->string_write(dest, tmp, string_class);
+               fsrc->string_read(&tmp, src, string_type);
+               fdest->string_write(dest, tmp, string_type);
                fsrc->string_free_temp(tmp);
        }
 }
 
-void string_type_free(struct type_class_string *string_class)
+static
+void _string_type_free(struct type *type)
 {
-       g_free(string_class);
+       struct type_string *string_type =
+               container_of(type, struct type_string, p);
+       g_free(string_type);
 }
 
-static void _string_type_free(struct type_class *type_class)
+struct type_string *string_type_new(const char *name)
 {
-       struct type_class_string *string_class =
-               container_of(type_class, struct type_class_string, p);
-       string_type_free(string_class);
+       struct type_string *string_type;
+
+       string_type = g_new(struct type_string, 1);
+       string_type->p.name = g_quark_from_string(name);
+       string_type->p.alignment = CHAR_BIT;
+       string_type->p.copy = string_copy;
+       string_type->p.type_free = _string_type_free;
+       string_type->p.declaration_new = _string_declaration_new;
+       string_type->p.declaration_free = _string_declaration_free;
+       string_type->p.ref = 1;
+       return string_type;
 }
 
-struct type_class_string *string_type_new(const char *name)
+static
+struct declaration *
+       _string_declaration_new(struct type *type,
+                               struct declaration_scope *parent_scope)
 {
-       struct type_class_string *string_class;
-       int ret;
+       struct type_string *string_type =
+               container_of(type, struct type_string, p);
+       struct declaration_string *string;
 
-       string_class = g_new(struct type_class_string, 1);
-       string_class->p.name = g_quark_from_string(name);
-       string_class->p.alignment = CHAR_BIT;
-       string_class->p.copy = string_copy;
-       string_class->p.free = _string_type_free;
-       if (string_class->p.name) {
-               ret = ctf_register_type(&string_class->p);
-               if (ret) {
-                       g_free(string_class);
-                       return NULL;
-               }
-       }
-       return string_class;
+       string = g_new(struct declaration_string, 1);
+       type_ref(&string_type->p);
+       string->p.type = type;
+       string->type = string_type;
+       string->p.ref = 1;
+       string->value = NULL;
+       return &string->p;
+}
+
+static
+void _string_declaration_free(struct declaration *declaration)
+{
+       struct declaration_string *string =
+               container_of(declaration, struct declaration_string, p);
+
+       type_unref(string->p.type);
+       g_free(string->value);
+       g_free(string);
 }
This page took 0.025853 seconds and 4 git commands to generate.