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 14a15fcc3cSEric Blake #include "qapi/visitor.h" 15a15fcc3cSEric Blake 16a15fcc3cSEric Blake /* 17a15fcc3cSEric Blake * The clone visitor is for direct use only by the QAPI_CLONE() macro; 18a15fcc3cSEric Blake * it requires that the root visit occur on an object, list, or 19a15fcc3cSEric Blake * alternate, and is not usable directly on built-in QAPI types. 20a15fcc3cSEric Blake */ 21a15fcc3cSEric Blake typedef struct QapiCloneVisitor QapiCloneVisitor; 22a15fcc3cSEric Blake 23*012d4c96SMarkus Armbruster void *qapi_clone(const void *src, bool (*visit_type)(Visitor *, const char *, 24a15fcc3cSEric Blake void **, Error **)); 254626a19cSMarkus Armbruster void qapi_clone_members(void *dst, const void *src, size_t sz, 26*012d4c96SMarkus Armbruster bool (*visit_type_members)(Visitor *, void *, 274626a19cSMarkus Armbruster Error **)); 28a15fcc3cSEric Blake 29a15fcc3cSEric Blake /* 30a15fcc3cSEric Blake * Deep-clone QAPI object @src of the given @type, and return the result. 31a15fcc3cSEric Blake * 32a15fcc3cSEric Blake * Not usable on QAPI scalars (integers, strings, enums), nor on a 33a15fcc3cSEric Blake * QAPI object that references the 'any' type. Safe when @src is NULL. 34a15fcc3cSEric Blake */ 35a15fcc3cSEric Blake #define QAPI_CLONE(type, src) \ 36a15fcc3cSEric Blake ((type *)qapi_clone(src, \ 37*012d4c96SMarkus Armbruster (bool (*)(Visitor *, const char *, void **, \ 38a15fcc3cSEric Blake Error **))visit_type_ ## type)) 39a15fcc3cSEric Blake 404626a19cSMarkus Armbruster /* 414626a19cSMarkus Armbruster * Copy deep clones of @type members from @src to @dst. 424626a19cSMarkus Armbruster * 434626a19cSMarkus Armbruster * Not usable on QAPI scalars (integers, strings, enums), nor on a 444626a19cSMarkus Armbruster * QAPI object that references the 'any' type. 454626a19cSMarkus Armbruster */ 464626a19cSMarkus Armbruster #define QAPI_CLONE_MEMBERS(type, dst, src) \ 474626a19cSMarkus Armbruster qapi_clone_members(dst, src, sizeof(type), \ 48*012d4c96SMarkus Armbruster (bool (*)(Visitor *, void *, \ 494626a19cSMarkus Armbruster Error **))visit_type_ ## type ## _members) 504626a19cSMarkus Armbruster 51a15fcc3cSEric Blake #endif 52