X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstring.c;h=41ac7576223b919920598d154e0eba64a5c46116;hp=df9bacac43260257d832c68ffd805f4e325bcf7c;hb=d00d17d1e06065eb31a699ce59e16ceb6b858029;hpb=bed864a75d2315c344a6e625db66ae9bfbc51e27 diff --git a/types/string.c b/types/string.c index df9bacac..41ac7576 100644 --- a/types/string.c +++ b/types/string.c @@ -1,69 +1,102 @@ /* - * BabelTrace - String Type Converter + * string.c * - * Copyright (c) 2010 Mathieu Desnoyers + * BabelTrace - String Type Converter * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * Copyright 2010, 2011 - Mathieu Desnoyers * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. */ #include #include -#include +#include + +static +struct definition *_string_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index); +static +void _string_definition_free(struct definition *definition); 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 definition *definition) { - struct type_class_string *string_class = - container_of(type_class, struct type_class_string, p); + struct definition_string *string = + container_of(definition, struct definition_string, p); + struct declaration_string *string_declaration = string->declaration; if (fsrc->string_copy == fdest->string_copy) { - fsrc->string_copy(dest, src, string_class); + fsrc->string_copy(dest, src, string_declaration); } else { - /* TODO */ + char *tmp = NULL; + + fsrc->string_read(&tmp, src, string_declaration); + fdest->string_write(dest, tmp, string_declaration); + fsrc->string_free_temp(tmp); } } -void string_type_free(struct type_class_string *string_class) +static +void _string_declaration_free(struct declaration *declaration) +{ + struct declaration_string *string_declaration = + container_of(declaration, struct declaration_string, p); + g_free(string_declaration); +} + +struct declaration_string *string_declaration_new(const char *name) { - g_free(string_class); + struct declaration_string *string_declaration; + + string_declaration = g_new(struct declaration_string, 1); + string_declaration->p.id = CTF_TYPE_STRING; + string_declaration->p.name = g_quark_from_string(name); + string_declaration->p.alignment = CHAR_BIT; + string_declaration->p.copy = string_copy; + string_declaration->p.declaration_free = _string_declaration_free; + string_declaration->p.definition_new = _string_definition_new; + string_declaration->p.definition_free = _string_definition_free; + string_declaration->p.ref = 1; + return string_declaration; } -static void _string_type_free(struct type_class *type_class) +static +struct definition * + _string_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index) { - struct type_class_string *string_class = - container_of(type_class, struct type_class_string, p); - string_type_free(string_class); + struct declaration_string *string_declaration = + container_of(declaration, struct declaration_string, p); + struct definition_string *string; + + 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; + string->value = NULL; + return &string->p; } -struct type_class_string *string_type_new(const char *name) +static +void _string_definition_free(struct definition *definition) { - struct type_class_string *string_class; - int ret; + struct definition_string *string = + container_of(definition, struct definition_string, p); - 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; + declaration_unref(string->p.declaration); + g_free(string->value); + g_free(string); }