⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_cls.h

📁 HP公司的SNMP++的Win32版本源码
💻 H
字号:
/*============================================================================
  Copyright (c) 1996
  Hewlett-Packard Company

  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  Permission to use, copy, modify, distribute and/or sell this software 
  and/or its documentation is hereby granted without fee. User agrees 
  to display the above copyright notice and this license notice in all 
  copies of the software and any documentation of the software. User 
  agrees to assume all liability for the use of the software; Hewlett-Packard 
  makes no representations about the suitability of this software for any 
  purpose. It is provided "AS-IS without warranty of any kind,either express 
  or implied. User hereby grants a royalty-free license to any and all 
  derivatives based upon this software code base. 
 
=============================================================================*/

//========================================================================
//     D B _ C L S . H
// 
//     Generic Database Class
//     Binary tree database class definition
//
//
//     Changes:
//
//========================================================================
#ifndef _DB_CLS
#define _DB_CLS


#include <string.h>
#include <stdio.h>

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

// Db class error macros
#define DB_OK              0                       // operation successful
#define DB_NO_NAME        -1                       // name not defined
#define DB_FILE_NOT_FOUND -2                       // file not found
#define DB_FRAG_ERROR     -3                       // file is fragmented
#define DB_OPEN_ERROR     -4                       // open error
#define DB_REC_NOT_FOUND  -5                       // record not found
#define DB_KEY_NEW        -6          
#define FILE_LOCKED       -7                       // file was locked 
#define SIGNAL_FAIL       -8                       // signal failed            

// Db class file access macros
#define DB_TIMEOUT        3

// Db class key size
#define DBKEYSIZE         80                       // size of Db Key 
#define MAXDBNAME         255                      // maximum file name size

// Db pattern search codes
#define WC_MATCH           0                       // pattern matched
#define WC_NO_MATCH       -1                       // pattern not matched

// database record definition
typedef char Key[DBKEYSIZE];                       // Binary search key


//======================[ Database class definition ]========================
class Db
{
  private:
     char db_name[MAXDBNAME];                      // database path and name
     long int rec_size;                            // size of each record
     long int current_number_of_records;	   // current # of records

  protected:
     // binary search
     int binary_search( FILE *binary_search_file,  // binary search file stream
                        void *data,                // record to look for
                        long int *location);       // location where found

     // fragment checking
     int frag_check ();

     // append records
     int append_recs( FILE *from,                  // copy from this file
                      FILE *to,                    // to this file
                      long int start,              // from this record #
                      long int stop,               // to this record #
                      long int recsize);           // size of record

     // wild card compare
     int wild_card_compare( const char *pattern,   // pattern to look for
                            const char *str);      // string to compare against

     // check the current time
     int check_current_time ();                       

     // Db class semaphore wait
     FILE * wait (const char *mode, 			  // open_file_flag
		int shflag);			  // file_sharing_flag
              


  public:
    // constructor, no arguments
    Db()
       { strcpy(db_name,"");
         current_number_of_records = 0;};        

   // constructor with filename and record size
   Db( const char *name,                           // file name
       const long int record_size)                 // size of each record
      { set_attributtes( name, record_size);};

   // set the current db attributtes
   int set_attributtes( const char *name,          // file name    
                        const long record_size);   // rocord size

   // write a record to the db   
   int write( const void *data);                   // record to write

   // read a record from the db
   int read( void *data);                         // record to read

   // delete a record from the db, using the key only
   int del( const Key key);                      // key to find & delete

   // wipe out the entire db
   int delete_db();                               

   // get the # of records in the db
   long int get_num_recs()
       { return current_number_of_records; };        

   // retrieve a record given the location
   int retrieve(  const long int location,       // location to look
                  void *data);                   // returned data 

   // look for a pattern in the db
   int pattern(const char *search_pattern,       // pattern to search for  
               Key **keys,                       // returned keys
               int *keycount);                   // count of returned keys


};   // end class def Db

#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -