1 // $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.8 2005-06-25 15:53:21 adam Exp $
6 #include <yaz/yaz-util.h> // for yaz_matchstr()
10 record::syntax::syntax (value rs): val(rs) {}
12 record::syntax::operator std::string() const {
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";
24 bool record::syntax::operator==(const record::syntax &s) const {
28 bool record::syntax::operator==(record::syntax::value rs) const {
32 record::syntax::operator record::syntax::value() const {
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'
41 int errcode = ZOOM_connection_error(rs._getYazConnection(),
43 throw bib1Exception(errcode, addinfo);
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.
54 // Nothing to do -- see comment in constructor
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
63 record::syntax record::recsyn() const {
64 const char *syn = ZOOM_record_get(r, "syntax", 0);
66 // These string constants are from yaz/util/oid.c
67 if (!yaz_matchstr(syn, "xml"))
69 else if (!yaz_matchstr(syn, "GRS-1"))
71 else if (!yaz_matchstr(syn, "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"))
82 return syntax::UNKNOWN;
85 std::string record::render() const {
87 const char* data = ZOOM_record_get(r, "render", &len);
88 return std::string(data, len);
91 std::string record::rawdata() const {
93 const char* data = ZOOM_record_get(r, "raw", &len);
94 return std::string(data, len);
100 * indent-tabs-mode: nil
102 * vim: shiftwidth=4 tabstop=8 expandtab