X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzrec.cpp;fp=zoom%2Fzrec.cpp;h=18e34be431ef823b94451b90f55e6e568579e30f;hb=8e0f7888835eb1a84882b440209ec125ce5856c1;hp=0000000000000000000000000000000000000000;hpb=a1c32cb5086cc24b6ba776379016bf6adad47821;p=yazpp-moved-to-github.git diff --git a/zoom/zrec.cpp b/zoom/zrec.cpp new file mode 100644 index 0000000..18e34be --- /dev/null +++ b/zoom/zrec.cpp @@ -0,0 +1,69 @@ +// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ + +// Z39.50 Record class + +#include "zoom++.h" +#include // for strcasecmp() + + +namespace ZOOM { + record::~record() { + if (owner == 0) { + // Must have been clone()d + ZOOM_record_destroy(r); + } + } + + // ### 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 systemError(); + } + + return rec; + } + + // It's tempting to modify this method just to return either the + // string that ZOOM_record_get("syntax") gives us, or the VAL_* + // value from Yaz's OID database, but we'd break the nominal + // plug-compatibility of competing C++ binding implementations + // if we did that. + // + record::syntax record::recsyn() const { + 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; + } + + const char *record::render() const { + int len; + return ZOOM_record_get(r, "render", &len); + } + + const char *record::rawdata() const { + int len; + return ZOOM_record_get(r, "raw", &len); + } +}