File: bdbxml.h

package info (click to toggle)
libdb-ruby 0.6.5-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,596 kB
  • ctags: 3,978
  • sloc: ansic: 13,984; cpp: 8,739; ruby: 7,864; sh: 47; makefile: 6
file content (432 lines) | stat: -rw-r--r-- 9,304 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#include "bdb.h"
#include "bdbxml_features.h"

#include <fstream>
#include <dbxml/DbXml.hpp>

using namespace DbXml;

#define RMF(func) RUBY_METHOD_FUNC(func)
#define RDF RUBY_DATA_FUNC

#if HAVE_DBXML_RB_NEW_PROTO
#define RMFS(func) ((VALUE (*)(VALUE))func)
#define RMFF(func) ((void (*)(VALUE))func)
#else
#define RMFS(func) RMF(func)
#define RMFF(func) ((void (*)())func)
#endif

#define BDBXML_VERSION (10000*DBXML_VERSION_MAJOR+100*DBXML_VERSION_MINOR+DBXML_VERSION_PATCH)

#define PROTECT2(comm_, libr_)                          \
  try {                                                 \
    comm_;                                              \
    libr_;                                              \
  }                                                     \
  catch (XmlException &e) {                             \
    VALUE xb_err = Qnil;                                \
    libr_;                                              \
    if ((xb_err = bdb_return_err()) != Qnil) {          \
      rb_raise(xb_eFatal, StringValuePtr(xb_err));      \
    }                                                   \
    rb_raise(xb_eFatal, e.what());                      \
  }                                                     \
  catch (DbException &e) {                              \
    VALUE xb_err = Qnil;                                \
    libr_;                                              \
    if ((xb_err = bdb_return_err()) != Qnil) {          \
      rb_raise(xb_eFatal, StringValuePtr(xb_err));      \
    }                                                   \
    rb_raise(xb_eFatal, e.what());                      \
  }                                                     \
  catch (std::exception &e) {                           \
    libr_;                                              \
    rb_raise(xb_eFatal, e.what());                      \
  }                                                     \
  catch (...) {                                         \
    libr_;                                              \
    rb_raise(xb_eFatal, "Unknown error");               \
  }

#define PROTECT(comm_) PROTECT2(comm_,)

typedef struct {
    XmlManager *man;
    VALUE env;
    VALUE rsv;
    VALUE ori;
} xman;
      
typedef struct {
    XmlContainer *con;
    VALUE ind;
    VALUE txn;
    VALUE man;
    int opened;
#if HAVE_DBXML_XML_INDEX_LOOKUP
    VALUE look;
#endif
} xcon;

typedef struct {
    XmlIndexSpecification *ind;
    VALUE con;
} xind;

#if HAVE_DBXML_XML_INDEX_LOOKUP

typedef struct {
    XmlIndexLookup *look;
    VALUE man;
    VALUE txn;
    VALUE con;
} xlook;

#endif

#if HAVE_DBXML_XML_EVENT_WRITER

typedef struct {
    XmlEventWriter *ewr;
    VALUE con;
} xewr;

#endif

#if HAVE_DBXML_XML_EVENT_READER

typedef struct {
    XmlEventReader *erd;
    VALUE doc;
} xerd;

#endif

typedef struct {
    XmlResults *res;
    VALUE man;
} xres;

typedef struct {
    XmlDocument *doc;
    VALUE man;
} xdoc;

typedef struct {
    XmlUpdateContext *upd;
    VALUE man;
} xupd;

typedef struct {
    XmlModify *mod;
    VALUE txn;
    VALUE man;
} xmod;

typedef struct {
    XmlQueryContext *cxt;
    VALUE man;
} xcxt;

typedef struct {
    XmlQueryExpression *que;
    VALUE txn;
    VALUE man;
} xque;

typedef struct {
    XmlValue *val;
    VALUE man;
} xval;

static VALUE xb_eFatal, xb_cTxn;

static void xb_man_free(xman *);

static inline xman *
get_man(VALUE obj)
{
    xman *man;
    if (TYPE(obj) != T_DATA || RDATA(obj)->dfree != (RDF)xb_man_free) {
        rb_raise(xb_eFatal, "invalid Manager objects");
    }
    Data_Get_Struct(obj, xman, man);
    if (!man->man) {
        rb_raise(rb_eArgError, "invalid Manager object");
    }
    return man;
}

static inline xres *
get_res(VALUE obj)
{
    xres *res;

    Data_Get_Struct(obj, xres, res);
    if (!res->res) {
        rb_raise(rb_eArgError, "invalid Results");
    }
    get_man(res->man);
    return res;
}

static inline xval *
get_val(VALUE obj)
{
    xval *val;

    Data_Get_Struct(obj, xval, val);
    if (!val->val) {
        rb_raise(rb_eArgError, "invalid Value");
    }
    get_man(val->man);
    return val;
}

static void xb_doc_mark(xdoc *);

static inline xdoc *
get_doc(VALUE obj)
{
    xdoc *doc;
    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_doc_mark) {
        rb_raise(rb_eArgError, "invalid document");
    }
    Data_Get_Struct(obj, xdoc, doc);
    if (!doc->doc) {
        rb_raise(rb_eArgError, "invalid document");
    }
    return doc;
}  

static inline XmlTransaction *
get_txn(VALUE obj)
{
    if (rb_obj_is_kind_of(obj, xb_cTxn)) {
	bdb_TXN *txnst;

	GetTxnDBErr(obj, txnst, xb_eFatal);
        return (XmlTransaction *)txnst->txn_cxx;
    }
    return 0;
}

