Release 1.6.4
[yazpp-moved-to-github.git] / zoom / master-header
1 // ZOOM C++ Binding.
2 // The ZOOM homepage is at http://zoom.z3950.org/
3 //
4 // Derived from version 1.3a at
5 //      http://zoom.z3950.org/bind/cplusplus/zoom-1.3a.hh
6
7 #include <stddef.h>             // for size_t
8 #include <string>
9
10
11 */*
12 * * This is a bit stupid.  The fact that our ZOOM-C++ implementation is
13 * * based on the ZOOM-C implementation is our Dirty Little Secret, and
14 * * there is in principle no reason why client code need be bothered
15 * * with it.  Except of course that the public class declarations in
16 * * C++ have to lay their private parts out for the world to see
17 * * (oo-er).  Hence the inclusion of <yaz/zoom.h>
18 * */
19 *#include <yaz/zoom.h>
20 *
21 namespace ZOOM {
22   // Forward declarations for type names.
23   class YAZ_EXPORT query;
24   class YAZ_EXPORT resultSet;
25   class YAZ_EXPORT record;
26
27   class YAZ_EXPORT connection {
28 *   ZOOM_connection c;
29 *   friend class resultSet; // so it can use _getYazConnection()
30 *   ZOOM_connection _getYazConnection () const { return c; }
31     // connections are non-copyable.
32     connection (const connection &);
33     connection &operator= (const connection &);
34   public:
35     connection ();
36     connection (const std::string &hostname, int portnum);
37     ~connection ();
38     void connect (const std::string &hostname, int portnum);
39     std::string option (const std::string &key) const;
40     bool option (const std::string &key, const std::string &val);
41   };
42
43   class query {
44       // base class for all query types
45 *   friend class resultSet; // so it can use _getYazQuery()
46 *   ZOOM_query _getYazQuery () const { return q; }
47 * protected:
48 *   ZOOM_query q;
49   public:
50     query ();
51     virtual ~query ();
52   };
53
54   class YAZ_EXPORT prefixQuery : public query {
55   public:
56     prefixQuery (const std::string &pqn);
57     ~prefixQuery ();
58   };
59
60   class YAZ_EXPORT CCLQuery : public query {
61   public:
62     CCLQuery (const std::string &ccl, void *qualset);
63     ~CCLQuery ();
64   };
65
66   class YAZ_EXPORT resultSet {
67 *   connection &owner;
68 *   ZOOM_resultset rs;
69 *   friend class record; // for _getYazResultSet() & _getYazConnection()
70 *   ZOOM_resultset _getYazResultSet () const { return rs; }
71 *   ZOOM_connection _getYazConnection () const {
72 *       return owner._getYazConnection(); }
73     // resultSets are non-copyable.
74     resultSet (const resultSet &);
75     resultSet &operator= (const resultSet &);
76   public:
77     resultSet (connection &c, const query &q);
78     ~resultSet ();
79     std::string option (const std::string &key) const;
80     bool option (const std::string &key, const std::string &val);
81     size_t size () const;
82   };
83
84   class YAZ_EXPORT record {
85 *   const resultSet &owner;
86 *   ZOOM_record r;
87   public:
88     class YAZ_EXPORT syntax {
89     public:
90       enum value {
91         UNKNOWN, GRS1, SUTRS, USMARC, UKMARC, XML
92       };
93 *   private:
94 *     enum value val;
95 *   public:
96       syntax (value rs);
97       operator std::string () const;
98       bool operator== (const syntax &s) const;
99       bool operator== (value rs) const;
100       operator value () const;
101     };
102
103     record (resultSet &rs, size_t num);
104     ~record ();
105     syntax recsyn () const;
106     std::string render () const;
107     std::string rawdata () const;
108   };
109
110   // Base exception class; from which all other ZOOM exceptions
111   // are derived. Other classes that use this as their base
112   // class may want to provide their own errcode() and errmsg()
113   // functions -- hence they are made virtual.
114   class YAZ_EXPORT exception {
115 * protected:
116 *   int code;
117   public:
118     exception (int code);
119     virtual ~exception ();
120     virtual int errcode () const;
121     virtual std::string errmsg () const;
122   };
123
124   // systemException could be thrown for timeouts, protocol errors,
125   // network outages.
126   class YAZ_EXPORT systemException : public exception {
127   public:
128     systemException ();         // Uses value of system `errno'
129     systemException (int code);
130 *   virtual std::string errmsg () const; // Why do I have to repeat this?
131   };
132
133   // bib1Exception::errcode() returns a code from the
134   // Bib-1 Diagnostic Set.
135   class YAZ_EXPORT bib1Exception: public exception {
136 *   std::string info;
137   public:
138 *   ~bib1Exception ();
139     bib1Exception (int code, const std::string &addinfo);
140 *   virtual std::string errmsg () const; // Why do I have to repeat this?
141     std::string addinfo () const;
142   };
143
144   class YAZ_EXPORT queryException : public exception {
145 *   std::string q;
146   public:
147 *   ~queryException ();
148     enum { PREFIX, CCL };
149     queryException (int qtype, const std::string &source);
150 *   virtual std::string errmsg () const; // Why do I have to repeat this?
151     std::string addinfo () const;
152   };
153 }