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 | |
---|
8 | class 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 | class statusrecord |
---|
20 | { |
---|
21 | public: |
---|
22 | stopos_key next; // points to first line for the 'next' command |
---|
23 | stopos_key first; // points to first record |
---|
24 | stopos_key last; // points to last record |
---|
25 | stopos_key nextd; // points to record to be dumped |
---|
26 | longuint count; // total number of records added |
---|
27 | longuint present; // total number of records now availabe |
---|
28 | longuint present0; // ditto, but uncommitted |
---|
29 | |
---|
30 | statusrecord(void); |
---|
31 | statusrecord(const std::string &s,char dbsep); |
---|
32 | std::string str(char dbsep); |
---|
33 | void init(void); |
---|
34 | }; |
---|
35 | |
---|
36 | class stopos_pool |
---|
37 | { |
---|
38 | protected: |
---|
39 | char* db_name; // name for database |
---|
40 | std::string sdb_name; // idem |
---|
41 | static const unsigned int reclen = 256; // 1024; |
---|
42 | bool kvp; //true if Koot-Vermin paradigm is to be used |
---|
43 | bool db_open; |
---|
44 | |
---|
45 | stopos_key statuskey; |
---|
46 | stopos_key nextkey; |
---|
47 | statusrecord status; |
---|
48 | |
---|
49 | virtual int get_record(std::string &r,const std::string &k)=0; |
---|
50 | virtual int put_record(const std::string &r,const std::string &k)=0; |
---|
51 | virtual int remove_record(const stopos_key &k)=0; |
---|
52 | virtual int get_status(void)=0; |
---|
53 | virtual int put_status(void)=0; |
---|
54 | |
---|
55 | virtual std::string get_slot(const std::string &k) { return ""; } |
---|
56 | |
---|
57 | int get_record(datarecord &r,const stopos_key &k); |
---|
58 | int put_record(const datarecord &r,const stopos_key &k); |
---|
59 | |
---|
60 | public: |
---|
61 | |
---|
62 | stopos_pool(); |
---|
63 | ~stopos_pool(); |
---|
64 | |
---|
65 | virtual int create_db(void) = 0; |
---|
66 | virtual int purge_db(void) = 0; |
---|
67 | virtual int open_db(void) = 0; |
---|
68 | virtual int close_db(void) = 0; |
---|
69 | virtual void dump_db(void) = 0; |
---|
70 | |
---|
71 | virtual void set_db_name(std::string filename); |
---|
72 | virtual std::string get_db_name(void); |
---|
73 | |
---|
74 | virtual int add_line(const std::string line,std::string &key); |
---|
75 | virtual int get_line(std::string &line,longuint &retrieved,std::string &key); |
---|
76 | virtual int remove_line(const std::string &key); |
---|
77 | |
---|
78 | virtual void set_kvp(const bool v); |
---|
79 | virtual bool get_kvp(void); |
---|
80 | |
---|
81 | int get_counts(longuint &count, |
---|
82 | longuint &present, |
---|
83 | longuint &present0); |
---|
84 | |
---|
85 | int dump_line(std::string &line, |
---|
86 | longuint &retrieved, |
---|
87 | std::string &key); |
---|
88 | |
---|
89 | const static int NOFILENAME = 1; |
---|
90 | const static int OPENERROR = 2; |
---|
91 | const static int STOREERROR = 3; |
---|
92 | const static int FETCHERROR = 4; |
---|
93 | const static int NOTFOUND = 5; |
---|
94 | const static int NOTIMPLEMENTED = 6; |
---|
95 | const static int REMOVEERROR = 7; |
---|
96 | const static int LOCKERROR = 8; |
---|
97 | const static int CLOSEERROR = 9; |
---|
98 | const static int UNLOCKERROR = 10; |
---|
99 | const static int DBNOTOPEN = 11; |
---|
100 | const static int CREATEERROR = 12; |
---|
101 | const static int PURGEERROR = 13; |
---|
102 | |
---|
103 | }; |
---|
104 | #endif |
---|