1 /* This file is part of the yazpp toolkit.
2 * Copyright (C) 1998-2009 Index Data and Mike Taylor
3 * See the file LICENSE for details.
6 #include <yaz/querytowrbuf.h>
7 #include <yazpp/z-query.h>
8 #include <yaz/pquery.h>
11 using namespace yazpp_1;
13 Yaz_Z_Query::Yaz_Z_Query()
15 odr_encode = odr_createmem(ODR_ENCODE);
16 odr_decode = odr_createmem(ODR_DECODE);
17 odr_print = odr_createmem(ODR_PRINT);
21 Yaz_Z_Query::Yaz_Z_Query(const Yaz_Z_Query &q)
23 odr_encode = odr_createmem(ODR_ENCODE);
24 odr_decode = odr_createmem(ODR_DECODE);
25 odr_print = odr_createmem(ODR_PRINT);
28 m_buf = (char*) odr_malloc(odr_encode, m_len);
29 memcpy(m_buf, q.m_buf, m_len);
32 Yaz_Z_Query& Yaz_Z_Query::operator=(const Yaz_Z_Query &q)
36 odr_reset(odr_encode);
45 m_buf = (char*) odr_malloc(odr_encode, m_len);
46 memcpy(m_buf, q.m_buf, m_len);
52 Yaz_Z_Query& Yaz_Z_Query::operator=(const char *rpn)
58 int Yaz_Z_Query::set_rpn(const char *rpn)
61 odr_reset(odr_encode);
62 Z_Query *query = (Z_Query*) odr_malloc(odr_encode, sizeof(*query));
63 query->which = Z_Query_type_1;
64 query->u.type_1 = p_query_rpn(odr_encode, rpn);
67 if (!z_Query(odr_encode, &query, 0, 0))
69 // z_Query(odr_print, &query, 0, 0);
70 m_buf = odr_getbuf(odr_encode, &m_len, 0);
74 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
77 odr_reset(odr_encode);
78 if (!z_Query(odr_encode, &z_query, 0, 0))
80 m_buf = odr_getbuf(odr_encode, &m_len, 0);
83 Yaz_Z_Query::~Yaz_Z_Query()
85 odr_destroy(odr_encode);
86 odr_destroy(odr_decode);
87 odr_destroy(odr_print);
90 Z_Query *Yaz_Z_Query::get_Z_Query()
95 odr_reset(odr_decode);
96 odr_setbuf(odr_decode, m_buf, m_len, 0);
97 if (!z_Query(odr_decode, &query, 0, 0))
102 void Yaz_Z_Query::print(char *str, size_t len)
108 odr_setbuf(odr_decode, m_buf, m_len, 0);
109 if (!z_Query(odr_decode, &query, 0, 0))
111 WRBUF wbuf = wrbuf_alloc();
112 yaz_query_to_wrbuf(wbuf, query);
113 if (wrbuf_len(wbuf) > len-1)
115 memcpy(str, wrbuf_buf(wbuf), len-1);
119 strcpy(str, wrbuf_cstr(wbuf));
121 odr_reset(odr_decode);
124 int Yaz_Z_Query::match(const Yaz_Z_Query *other)
126 if (m_len != other->m_len)
128 if (!m_buf || !other->m_buf)
130 if (memcmp(m_buf, other->m_buf, m_len))
138 * c-file-style: "Stroustrup"
139 * indent-tabs-mode: nil
141 * vim: shiftwidth=4 tabstop=8 expandtab