5 ** Copyright 1998 - 2007 Double Precision, Inc. See COPYING for
6 ** distribution information.
14 #include <sys/types.h>
31 #if DB_VERSION_MAJOR >= 2
37 void bdbobj_init(struct bdbobj
*);
39 int bdbobj_open(struct bdbobj
*, const char *, const char *);
40 void bdbobj_close(struct bdbobj
*);
42 #define bdbobj_isopen(p) (!!(p)->has_dbf)
44 char *bdbobj_fetch(struct bdbobj
*, const char *, size_t, size_t *, const char *);
46 int bdbobj_exists(struct bdbobj
*, const char *, size_t);
47 int bdbobj_delete(struct bdbobj
*, const char *, size_t);
48 int bdbobj_store(struct bdbobj
*, const char *, size_t, const char *,
49 size_t, const char *);
51 char *bdbobj_firstkey(struct bdbobj
*, size_t *, char **, size_t *);
52 char *bdbobj_nextkey(struct bdbobj
*, size_t *, char **, size_t *);
63 BDbObj(const BDbObj
&); // Undefined
64 BDbObj
&operator=(const BDbObj
&); // Undefined
65 char *do_fetch(const char *, size_t, size_t &);
66 char *do_query(const char *, size_t, size_t &, const char *);
69 BDbObj() { bdbobj_init(&obj
); }
70 ~BDbObj() { bdbobj_close(&obj
); }
71 int Open(std::string filename
, const char *mode
)
73 return (bdbobj_open(&obj
, filename
.c_str(), mode
));
76 int IsOpen() { return (bdbobj_isopen(&obj
)); }
77 void Close() { bdbobj_close(&obj
); }
79 std::string
Fetch(std::string key
, std::string mode
)
82 char *p
=Fetch(key
.c_str(), key
.size(), l
, mode
.c_str());
86 std::string
v(p
, p
+l
);
92 bool Exists(std::string key
)
94 return !!Exists(key
.c_str(), key
.size());
97 bool Delete(std::string key
)
99 return !!Delete(key
.c_str(), key
.size());
102 bool Store(std::string key
, std::string val
, std::string mode
)
104 return Store(key
.c_str(), key
.size(),
105 val
.c_str(), val
.size(), mode
.c_str());
108 std::string
FetchFirstKeyVal(std::string
&valRet
)
115 key
=FetchFirstKeyVal(keyLen
, val
, valLen
);
120 std::string
r(key
, key
+keyLen
);
122 valRet
=std::string(val
, val
+valLen
);
127 std::string
FetchNextKeyVal(std::string
&valRet
)
134 key
=FetchNextKeyVal(keyLen
, val
, valLen
);
139 std::string
r(key
, key
+keyLen
);
141 valRet
=std::string(val
, val
+valLen
);
150 char *Fetch(const char *key
, size_t keylen
, size_t &vallen
,
153 return (bdbobj_fetch(&obj
, key
, keylen
, &vallen
, mode
));
155 int Exists(const char *key
, size_t keylen
)
157 return (bdbobj_exists(&obj
, key
, keylen
));
159 int Delete(const char *key
, size_t keylen
)
161 return (bdbobj_delete(&obj
, key
, keylen
));
164 int Store(const char *key
, size_t keylen
, const char *val
,
165 size_t vallen
, const char *mode
)
167 return (bdbobj_store(&obj
, key
, keylen
, val
, vallen
,
171 char *FetchFirstKeyVal(size_t &keylen
, char *&val
, size_t &vallen
)
173 return (bdbobj_firstkey(&obj
, &keylen
, &val
, &vallen
));
175 char *FetchNextKeyVal(size_t &keylen
, char *&val
, size_t &vallen
)
177 return (bdbobj_nextkey(&obj
, &keylen
, &val
, &vallen
));