source: gsdl/trunk/common-src/src/lib/infodbclass.h@ 18050

Last change on this file since 18050 was 15436, checked in by mdewsnip, 16 years ago

(Adding new DB support) Created stub dbclass that gdbmclass (and sqlitedbclass etc. in the future) will inherit from.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1/**********************************************************************
2 *
3 * infodbclass.h --
4 * Copyright (C) 1999-2008 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#ifndef INFODBCLASS_H
27#define INFODBCLASS_H
28
29
30#include "text_t.h"
31
32
33typedef map<text_t, text_tarray, lttext_t> text_tarraymap;
34
35
36// infodbclass is used to store information about a object
37class infodbclass {
38protected:
39 text_tarraymap info;
40 text_t lang;
41
42public:
43 // type support for text_tarraymap
44 typedef text_tarraymap::iterator iterator;
45 typedef text_tarraymap::const_iterator const_iterator;
46 typedef text_tarraymap::reference reference;
47 typedef text_tarraymap::const_reference const_reference;
48 typedef text_tarraymap::size_type size_type;
49 typedef text_tarraymap::difference_type difference_type;
50 typedef text_tarraymap::const_reverse_iterator const_reverse_iterator;
51 typedef text_tarraymap::reverse_iterator reverse_iterator;
52
53 // constructors
54 infodbclass ();
55
56 // basic container support
57 iterator begin () {return info.begin();}
58 const_iterator begin () const {return info.begin();}
59 iterator end () {return info.end();}
60 const_iterator end () const {return info.end();}
61
62 void erase(iterator pos) {info.erase(pos);}
63 void erase(iterator first, iterator last) {info.erase(first, last);}
64 infodbclass &operator=(const infodbclass &x) {info=x.info;return *this;}
65
66 bool empty () const {return info.empty();}
67 size_type size() const {return info.size();}
68
69
70 // added functionality
71 void clear () {info.erase(info.begin(),info.end());}
72
73 // set default language
74 void set_language(const text_t& str_lang) { lang = str_lang; }
75 const text_t &get_language() const { return lang; }
76
77 // the following functions deal with keys that can only
78 // have one value for compatibility
79
80 // getinfo returns NULL if there isn't an entry with
81 // 'key' already defined, getintinfo returns 0 if there wasn't an
82 // entry with 'key' defined and operator[] returns "" if
83 // 'key' wasn't already defined (and sets 'key'="").
84 void setinfo (const text_t &key, const text_t &value);
85 void setintinfo (const text_t &key, int value);
86 void setcinfo (const text_t &key, unsigned short c);
87 text_t *getinfo (const text_t &key);
88 // get info overriding language set on this object
89 text_t *getinfo (const text_t &key, const text_t& lang);
90 int getintinfo (const text_t &key);
91 // get info overriding language set on this object
92 int getintinfo (const text_t &key, const text_t& lang);
93 text_t &operator[] (const text_t &key);
94
95
96 // the next set of functions allow you to set and access keys
97 // that can have more than one value
98
99 // getmultinfo returns NULL if there isn't an entry with
100 // 'key' already defined
101 void addinfo (const text_t &key, const text_t &value);
102 void addintinfo (const text_t &key, int value);
103 void addcinfo (const text_t &key, unsigned short c);
104 text_tarray *getmultinfo (const text_t &key);
105 // get info overriding language set on this object
106 text_tarray *getmultinfo (const text_t &key, const text_t& lang);
107};
108
109
110#endif
Note: See TracBrowser for help on using the repository browser.