Implemented yp2::odr which is a noncopyable wrapper for YAZ' ODR.
[metaproxy-moved-to-github.git] / src / util.cpp
1 /* $Id: util.cpp,v 1.2 2005-10-30 17:13:36 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8
9 #include <yaz/odr.h>
10 #include <yaz/pquery.h>
11 #include "util.hpp"
12
13 bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) {
14     YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
15     
16     Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str());
17     if (!rpn)
18     {
19         yaz_pqf_destroy(pqf_parser);
20         return false;
21     }
22     yaz_pqf_destroy(pqf_parser);
23     Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query));
24     query->which = Z_Query_type_1;
25     query->u.type_1 = rpn;
26     
27     apdu->u.searchRequest->query = query;
28     return true;
29 }
30
31 yp2::odr::odr(int type)
32 {
33     m_odr = odr_createmem(type);
34 }
35
36 yp2::odr::odr()
37 {
38     m_odr = odr_createmem(ODR_ENCODE);
39 }
40
41 yp2::odr::~odr()
42 {
43     odr_destroy(m_odr);
44 }
45
46 yp2::odr::operator ODR() const
47 {
48     return m_odr;
49 }
50
51 /*
52  * Local variables:
53  * c-basic-offset: 4
54  * indent-tabs-mode: nil
55  * c-file-style: "stroustrup"
56  * End:
57  * vim: shiftwidth=4 tabstop=8 expandtab
58  */