Changeset 15557

Show
Ignore:
Timestamp:
17.05.2008 15:58:11 (11 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Set up dbclass as an abstract class that gdbmclass (and others in the future) inherit from.

Location:
gsdl/trunk/lib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/lib/dbclass.h

    r15436 r15557  
    4343 
    4444 
     45#define DB_READER         1 
     46#define DB_WRITER         2 
     47#define DB_WRITER_CREATE  3 
     48 
     49 
    4550class dbclass 
    4651{ 
    4752public: 
    4853  dbclass() { logout = &cerr; } 
    49   ~dbclass(); 
     54  virtual ~dbclass(); 
     55 
     56  void setlogout (ostream *logout_arg) { logout = logout_arg; } 
     57 
     58  // returns true if opened 
     59  virtual bool opendatabase(const text_t &filename, int mode, int num_retrys, bool need_filelock) = 0; 
     60  virtual void closedatabase() = 0; 
     61 
     62  // returns true on success 
     63  virtual bool getinfo (const text_t& key, infodbclass &info) = 0; 
     64 
     65  // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)  
     66  // it expects child, parent, etc. to exist if syntax has been used 
     67  // so you should test before using 
     68  virtual text_t translate_OID (const text_t &OID, infodbclass &info) = 0; 
    5069 
    5170protected: 
  • gsdl/trunk/lib/gdbmclass.cpp

    r15429 r15557  
    5353 
    5454  openfile = filename; 
    55    
     55 
     56  // Map the DB mode values into GDBM mode values 
     57  int gdbm_mode = GDBM_READER; 
     58  if (mode == DB_WRITER) 
     59  { 
     60    gdbm_mode = GDBM_WRITER; 
     61  } 
     62  else if (mode == DB_WRITER_CREATE) 
     63  { 
     64    gdbm_mode = GDBM_WRCREAT; 
     65  } 
     66 
    5667  char *namebuffer = filename.getcstr(); 
    5768  do { 
    5869#ifdef __WIN32__ 
    59     gdbmfile = gdbm_open (namebuffer, block_size, mode, 00664, NULL, (need_filelock) ? 1 : 0); 
     70    gdbmfile = gdbm_open (namebuffer, block_size, gdbm_mode, 00664, NULL, (need_filelock) ? 1 : 0); 
    6071#else 
    61     gdbmfile = gdbm_open (namebuffer, block_size, mode, 00664, NULL); 
     72    gdbmfile = gdbm_open (namebuffer, block_size, gdbm_mode, 00664, NULL); 
    6273#endif 
    6374    --num_retrys; 
  • gsdl/trunk/lib/gdbmclass.h

    r15436 r15557  
    4949 
    5050 
    51 class gdbmclass: dbclass 
     51class gdbmclass : public dbclass 
    5252{ 
    5353public: 
     
    6767  // returns true on success 
    6868  bool getinfo (const text_t& key, infodbclass &info); 
    69   void setlogout (ostream *thelogout) {logout = thelogout;} 
    7069 
    7170  // returns true if exists