static inline xman *
get_man_txn(VALUE obj)
{
    if (rb_obj_is_kind_of(obj, xb_cTxn)) {
	bdb_TXN *txnst;

	GetTxnDBErr(obj, txnst, xb_eFatal);
        return get_man(txnst->man);
    }
    else {
        return get_man(obj);
    }
}

static void xb_upd_free(xupd *);

static inline xupd *
get_upd(VALUE obj)
{
    xupd *upd;
    if (TYPE(obj) != T_DATA || RDATA(obj)->dfree != (RDF)xb_upd_free) {
        rb_raise(rb_eArgError, "expected an Update Context");
    }
    Data_Get_Struct(obj, xupd, upd);
    if (!upd->upd) {
        rb_raise(rb_eArgError, "invalid Update Context");
    }
    get_man(upd->man);
    return upd;
}

static inline VALUE
get_txn_man(VALUE obj)
{
    if (rb_obj_is_kind_of(obj, xb_cTxn)) {
        bdb_TXN *txnst;

        GetTxnDBErr(obj, txnst, xb_eFatal);
        return txnst->man;
    }
    return 0;
}

static void xb_cxt_free(xcxt *);

static inline xcxt *
get_cxt(VALUE obj)
{
    xcxt *cxt;
    if (TYPE(obj) != T_DATA || RDATA(obj)->dfree != (RDF)xb_cxt_free) {
        rb_raise(rb_eArgError, "expected a Query Context");
    }
    Data_Get_Struct(obj, xcxt, cxt);
    if (!cxt->cxt) {
        rb_raise(rb_eArgError, "invalid QueryContext");
    }
    get_man(cxt->man);
    return cxt;
}

static void xb_con_mark(xcon *);

static inline xcon *
get_con(VALUE obj)
{
    xcon *con;

    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_con_mark) {
        rb_raise(rb_eArgError, "invalid Container");
    }
    Data_Get_Struct(obj, xcon, con);
    if (!con->opened) {
        rb_raise(rb_eArgError, "closed container");
    }
    if (!con->con || !con->man) {
        rb_raise(rb_eArgError, "invalid Container");
    }
    get_man(con->man);
    return con;
} 

static inline XmlTransaction *
get_con_txn(xcon *con)
{
    if (RTEST(con->txn)) {
        bdb_TXN *txnst;

	GetTxnDBErr(con->txn, txnst, xb_eFatal);
        return (XmlTransaction *)txnst->txn_cxx;
    }
    return 0;
}

static void xb_ind_free(xind *);

static inline xind *
get_ind(VALUE obj)
{
    if (TYPE(obj) != T_DATA || RDATA(obj)->dfree != (RDF)xb_ind_free) {
        rb_raise(rb_eArgError, "expected an IndexSpecification object");
    }
    xind *ind;
    Data_Get_Struct(obj, xind, ind);
    if (!ind->ind) {
        rb_raise(rb_eArgError, "expected an IndexSpecification object");
    }
    return ind;
}

#if HAVE_DBXML_XML_INDEX_LOOKUP

static void xb_look_mark(xlook *);

static inline xlook *
get_look(VALUE obj)
{
    xlook *look;

    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_look_mark) {
        rb_raise(rb_eArgError, "invalid IndexLookup");
    }
    Data_Get_Struct(obj, xlook, look);
    if (!look->look || !look->man || !look->con) {
        rb_raise(rb_eArgError, "invalid IndexLookup");
    }
    get_man(look->man);
    get_con(look->con);
    return look;
} 

#endif

static void xb_que_mark(xque *);

static inline xque *
get_que(VALUE obj)
{
    xque *que;

    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_que_mark) {
        rb_raise(rb_eArgError, "expected a Query Expression");
    }
    Data_Get_Struct(obj, xque, que);
    if (!que->que) {
        rb_raise(rb_eArgError, "invalid QueryExpression");
    }
    get_man(que->man);
    return que;
}

static inline xmod *
get_mod(VALUE obj)
{
    xmod *mod;
    Data_Get_Struct(obj, xmod, mod);
    if (!mod->mod) {
        rb_raise(rb_eArgError, "invalid Modify");
    }
    get_man(mod->man);
    return mod;
}

static inline void
rset_obj(VALUE obj)
{
    RBASIC(obj)->klass = rb_cData;
    RDATA(obj)->dfree = (RDF)free;
    RDATA(obj)->dmark = 0;
}


static void xb_res_free(xres *res);
static void xb_res_mark(xres *res);

#if HAVE_DBXML_XML_EVENT_WRITER

static void xb_ewr_free(xewr *ewr);
static void xb_ewr_mark(xewr *ewr);

static inline xewr *
get_ewr(VALUE obj)
{
    xewr *ewr;

    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_ewr_mark) {
        rb_raise(rb_eArgError, "expected a XML::EventWriter");
    }
    Data_Get_Struct(obj, xewr, ewr);
    if (!ewr->ewr) {
        rb_raise(rb_eArgError, "closed XML::EventWriter");
    }
    get_con(ewr->con);
    return ewr;
}

#endif

#if HAVE_DBXML_XML_EVENT_READER

static void xb_erd_free(xerd *erd);
static void xb_erd_mark(xerd *erd);

static inline xerd *
get_erd(VALUE obj)
{
    xerd *erd;

    if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RDF)xb_erd_mark) {
        rb_raise(rb_eArgError, "expected a XML::EventReader");
    }
    Data_Get_Struct(obj, xerd, erd);
    if (!erd->erd) {
        rb_raise(rb_eArgError, "closed XML::EventReader");
    }
    return erd;
}

#endif