1 /* 2 * Clone Visitor 3 * 4 * Copyright (C) 2016 Red Hat, Inc. 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or later. 7 * See the COPYING file in the top-level directory. 8 * 9 */ 10 11 #ifndef QAPI_CLONE_VISITOR_H 12 #define QAPI_CLONE_VISITOR_H 13 14 #include "qapi/visitor.h" 15 #include "qapi-visit.h" 16 17 /* 18 * The clone visitor is for direct use only by the QAPI_CLONE() macro; 19 * it requires that the root visit occur on an object, list, or 20 * alternate, and is not usable directly on built-in QAPI types. 21 */ 22 typedef struct QapiCloneVisitor QapiCloneVisitor; 23 24 void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *, 25 void **, Error **)); 26 void qapi_clone_members(void *dst, const void *src, size_t sz, 27 void (*visit_type_members)(Visitor *, void *, 28 Error **)); 29 30 /* 31 * Deep-clone QAPI object @src of the given @type, and return the result. 32 * 33 * Not usable on QAPI scalars (integers, strings, enums), nor on a 34 * QAPI object that references the 'any' type. Safe when @src is NULL. 35 */ 36 #define QAPI_CLONE(type, src) \ 37 ((type *)qapi_clone(src, \ 38 (void (*)(Visitor *, const char *, void**, \ 39 Error **))visit_type_ ## type)) 40 41 /* 42 * Copy deep clones of @type members from @src to @dst. 43 * 44 * Not usable on QAPI scalars (integers, strings, enums), nor on a 45 * QAPI object that references the 'any' type. 46 */ 47 #define QAPI_CLONE_MEMBERS(type, dst, src) \ 48 qapi_clone_members(dst, src, sizeof(type), \ 49 (void (*)(Visitor *, void *, \ 50 Error **))visit_type_ ## type ## _members) 51 52 #endif 53