X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzrec.cpp;h=fc4bff67d004b5e53faa33d90cd60818165cc6f9;hb=3f60ee904bd42b93051a01ac88fadca365101368;hp=2a0bd6f78450e9e68c9ed7f36c8e2a0c8977785c;hpb=7c6295779d21f882f9d53186c5a751cbf86b6c86;p=yazpp-moved-to-github.git diff --git a/zoom/zrec.cpp b/zoom/zrec.cpp index 2a0bd6f..fc4bff6 100644 --- a/zoom/zrec.cpp +++ b/zoom/zrec.cpp @@ -1,32 +1,57 @@ -// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.5 2002-11-30 22:33:21 mike Exp $ // Z39.50 Record class -#include "zoom++.h" -#include // for strcasecmp() +#include "zoom.h" +#include // for yaz_matchstr() namespace ZOOM { - record::~record() { - if (owner == 0) { - // Must have been clone()d - ZOOM_record_destroy(r); + record::syntax::syntax (value rs): val(rs) {} + + record::syntax::operator string() const { + switch (val) { + case GRS1: return "grs1"; + case SUTRS: return "sutrs"; + case USMARC: return "usmarc"; + case UKMARC: return "ukmarc"; + case XML: return "xml"; + default: break; } + return "unknown"; + } + + bool record::syntax::operator==(const record::syntax &s) const { + return s.val == val; + } + + bool record::syntax::operator==(record::syntax::value rs) const { + return rs == val; + } + + record::syntax::operator record::syntax::value() const { + return val; } - // ### Would this operation be better expressed as a copy constructor? - record *record::clone() const { - // It's tempting just to replace `r' with a clone, and return - // `this', but probably more honest to allocate a new C++ - // record object. - record *rec = new record(0, 0); - if ((rec->r = ZOOM_record_clone(r)) == 0) { - // Presumably an out-of-memory error - throw systemException(); + record::record(resultSet &rs, size_t i): owner(rs) { + if ((r = ZOOM_resultset_record(rs._getYazResultSet(), i)) == 0) { + const char *errmsg; // unused: carries same info as `errcode' + const char *addinfo; + int errcode = ZOOM_connection_error(rs._getYazConnection(), + &errmsg, &addinfo); + throw bib1Exception(errcode, addinfo); } - return rec; + // Memory management is odd here. The ZOOM-C record we've + // just fetched (`r') is owned by the ZOOM-C result-set we + // fetched it from (`rs.rs'), so the underlying (ZOOM-C) + // record is _not_ destroyed when this object is destroyed: + // it's done when the underlying result-set is deleted. + } + + record::~record() { + // Nothing to do -- see comment in constructor } // It's tempting to modify this method just to return either the @@ -39,30 +64,30 @@ namespace ZOOM { const char *syn = ZOOM_record_get(r, "syntax", 0); // These string constants are from yaz/util/oid.c - if (!strcasecmp(syn, "xml")) - return XML; - else if (!strcasecmp(syn, "GRS-1")) - return GRS1; - else if (!strcasecmp(syn, "SUTRS")) - return SUTRS; - else if (!strcasecmp(syn, "USmarc")) - return USMARC; - else if (!strcasecmp(syn, "UKmarc")) - return UKMARC; - else if (!strcasecmp(syn, "XML") || - !strcasecmp(syn, "text-XML") || - !strcasecmp(syn, "application-XML")) - return XML; - - return UNKNOWN; + if (!yaz_matchstr(syn, "xml")) + return syntax::XML; + else if (!yaz_matchstr(syn, "GRS-1")) + return syntax::GRS1; + else if (!yaz_matchstr(syn, "SUTRS")) + return syntax::SUTRS; + else if (!yaz_matchstr(syn, "USmarc")) + return syntax::USMARC; + else if (!yaz_matchstr(syn, "UKmarc")) + return syntax::UKMARC; + else if (!yaz_matchstr(syn, "XML") || + !yaz_matchstr(syn, "text-XML") || + !yaz_matchstr(syn, "application-XML")) + return syntax::XML; + + return syntax::UNKNOWN; } - const char *record::render() const { + string record::render() const { int len; return ZOOM_record_get(r, "render", &len); } - const char *record::rawdata() const { + string record::rawdata() const { int len; return ZOOM_record_get(r, "raw", &len); }