bdbobj.h
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. #ifndef bdbobj_h
  2. #define bdbobj_h
  3. /*
  4. ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
  5. ** distribution information.
  6. */
  7. static const char bdbobj_h_rcsid[]="$Id: bdbobj.h,v 1.5 1999/12/06 13:13:46 mrsam Exp $";
  8. #if HAVE_CONFIG_H
  9. #include "config.h"
  10. #endif
  11. #include <sys/types.h>
  12. #if HAVE_LIMITS_H
  13. #include <limits.h>
  14. #endif
  15. #include <db.h>
  16. #include <stdlib.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct bdbobj {
  21. DB *dbf;
  22. int has_dbf;
  23. #if DB_VERSION_MAJOR >= 2
  24. DBC *dbc;
  25. int has_dbc;
  26. #endif
  27. } ;
  28. void bdbobj_init(struct bdbobj *);
  29. int bdbobj_open(struct bdbobj *, const char *, const char *);
  30. void bdbobj_close(struct bdbobj *);
  31. #define bdbobj_isopen(p) (!!(p)->has_dbf)
  32. char *bdbobj_fetch(struct bdbobj *, const char *, size_t, size_t *, const char *);
  33. int bdbobj_exists(struct bdbobj *, const char *, size_t);
  34. int bdbobj_delete(struct bdbobj *, const char *, size_t);
  35. int bdbobj_store(struct bdbobj *, const char *, size_t, const char *,
  36. size_t, const char *);
  37. char *bdbobj_firstkey(struct bdbobj *, size_t *, char **, size_t *);
  38. char *bdbobj_nextkey(struct bdbobj *, size_t *, char **, size_t *);
  39. #ifdef __cplusplus
  40. } ;
  41. class BDbObj {
  42. struct bdbobj obj;
  43. BDbObj(const BDbObj &); // Undefined
  44. BDbObj &operator=(const BDbObj &); // Undefined
  45. char *do_fetch(const char *, size_t, size_t &);
  46. char *do_query(const char *, size_t, size_t &, const char *);
  47. public:
  48. BDbObj() { bdbobj_init(&obj); }
  49. ~BDbObj() { bdbobj_close(&obj); }
  50. int Open(const char *filename, const char *mode)
  51. {
  52. return (bdbobj_open(&obj, filename, mode));
  53. }
  54. int IsOpen() { return (bdbobj_isopen(&obj)); }
  55. void Close() { bdbobj_close(&obj); }
  56. char *Fetch(const char *key, size_t keylen, size_t &vallen,
  57. const char *mode)
  58. {
  59. return (bdbobj_fetch(&obj, key, keylen, &vallen, mode));
  60. }
  61. int Exists(const char *key, size_t keylen)
  62. {
  63. return (bdbobj_exists(&obj, key, keylen));
  64. }
  65. int Delete(const char *key, size_t keylen)
  66. {
  67. return (bdbobj_delete(&obj, key, keylen));
  68. }
  69. int Store(const char *key, size_t keylen, const char *val,
  70. size_t vallen, const char *mode)
  71. {
  72. return (bdbobj_store(&obj, key, keylen, val, vallen,
  73. mode));
  74. }
  75. char *FetchFirstKeyVal(size_t &keylen, char *&val, size_t &vallen)
  76. {
  77. return (bdbobj_firstkey(&obj, &keylen, &val, &vallen));
  78. }
  79. char *FetchNextKeyVal(size_t &keylen, char *&val, size_t &vallen)
  80. {
  81. return (bdbobj_nextkey(&obj, &keylen, &val, &vallen));
  82. }
  83. } ;
  84. #endif
  85. #endif