From: Adam Dickmeiss Date: Thu, 26 Mar 2009 10:27:24 +0000 (+0100) Subject: Rework copy/clone of ASN.1 type utilities. X-Git-Tag: v3.0.45~10 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=de9864f98c5fec785fb0e4cb05cf9db1e7a7e4af Rework copy/clone of ASN.1 type utilities. The copy/clone of a type, such as Z_RPNQuery, is implemented as a macro. The following funcions are defined at this stage: yaz_clone_z_{Query,RPNQuery,NamePlusRecord}. --- diff --git a/include/yaz/copy_types.h b/include/yaz/copy_types.h index 882a0fb..2118144 100644 --- a/include/yaz/copy_types.h +++ b/include/yaz/copy_types.h @@ -43,6 +43,15 @@ Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out); YAZ_EXPORT Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out); +YAZ_EXPORT +Z_RPNQuery *yaz_clone_z_RPNQuery(Z_RPNQuery *q, NMEM out); + +YAZ_EXPORT +Z_Query *yaz_clone_z_Query(Z_Query *q, NMEM out); + +YAZ_EXPORT +Z_NamePlusRecord *yaz_clone_z_NamePlusRecord(Z_NamePlusRecord *s, NMEM out); + YAZ_END_CDECL #endif diff --git a/src/copy_types.c b/src/copy_types.c index 03a1c91..d6d6c55 100644 --- a/src/copy_types.c +++ b/src/copy_types.c @@ -9,53 +9,45 @@ #include +/** macro clone_z_type copies a given ASN.1 type */ +#define clone_z_type(x) \ +Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \ +{ \ + Z_##x *q1 = 0; \ + ODR enc = odr_createmem(ODR_ENCODE); \ + ODR dec = odr_createmem(ODR_DECODE); \ + if (!z_##x(enc, &q, 0, 0)) \ + return 0; \ + else \ + { \ + int len; \ + char *buf = odr_getbuf(enc, &len, 0); \ + if (buf) \ + { \ + odr_setbuf(dec, buf, len, 0); \ + z_##x(dec, &q1, 0, 0); \ + nmem_transfer(nmem_out, dec->mem); \ + } \ + } \ + odr_destroy(enc); \ + odr_destroy(dec); \ + return q1; \ +} + +clone_z_type(NamePlusRecord) +clone_z_type(RPNQuery) +clone_z_type(Query) + Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out) { - Z_RPNQuery *q1 = 0; - ODR enc = odr_createmem(ODR_ENCODE); - ODR dec = odr_createmem(ODR_DECODE); - if (!z_RPNQuery(enc, &q, 0, 0)) - return 0; - else - { - int len; - char *buf = odr_getbuf(enc, &len, 0); - if (buf) - { - odr_setbuf(dec, buf, len, 0); - z_RPNQuery(dec, &q1, 0, 0); - nmem_transfer(out->mem, dec->mem); - } - } - odr_destroy(enc); - odr_destroy(dec); - return q1; + return yaz_clone_z_RPNQuery(q, out->mem); } Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out) { - Z_Query *q1 = 0; - ODR enc = odr_createmem(ODR_ENCODE); - ODR dec = odr_createmem(ODR_DECODE); - if (!z_Query(enc, &q, 0, 0)) - return 0; - else - { - int len; - char *buf = odr_getbuf(enc, &len, 0); - if (buf) - { - odr_setbuf(dec, buf, len, 0); - z_Query(dec, &q1, 0, 0); - nmem_transfer(out->mem, dec->mem); - } - } - odr_destroy(enc); - odr_destroy(dec); - return q1; + return yaz_clone_z_Query(q, out->mem); } - /* * Local variables: * c-basic-offset: 4