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 declaration
*_string_declaration_new(struct type
*type
,
25 struct declaration_scope
*parent_scope
);
27 void _string_declaration_free(struct declaration
*declaration
);
29 void string_copy(struct stream_pos
*dest
, const struct format
*fdest
,
30 struct stream_pos
*src
, const struct format
*fsrc
,
31 struct declaration
*declaration
)
33 struct declaration_string
*string
=
34 container_of(declaration
, struct declaration_string
, p
);
35 struct type_string
*string_type
= string
->type
;
37 if (fsrc
->string_copy
== fdest
->string_copy
) {
38 fsrc
->string_copy(dest
, src
, string_type
);
42 fsrc
->string_read(&tmp
, src
, string_type
);
43 fdest
->string_write(dest
, tmp
, string_type
);
44 fsrc
->string_free_temp(tmp
);
49 void _string_type_free(struct type
*type
)
51 struct type_string
*string_type
=
52 container_of(type
, struct type_string
, p
);
56 struct type_string
*string_type_new(const char *name
)
58 struct type_string
*string_type
;
60 string_type
= g_new(struct type_string
, 1);
61 string_type
->p
.name
= g_quark_from_string(name
);
62 string_type
->p
.alignment
= CHAR_BIT
;
63 string_type
->p
.copy
= string_copy
;
64 string_type
->p
.type_free
= _string_type_free
;
65 string_type
->p
.declaration_new
= _string_declaration_new
;
66 string_type
->p
.declaration_free
= _string_declaration_free
;
67 string_type
->p
.ref
= 1;
73 _string_declaration_new(struct type
*type
,
74 struct declaration_scope
*parent_scope
)
76 struct type_string
*string_type
=
77 container_of(type
, struct type_string
, p
);
78 struct declaration_string
*string
;
80 string
= g_new(struct declaration_string
, 1);
81 type_ref(&string_type
->p
);
82 string
->p
.type
= type
;
83 string
->type
= string_type
;
90 void _string_declaration_free(struct declaration
*declaration
)
92 struct declaration_string
*string
=
93 container_of(declaration
, struct declaration_string
, p
);
95 type_unref(string
->p
.type
);
96 g_free(string
->value
);
This page took 0.032962 seconds and 4 git commands to generate.