disable-zoom configure option
[yazpp-moved-to-github.git] / src / yaz-z-query.cpp
1 /*
2  * Copyright (c) 1998-2001, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: yaz-z-query.cpp,v 1.11 2002-10-09 12:50:26 adam Exp $
6  */
7
8 #include <yaz++/z-query.h>
9 #include <yaz/pquery.h>
10
11 Yaz_Z_Query::Yaz_Z_Query()
12 {
13     odr_encode = odr_createmem (ODR_ENCODE);
14     odr_decode = odr_createmem (ODR_DECODE);
15     odr_print = odr_createmem (ODR_PRINT);
16 }
17
18 int Yaz_Z_Query::set_rpn (const char *rpn)
19 {
20     buf = 0;
21     odr_reset (odr_encode);
22     Z_Query *query = (Z_Query*) odr_malloc (odr_encode, sizeof(*query));
23     query->which = Z_Query_type_1;
24     query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn);
25     if (!query->u.type_1)
26         return -1;
27     if (!z_Query (odr_encode, &query, 0, 0))
28         return -1;
29     // z_Query(odr_print, &query, 0, 0);
30     buf = odr_getbuf (odr_encode, &len, 0);
31     return len;
32 }
33
34 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
35 {
36     buf = 0;
37     odr_reset (odr_encode);
38     if (!z_Query (odr_encode, &z_query, 0, 0))
39         return;
40     buf = odr_getbuf (odr_encode, &len, 0);
41 }
42
43 Yaz_Z_Query::~Yaz_Z_Query()
44 {
45     odr_destroy (odr_encode);
46     odr_destroy (odr_decode);
47     odr_destroy (odr_print);
48 }
49
50 Z_Query *Yaz_Z_Query::get_Z_Query ()
51 {
52     Z_Query *query;
53     if (!buf)
54         return 0;
55     odr_setbuf (odr_decode, buf, len, 0);
56     if (!z_Query(odr_decode, &query, 0, 0))
57         return 0;
58     return query;
59 }
60
61 void Yaz_Z_Query::print(char *str, int len)
62 {
63
64 }
65
66 int Yaz_Z_Query::match(Yaz_Z_Query *other)
67 {
68     if (len != other->len)
69         return 0;
70     if (!buf || !other->buf)
71         return 0;
72     if (memcmp(buf, other->buf, len))
73         return 0;
74     return 1;
75 }