1 /* This file is part of the yazpp toolkit.
2 * Copyright (C) 1998-2012 Index Data and Mike Taylor
3 * See the file LICENSE for details.
9 #include <yaz/querytowrbuf.h>
10 #include <yazpp/z-query.h>
11 #include <yaz/pquery.h>
14 using namespace yazpp_1;
16 Yaz_Z_Query::Yaz_Z_Query()
18 odr_encode = odr_createmem(ODR_ENCODE);
19 odr_decode = odr_createmem(ODR_DECODE);
20 odr_print = odr_createmem(ODR_PRINT);
24 Yaz_Z_Query::Yaz_Z_Query(const Yaz_Z_Query &q)
26 odr_encode = odr_createmem(ODR_ENCODE);
27 odr_decode = odr_createmem(ODR_DECODE);
28 odr_print = odr_createmem(ODR_PRINT);
31 m_buf = (char*) odr_malloc(odr_encode, m_len);
32 memcpy(m_buf, q.m_buf, m_len);
35 Yaz_Z_Query& Yaz_Z_Query::operator=(const Yaz_Z_Query &q)
39 odr_reset(odr_encode);
48 m_buf = (char*) odr_malloc(odr_encode, m_len);
49 memcpy(m_buf, q.m_buf, m_len);
55 Yaz_Z_Query& Yaz_Z_Query::operator=(const char *rpn)
61 int Yaz_Z_Query::set_rpn(const char *rpn)
64 odr_reset(odr_encode);
65 Z_Query *query = (Z_Query*) odr_malloc(odr_encode, sizeof(*query));
66 query->which = Z_Query_type_1;
67 query->u.type_1 = p_query_rpn(odr_encode, rpn);
70 if (!z_Query(odr_encode, &query, 0, 0))
72 // z_Query(odr_print, &query, 0, 0);
73 m_buf = odr_getbuf(odr_encode, &m_len, 0);
77 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
80 odr_reset(odr_encode);
81 if (!z_Query(odr_encode, &z_query, 0, 0))
83 m_buf = odr_getbuf(odr_encode, &m_len, 0);
86 Yaz_Z_Query::~Yaz_Z_Query()
88 odr_destroy(odr_encode);
89 odr_destroy(odr_decode);
90 odr_destroy(odr_print);
93 Z_Query *Yaz_Z_Query::get_Z_Query()
98 odr_reset(odr_decode);
99 odr_setbuf(odr_decode, m_buf, m_len, 0);
100 if (!z_Query(odr_decode, &query, 0, 0))
105 void Yaz_Z_Query::print(char *str, size_t len)
111 odr_setbuf(odr_decode, m_buf, m_len, 0);
112 if (!z_Query(odr_decode, &query, 0, 0))
114 WRBUF wbuf = wrbuf_alloc();
115 yaz_query_to_wrbuf(wbuf, query);
116 if (wrbuf_len(wbuf) > len-1)
118 memcpy(str, wrbuf_buf(wbuf), len-1);
122 strcpy(str, wrbuf_cstr(wbuf));
124 odr_reset(odr_decode);
127 int Yaz_Z_Query::match(const Yaz_Z_Query *other)
129 if (m_len != other->m_len)
131 if (!m_buf || !other->m_buf)
133 if (memcmp(m_buf, other->m_buf, m_len))
141 * c-file-style: "Stroustrup"
142 * indent-tabs-mode: nil
144 * vim: shiftwidth=4 tabstop=8 expandtab