1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * gdbmclass.h --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * PUT COPYRIGHT NOTICE HERE
|
---|
7 | *
|
---|
8 | * $Id: gdbmclass.h 124 1999-01-21 21:20:15Z sjboddie $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 |
|
---|
13 | #ifndef GDBMCLASS_H
|
---|
14 | #define GDBMCLASS_H
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 | #ifdef __WIN32__
|
---|
19 | #include "autoconf.h"
|
---|
20 | #include "systems.h"
|
---|
21 | #include "gdbmconst.h"
|
---|
22 | #include "gdbm.h"
|
---|
23 |
|
---|
24 | #else
|
---|
25 | #include <gdbm.h>
|
---|
26 | #endif
|
---|
27 |
|
---|
28 |
|
---|
29 | class gdbm_info {
|
---|
30 | public:
|
---|
31 | int docnum; // 'd'
|
---|
32 | text_t title; // 't'
|
---|
33 | text_t parent; // 'p'
|
---|
34 | text_t classification; // 'x'
|
---|
35 | text_t contents; // 'c'
|
---|
36 | text_t jobnum; // 'j'
|
---|
37 | text_t OID; // 'o'
|
---|
38 | text_t author; // 'a'
|
---|
39 | text_t source; // 's'
|
---|
40 | text_t date; // 'i'
|
---|
41 |
|
---|
42 | void clear ();
|
---|
43 | };
|
---|
44 |
|
---|
45 |
|
---|
46 | class gdbmclass {
|
---|
47 | public:
|
---|
48 | gdbmclass() {gdbmfile = NULL; logout = &cerr;};
|
---|
49 | ~gdbmclass() {};
|
---|
50 |
|
---|
51 | // returns 0 if failed, 1 if opened
|
---|
52 | int opendatabase (const text_t &filename);
|
---|
53 | void closedatabase ();
|
---|
54 |
|
---|
55 | // returns 0 on success, -1 on failure
|
---|
56 | int getinfo (text_t key, gdbm_info &info);
|
---|
57 | void setlogout (ostream *thelogout) {logout = thelogout;}
|
---|
58 | int exists (text_t key);
|
---|
59 |
|
---|
60 | protected:
|
---|
61 | text_t openfile;
|
---|
62 | GDBM_FILE gdbmfile;
|
---|
63 | ostream *logout;
|
---|
64 |
|
---|
65 | int getkeydata (text_t key, text_t &data);
|
---|
66 | int getinfoline (text_t::iterator &here, text_t::iterator end,
|
---|
67 | text_t &key, text_t &value);
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | // a few useful functions
|
---|
72 |
|
---|
73 | int is_top_level (const text_t &targetdoc);
|
---|
74 | int is_book (const text_t &targetdoc);
|
---|
75 | void get_book_top (const text_t &targetdoc, text_t &book_top);
|
---|
76 | void get_book (const text_t &targetdoc, text_t &book);
|
---|
77 | void get_parent_section (text_t §ion);
|
---|
78 | void get_parent_section (text_t &parentsection, text_t &childsection);
|
---|
79 | int count_dots (text_t::const_iterator first, text_t::const_iterator last);
|
---|
80 | int count_dots (const text_t &targetdoc);
|
---|
81 | int is_section_top (const text_t &targetdoc);
|
---|
82 | void remove_tags (text_t &text);
|
---|
83 |
|
---|
84 | void separate_parts (const text_t &targetdoc, gdbmclass &gdbm,
|
---|
85 | text_t &classification, text_t &booksection);
|
---|
86 | void split_targetdoc (const text_t &targetdoc, text_t &classification,
|
---|
87 | text_t &booksection);
|
---|
88 | void splitstring (const text_t &string, vector<text_t> &array);
|
---|
89 | void get_parents (const text_t &targetdoc, vector<text_t> &parents);
|
---|
90 | void get_siblings (const text_t &classification, const text_t &booksection,
|
---|
91 | gdbmclass &gdbm, vector<text_t> &siblings);
|
---|
92 | int are_same_chapter(text_t section1, text_t section2);
|
---|
93 | void get_first_section(const text_t &instring, text_t &returnstring);
|
---|
94 | int is_number (text_t &text);
|
---|
95 | text_t get_section_str(const text_t &str);
|
---|
96 | void alphabetize_string_english (text_t &text);
|
---|
97 | void alphabetize_string_name (text_t &text);
|
---|
98 | char ** string_add (char **array, int *len, char *str);
|
---|
99 | void string_sort (char **array, int len);
|
---|
100 | void string_free(char **array, int len);
|
---|
101 | text_t format_date (const text_t &date);
|
---|
102 | void format_month (text_t &month);
|
---|
103 | void format_day(text_t &day);
|
---|
104 |
|
---|
105 |
|
---|
106 | #endif
|
---|