Rename internal func yaz_use_attribute_create
[yaz-moved-to-github.git] / src / copy_types.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data
3  * See the file LICENSE for details.
4  */
5 /** \file copy_types.c
6     \brief Copies various Z39.50 types
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <yaz/copy_types.h>
13
14 /** macro clone_z_type copies a given ASN.1 type */
15 #define clone_z_type(x) \
16 Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \
17 { \
18     Z_##x *q1 = 0; \
19     ODR enc = odr_createmem(ODR_ENCODE); \
20     ODR dec = odr_createmem(ODR_DECODE); \
21     if (z_##x(enc, &q, 0, 0)) \
22     { \
23         int len; \
24         char *buf = odr_getbuf(enc, &len, 0); \
25         if (buf) \
26         { \
27             odr_setbuf(dec, buf, len, 0); \
28             z_##x(dec, &q1, 0, 0); \
29             nmem_transfer(nmem_out, dec->mem);  \
30         } \
31     } \
32     odr_destroy(enc); \
33     odr_destroy(dec); \
34     return q1; \
35 }
36
37 clone_z_type(NamePlusRecord)
38 clone_z_type(RPNQuery)
39 clone_z_type(Query)
40 clone_z_type(RecordComposition)
41
42 Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out)
43 {
44     return yaz_clone_z_RPNQuery(q, out->mem);
45 }
46
47 Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out)
48 {
49     return yaz_clone_z_Query(q, out->mem);
50 }
51
52 /*
53  * Local variables:
54  * c-basic-offset: 4
55  * c-file-style: "Stroustrup"
56  * indent-tabs-mode: nil
57  * End:
58  * vim: shiftwidth=4 tabstop=8 expandtab
59  */
60