Added ZOOM.
[yazpp-moved-to-github.git] / zoom / zrec.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $
2
3 // Z39.50 Record class
4
5 #include "zoom++.h"
6 #include <string.h>             // for strcasecmp()
7
8
9 namespace ZOOM {
10     record::~record() {
11         if (owner == 0) {
12             // Must have been clone()d
13             ZOOM_record_destroy(r);
14         }
15     }
16
17     // ### Would this operation be better expressed as a copy constructor?
18     record *record::clone() const {
19         // It's tempting just to replace `r' with a clone, and return
20         // `this', but probably more honest to allocate a new C++
21         // record object.
22
23         record *rec = new record(0, 0);
24         if ((rec->r = ZOOM_record_clone(r)) == 0) {
25             // Presumably an out-of-memory error
26             throw systemError();
27         }
28
29         return rec;
30     }
31
32     // It's tempting to modify this method just to return either the
33     // string that ZOOM_record_get("syntax") gives us, or the VAL_*
34     // value from Yaz's OID database, but we'd break the nominal
35     // plug-compatibility of competing C++ binding implementations
36     // if we did that.
37     //
38     record::syntax record::recsyn() const {
39         const char *syn = ZOOM_record_get(r, "syntax", 0);
40
41         // These string constants are from yaz/util/oid.c
42         if (!strcasecmp(syn, "xml"))
43             return XML;
44         else if (!strcasecmp(syn, "GRS-1"))
45             return GRS1;
46         else if (!strcasecmp(syn, "SUTRS"))
47             return SUTRS;
48         else if (!strcasecmp(syn, "USmarc"))
49             return USMARC;
50         else if (!strcasecmp(syn, "UKmarc"))
51             return UKMARC;
52         else if (!strcasecmp(syn, "XML") ||
53                  !strcasecmp(syn, "text-XML") ||
54                  !strcasecmp(syn, "application-XML"))
55             return XML;
56
57         return UNKNOWN;
58     }
59
60     const char *record::render() const {
61         int len;
62         return ZOOM_record_get(r, "render", &len);
63     }
64
65     const char *record::rawdata() const {
66         int len;
67         return ZOOM_record_get(r, "raw", &len);
68     }
69 }