disable-zoom configure option
[yazpp-moved-to-github.git] / zoom / zrec.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.5 2002-11-30 22:33:21 mike Exp $
2
3 // Z39.50 Record class
4
5 #include "zoom.h"
6 #include <yaz/yaz-util.h>       // for yaz_matchstr()
7
8
9 namespace ZOOM {
10     record::syntax::syntax (value rs): val(rs) {}
11
12     record::syntax::operator string() const {
13         switch (val) {
14         case GRS1:   return "grs1";
15         case SUTRS:  return "sutrs";
16         case USMARC: return "usmarc";
17         case UKMARC: return "ukmarc";
18         case XML:    return "xml";
19         default: break;
20         }
21         return "unknown";
22     }
23
24     bool record::syntax::operator==(const record::syntax &s) const {
25         return s.val == val;
26     }
27
28     bool record::syntax::operator==(record::syntax::value rs) const {
29         return rs == val;
30     }
31
32     record::syntax::operator record::syntax::value() const {
33         return val;
34     }
35
36
37     record::record(resultSet &rs, size_t i): owner(rs) {
38         if ((r = ZOOM_resultset_record(rs._getYazResultSet(), i)) == 0) {
39             const char *errmsg; // unused: carries same info as `errcode'
40             const char *addinfo;
41             int errcode = ZOOM_connection_error(rs._getYazConnection(),
42                                                 &errmsg, &addinfo);
43             throw bib1Exception(errcode, addinfo);
44         }
45
46         // Memory management is odd here.  The ZOOM-C record we've
47         // just fetched (`r') is owned by the ZOOM-C result-set we
48         // fetched it from (`rs.rs'), so the underlying (ZOOM-C)
49         // record is _not_ destroyed when this object is destroyed:
50         // it's done when the underlying result-set is deleted.
51     }
52
53     record::~record() {
54         // Nothing to do -- see comment in constructor
55     }
56
57     // It's tempting to modify this method just to return either the
58     // string that ZOOM_record_get("syntax") gives us, or the VAL_*
59     // value from Yaz's OID database, but we'd break the nominal
60     // plug-compatibility of competing C++ binding implementations
61     // if we did that.
62     //
63     record::syntax record::recsyn() const {
64         const char *syn = ZOOM_record_get(r, "syntax", 0);
65
66         // These string constants are from yaz/util/oid.c
67         if (!yaz_matchstr(syn, "xml"))
68             return syntax::XML;
69         else if (!yaz_matchstr(syn, "GRS-1"))
70             return syntax::GRS1;
71         else if (!yaz_matchstr(syn, "SUTRS"))
72             return syntax::SUTRS;
73         else if (!yaz_matchstr(syn, "USmarc"))
74             return syntax::USMARC;
75         else if (!yaz_matchstr(syn, "UKmarc"))
76             return syntax::UKMARC;
77         else if (!yaz_matchstr(syn, "XML") ||
78                  !yaz_matchstr(syn, "text-XML") ||
79                  !yaz_matchstr(syn, "application-XML"))
80             return syntax::XML;
81
82         return syntax::UNKNOWN;
83     }
84
85     string record::render() const {
86         int len;
87         return ZOOM_record_get(r, "render", &len);
88     }
89
90     string record::rawdata() const {
91         int len;
92         return ZOOM_record_get(r, "raw", &len);
93     }
94 }