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