5 ** Copyright 1998 - 2007 Double Precision, Inc. See COPYING for
6 ** distribution information.
9 static const char bdbobj_h_rcsid
[]="$Id: bdbobj.h,v 1.6 2007/03/01 04:32:03 mrsam Exp $";
15 #include <sys/types.h>
32 #if DB_VERSION_MAJOR >= 2
38 void bdbobj_init(struct bdbobj
*);
40 int bdbobj_open(struct bdbobj
*, const char *, const char *);
41 void bdbobj_close(struct bdbobj
*);
43 #define bdbobj_isopen(p) (!!(p)->has_dbf)
45 char *bdbobj_fetch(struct bdbobj
*, const char *, size_t, size_t *, const char *);
47 int bdbobj_exists(struct bdbobj
*, const char *, size_t);
48 int bdbobj_delete(struct bdbobj
*, const char *, size_t);
49 int bdbobj_store(struct bdbobj
*, const char *, size_t, const char *,
50 size_t, const char *);
52 char *bdbobj_firstkey(struct bdbobj
*, size_t *, char **, size_t *);
53 char *bdbobj_nextkey(struct bdbobj
*, size_t *, char **, size_t *);
64 BDbObj(const BDbObj
&); // Undefined
65 BDbObj
&operator=(const BDbObj
&); // Undefined
66 char *do_fetch(const char *, size_t, size_t &);
67 char *do_query(const char *, size_t, size_t &, const char *);
70 BDbObj() { bdbobj_init(&obj
); }
71 ~BDbObj() { bdbobj_close(&obj
); }
72 int Open(std::string filename
, const char *mode
)
74 return (bdbobj_open(&obj
, filename
.c_str(), mode
));
77 int IsOpen() { return (bdbobj_isopen(&obj
)); }
78 void Close() { bdbobj_close(&obj
); }
80 std::string
Fetch(std::string key
, std::string mode
)
83 char *p
=Fetch(key
.c_str(), key
.size(), l
, mode
.c_str());
87 std::string
v(p
, p
+l
);
93 bool Exists(std::string key
)
95 return !!Exists(key
.c_str(), key
.size());
98 bool Delete(std::string key
)
100 return !!Delete(key
.c_str(), key
.size());
103 bool Store(std::string key
, std::string val
, std::string mode
)
105 return Store(key
.c_str(), key
.size(),
106 val
.c_str(), val
.size(), mode
.c_str());
109 std::string
FetchFirstKeyVal(std::string
&valRet
)
116 key
=FetchFirstKeyVal(keyLen
, val
, valLen
);
121 std::string
r(key
, key
+keyLen
);
123 valRet
=std::string(val
, val
+valLen
);
128 std::string
FetchNextKeyVal(std::string
&valRet
)
135 key
=FetchNextKeyVal(keyLen
, val
, valLen
);
140 std::string
r(key
, key
+keyLen
);
142 valRet
=std::string(val
, val
+valLen
);
151 char *Fetch(const char *key
, size_t keylen
, size_t &vallen
,
154 return (bdbobj_fetch(&obj
, key
, keylen
, &vallen
, mode
));
156 int Exists(const char *key
, size_t keylen
)
158 return (bdbobj_exists(&obj
, key
, keylen
));
160 int Delete(const char *key
, size_t keylen
)
162 return (bdbobj_delete(&obj
, key
, keylen
));
165 int Store(const char *key
, size_t keylen
, const char *val
,
166 size_t vallen
, const char *mode
)
168 return (bdbobj_store(&obj
, key
, keylen
, val
, vallen
,
172 char *FetchFirstKeyVal(size_t &keylen
, char *&val
, size_t &vallen
)
174 return (bdbobj_firstkey(&obj
, &keylen
, &val
, &vallen
));
176 char *FetchNextKeyVal(size_t &keylen
, char *&val
, size_t &vallen
)
178 return (bdbobj_nextkey(&obj
, &keylen
, &val
, &vallen
));