Added object Yaz_Z_Assoc. Much more functional client.
[yazpp-moved-to-github.git] / src / yaz-z-query.cpp
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Log: yaz-z-query.cpp,v $
7  * Revision 1.2  1999-04-09 11:46:57  adam
8  * Added object Yaz_Z_Assoc. Much more functional client.
9  *
10  * Revision 1.1  1999/03/23 14:17:57  adam
11  * More work on timeout handling. Work on yaz-client.
12  *
13  */
14
15 #include <yaz-z-query.h>
16 #include <pquery.h>
17
18 Yaz_Z_Query::Yaz_Z_Query()
19 {
20     odr_encode = odr_createmem (ODR_ENCODE);
21     odr_decode = odr_createmem (ODR_DECODE);
22 }
23
24 int Yaz_Z_Query::set_rpn (const char *rpn)
25 {
26     buf = 0;
27     odr_reset (odr_encode);
28     Z_Query *query = (Z_Query*) odr_malloc (odr_encode, sizeof(*query));
29     query->which = Z_Query_type_1;
30     query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn);
31     if (!query->u.type_1)
32         return -1;
33     if (!z_Query (odr_encode, &query, 0))
34         return -1;
35     buf = odr_getbuf (odr_encode, &len, 0);
36     return len;
37 }
38
39 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
40 {
41     buf = 0;
42     odr_reset (odr_encode);
43     if (!z_Query (odr_encode, &z_query, 0))
44         return;
45     buf = odr_getbuf (odr_encode, &len, 0);
46 }
47
48 Yaz_Z_Query::~Yaz_Z_Query()
49 {
50     odr_destroy (odr_encode);
51     odr_destroy (odr_decode);
52 }
53
54 Z_Query *Yaz_Z_Query::get_Z_Query ()
55 {
56     Z_Query *query;
57     if (!buf)
58         return 0;
59     odr_setbuf (odr_decode, buf, len, 0);
60     if (!z_Query(odr_decode, &query, 0))
61         return 0;
62     return query;
63 }
64
65 void Yaz_Z_Query::print(char *str, int len)
66 {
67
68 }