2 * Copyright (c) 1998-2007, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-z-query.cpp,v 1.21 2007-03-20 07:54:11 adam Exp $
8 #include <yaz/querytowrbuf.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, size_t len)
110 odr_setbuf(odr_decode, m_buf, m_len, 0);
111 if (!z_Query(odr_decode, &query, 0, 0))
113 WRBUF wbuf = wrbuf_alloc();
114 yaz_query_to_wrbuf(wbuf, query);
115 if (wrbuf_len(wbuf) > len-1)
117 memcpy(str, wrbuf_buf(wbuf), len-1);
121 strcpy(str, wrbuf_cstr(wbuf));
123 odr_reset(odr_decode);
126 int Yaz_Z_Query::match(const Yaz_Z_Query *other)
128 if (m_len != other->m_len)
130 if (!m_buf || !other->m_buf)
132 if (memcmp(m_buf, other->m_buf, m_len))
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab