e76ac77ae7620def6537f415642ef8375bd9210d
4 * BabelTrace - String Type Converter
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
24 struct type_string
*_string_type_new(struct type_class
*type_class
,
25 struct declaration_scope
*parent_scope
);
27 void _string_type_free(struct type
*type
);
29 void string_copy(struct stream_pos
*dest
, const struct format
*fdest
,
30 struct stream_pos
*src
, const struct format
*fsrc
,
33 struct type_string
*string
= container_of(type
, struct type_string
, p
);
34 struct type_class_string
*string_class
= string
->_class
;
36 if (fsrc
->string_copy
== fdest
->string_copy
) {
37 fsrc
->string_copy(dest
, src
, string_class
);
41 fsrc
->string_read(&tmp
, src
, string_class
);
42 fdest
->string_write(dest
, tmp
, string_class
);
43 fsrc
->string_free_temp(tmp
);
48 void _string_type_class_free(struct type_class_string
*string_class
)
50 struct type_class_string
*string_class
=
51 container_of(type_class
, struct type_class_string
, p
);
55 struct type_class_string
*
56 string_type_class_new(const char *name
)
58 struct type_class_string
*string_class
;
61 string_class
= g_new(struct type_class_string
, 1);
62 string_class
->p
.name
= g_quark_from_string(name
);
63 string_class
->p
.alignment
= CHAR_BIT
;
64 string_class
->p
.copy
= string_copy
;
65 string_class
->p
.class_free
= _string_type_class_free
;
66 string_class
->p
.type_new
= _string_type_new
;
67 string_class
->p
.type_free
= _string_type_free
;
68 string_class
->p
.ref
= 1;
69 if (string_class
->p
.name
) {
70 ret
= register_type(&string_class
->p
);
80 struct type_string
*_string_type_new(struct type_class
*type_class
,
81 struct declaration_scope
*parent_scope
)
83 struct type_class_string
*string_class
=
84 container_of(type_class
, struct type_class_string
, p
);
85 struct type_string
*string
;
87 string
= g_new(struct type_string
, 1);
88 type_class_ref(&string_class
->p
);
89 string
->p
._class
= string_class
;
96 void _string_type_free(struct type
*type
)
98 struct type_string
*string
=
99 container_of(type
, struct type_string
, p
);
101 type_class_unref(string
->p
._class
);
102 g_free(string
->value
);
This page took 0.03026 seconds and 3 git commands to generate.