xref: /openbmc/qemu/include/qapi/clone-visitor.h (revision 37f9e0a2)
1a15fcc3cSEric Blake /*
2a15fcc3cSEric Blake  * Clone Visitor
3a15fcc3cSEric Blake  *
4a15fcc3cSEric Blake  * Copyright (C) 2016 Red Hat, Inc.
5a15fcc3cSEric Blake  *
6a15fcc3cSEric Blake  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7a15fcc3cSEric Blake  * See the COPYING file in the top-level directory.
8a15fcc3cSEric Blake  *
9a15fcc3cSEric Blake  */
10a15fcc3cSEric Blake 
11a15fcc3cSEric Blake #ifndef QAPI_CLONE_VISITOR_H
12a15fcc3cSEric Blake #define QAPI_CLONE_VISITOR_H
13a15fcc3cSEric Blake 
14*37f9e0a2SEric Blake #include "qemu/typedefs.h"
15a15fcc3cSEric Blake #include "qapi/visitor.h"
16*37f9e0a2SEric Blake #include "qapi-visit.h"
17a15fcc3cSEric Blake 
18a15fcc3cSEric Blake /*
19a15fcc3cSEric Blake  * The clone visitor is for direct use only by the QAPI_CLONE() macro;
20a15fcc3cSEric Blake  * it requires that the root visit occur on an object, list, or
21a15fcc3cSEric Blake  * alternate, and is not usable directly on built-in QAPI types.
22a15fcc3cSEric Blake  */
23a15fcc3cSEric Blake typedef struct QapiCloneVisitor QapiCloneVisitor;
24a15fcc3cSEric Blake 
25a15fcc3cSEric Blake void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
26a15fcc3cSEric Blake                                                      void **, Error **));
27a15fcc3cSEric Blake 
28a15fcc3cSEric Blake /*
29a15fcc3cSEric Blake  * Deep-clone QAPI object @src of the given @type, and return the result.
30a15fcc3cSEric Blake  *
31a15fcc3cSEric Blake  * Not usable on QAPI scalars (integers, strings, enums), nor on a
32a15fcc3cSEric Blake  * QAPI object that references the 'any' type.  Safe when @src is NULL.
33a15fcc3cSEric Blake  */
34a15fcc3cSEric Blake #define QAPI_CLONE(type, src)                                           \
35a15fcc3cSEric Blake     ((type *)qapi_clone(src,                                            \
36a15fcc3cSEric Blake                         (void (*)(Visitor *, const char *, void**,      \
37a15fcc3cSEric Blake                                   Error **))visit_type_ ## type))
38a15fcc3cSEric Blake 
39a15fcc3cSEric Blake #endif
40