source: tags/0.58/stopos_pool.h @ 9

Last change on this file since 9 was 9, checked in by willem, 11 years ago

willem

File size: 3.6 KB
Line 
1#ifndef STOPOS_POOL_H
2#define STOPOS_POOL_H
3#include <string>
4#include "stopos.h"
5#include "stopos_key.h"
6#include <iostream>
7 
8class datarecord
9{
10  public:
11    datarecord();
12    datarecord(const std::string &s,char sep);
13    stopos_key prev;
14    stopos_key next;
15    longuint retrieved;
16    std::string value;
17    std::string str(char dbsep) const;
18};
19
20class statusrecord
21{
22  public:
23  stopos_key next;      // points to first line for the 'next' command
24  stopos_key first;     // points to first record
25  stopos_key last;      // points to last record
26  stopos_key nextd;     // points to record to be dumped
27  longuint count;       // total number of records added
28  longuint present;     // total number of records now availabe
29  longuint present0;    // ditto, but uncommitted
30  std::string extra;    // string that can be used by derived class
31
32  statusrecord(void);
33  statusrecord(const std::string &s,char dbsep);
34  std::string str(char dbsep);
35  void init(void);
36};
37
38class stopos_pool
39{
40  protected:
41    char* db_name;        // name for database
42    std::string sdb_name; // idem
43    static const unsigned int reclen = 4096;
44    bool kvp; //true if Koot-Vermin paradigm is to be used
45    bool db_open;
46   
47    stopos_key statuskey;
48    stopos_key nextkey;
49    statusrecord status;
50
51    virtual int get_record(std::string &r,       const std::string &k, const std::string &l)=0;
52    virtual int put_record(const std::string &r, const std::string &k, const std::string &l)=0;
53    virtual int remove_record(                   const std::string &k, const std::string &l)=0;
54
55    int put_status(void);
56    int get_status(void);
57
58    virtual std::string key_to_slot(const std::string &k) = 0;
59    // the function add_line calls this to get a slot
60    // from the derived class.  If no slot is necessary,
61    // this function may return "".
62    // The subsequent put_record call will have the return
63    // value of this function as parameter.
64
65    int get_record(datarecord &r,const stopos_key &k);
66    int put_record(const datarecord &r,const stopos_key &k);
67    int remove_record(const stopos_key &k);
68
69    std::string whoami;
70
71  public:
72
73    stopos_pool();
74    ~stopos_pool();
75
76    virtual int create_db(const std::string &dbname) = 0;  // todo private
77    virtual int purge_db(void)  = 0;
78    virtual int open_db(void)   = 0;
79    virtual int close_db(void)  = 0;
80    virtual void dump_db(void)  = 0;
81
82
83    int create_db(void);
84
85    virtual void set_db_name(std::string filename);
86    virtual std::string get_db_name(void);
87
88    virtual int add_line(const std::string line,std::string &key);
89    virtual int get_line(std::string &line,longuint &retrieved,std::string &key);
90    virtual int remove_line(const std::string &key);
91
92    virtual void set_kvp(const bool v);
93    virtual bool get_kvp(void);
94
95    int get_counts(longuint &count, 
96                   longuint &present, 
97                   longuint &present0);
98
99    int dump_line(std::string  &line,
100                  longuint     &retrieved,
101                  std::string  &key);
102
103    bool is_statusrecord(const std::string &k);
104
105    const static int NOFILENAME        =  1;
106    const static int OPENERROR         =  2;
107    const static int STOREERROR        =  3;
108    const static int FETCHERROR        =  4;
109    const static int NOTFOUND          =  5;
110    const static int NOTIMPLEMENTED    =  6;
111    const static int REMOVEERROR       =  7;
112    const static int LOCKERROR         =  8;
113    const static int CLOSEERROR        =  9;
114    const static int UNLOCKERROR       = 10;
115    const static int DBNOTOPEN         = 11;
116    const static int CREATEERROR       = 12;
117    const static int PURGEERROR        = 13;
118    const static int RECORDTOOLONG     = 14;
119
120};
121#endif
Note: See TracBrowser for help on using the repository browser.