2 * String printing Visitor
4 * Copyright Red Hat, Inc. 2012
6 * Author: Paolo Bonzini <pbonzini@redhat.com>
8 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
9 * See the COPYING.LIB file in the top-level directory.
13 #include "qemu-common.h"
14 #include "string-output-visitor.h"
15 #include "qapi/qapi-visit-impl.h"
18 struct StringOutputVisitor
24 static void string_output_set(StringOutputVisitor
*sov
, char *string
)
30 static void print_type_int(Visitor
*v
, int64_t *obj
, const char *name
,
33 StringOutputVisitor
*sov
= DO_UPCAST(StringOutputVisitor
, visitor
, v
);
34 string_output_set(sov
, g_strdup_printf("%lld", (long long) *obj
));
37 static void print_type_bool(Visitor
*v
, bool *obj
, const char *name
,
40 StringOutputVisitor
*sov
= DO_UPCAST(StringOutputVisitor
, visitor
, v
);
41 string_output_set(sov
, g_strdup(*obj
? "true" : "false"));
44 static void print_type_str(Visitor
*v
, char **obj
, const char *name
,
47 StringOutputVisitor
*sov
= DO_UPCAST(StringOutputVisitor
, visitor
, v
);
48 string_output_set(sov
, g_strdup(*obj
? *obj
: ""));
51 static void print_type_number(Visitor
*v
, double *obj
, const char *name
,
54 StringOutputVisitor
*sov
= DO_UPCAST(StringOutputVisitor
, visitor
, v
);
55 string_output_set(sov
, g_strdup_printf("%g", *obj
));
58 char *string_output_get_string(StringOutputVisitor
*sov
)
60 char *string
= sov
->string
;
65 Visitor
*string_output_get_visitor(StringOutputVisitor
*sov
)
70 void string_output_visitor_cleanup(StringOutputVisitor
*sov
)
76 StringOutputVisitor
*string_output_visitor_new(void)
78 StringOutputVisitor
*v
;
80 v
= g_malloc0(sizeof(*v
));
82 v
->visitor
.type_enum
= output_type_enum
;
83 v
->visitor
.type_int
= print_type_int
;
84 v
->visitor
.type_bool
= print_type_bool
;
85 v
->visitor
.type_str
= print_type_str
;
86 v
->visitor
.type_number
= print_type_number
;