2 * Copyright (c) 1998-2005, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-z-query.cpp,v 1.20 2006-06-19 13:12:07 adam Exp $
8 #include <yaz/logrpn.h>
9 #include <yazpp/z-query.h>
10 #include <yaz/pquery.h>
13 using namespace yazpp_1;
15 Yaz_Z_Query::Yaz_Z_Query()
17 odr_encode = odr_createmem(ODR_ENCODE);
18 odr_decode = odr_createmem(ODR_DECODE);
19 odr_print = odr_createmem(ODR_PRINT);
23 Yaz_Z_Query::Yaz_Z_Query(const Yaz_Z_Query &q)
25 odr_encode = odr_createmem(ODR_ENCODE);
26 odr_decode = odr_createmem(ODR_DECODE);
27 odr_print = odr_createmem(ODR_PRINT);
30 m_buf = (char*) odr_malloc(odr_encode, m_len);
31 memcpy(m_buf, q.m_buf, m_len);
34 Yaz_Z_Query& Yaz_Z_Query::operator=(const Yaz_Z_Query &q)
38 odr_reset(odr_encode);
47 m_buf = (char*) odr_malloc(odr_encode, m_len);
48 memcpy(m_buf, q.m_buf, m_len);
54 Yaz_Z_Query& Yaz_Z_Query::operator=(const char *rpn)
60 int Yaz_Z_Query::set_rpn(const char *rpn)
63 odr_reset(odr_encode);
64 Z_Query *query = (Z_Query*) odr_malloc(odr_encode, sizeof(*query));
65 query->which = Z_Query_type_1;
66 query->u.type_1 = p_query_rpn(odr_encode, PROTO_Z3950, rpn);
69 if (!z_Query(odr_encode, &query, 0, 0))
71 // z_Query(odr_print, &query, 0, 0);
72 m_buf = odr_getbuf(odr_encode, &m_len, 0);
76 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
79 odr_reset(odr_encode);
80 if (!z_Query(odr_encode, &z_query, 0, 0))
82 m_buf = odr_getbuf(odr_encode, &m_len, 0);
85 Yaz_Z_Query::~Yaz_Z_Query()
87 odr_destroy(odr_encode);
88 odr_destroy(odr_decode);
89 odr_destroy(odr_print);
92 Z_Query *Yaz_Z_Query::get_Z_Query()
97 odr_reset(odr_decode);
98 odr_setbuf(odr_decode, m_buf, m_len, 0);
99 if (!z_Query(odr_decode, &query, 0, 0))
104 void Yaz_Z_Query::print(char *str, int len)
110 odr_setbuf(odr_decode, m_buf, m_len, 0);
111 if (!z_Query(odr_decode, &query, 0, 0))
113 WRBUF wbuf = zquery2pquery(query);
116 if (wrbuf_len(wbuf) > len-1)
118 memcpy(str, wrbuf_buf(wbuf), len-1);
122 strcpy(str, wrbuf_buf(wbuf));
125 odr_reset(odr_decode);
128 int Yaz_Z_Query::match(const Yaz_Z_Query *other)
130 if (m_len != other->m_len)
132 if (!m_buf || !other->m_buf)
134 if (memcmp(m_buf, other->m_buf, m_len))
139 WRBUF Yaz_Z_Query::zquery2pquery(Z_Query *q)
141 WRBUF w = wrbuf_alloc();
142 wrbuf_put_zquery(w, q);
149 * indent-tabs-mode: nil
151 * vim: shiftwidth=4 tabstop=8 expandtab