1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * infodbclass.cpp --
|
---|
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 | #include "infodbclass.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | // constructors
|
---|
30 | infodbclass::infodbclass () {
|
---|
31 | }
|
---|
32 |
|
---|
33 |
|
---|
34 | void infodbclass::setinfo (const text_t &key, const text_t &value)
|
---|
35 | {
|
---|
36 | text_tarray &tarr = info[key];
|
---|
37 | tarr.erase(tarr.begin(), tarr.end());
|
---|
38 | tarr.push_back(value);
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | void infodbclass::setintinfo (const text_t &key, int value)
|
---|
43 | {
|
---|
44 | setinfo (key, value);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | void infodbclass::setcinfo (const text_t &key, unsigned short c)
|
---|
49 | {
|
---|
50 | text_t t;
|
---|
51 | t.push_back (c);
|
---|
52 | setinfo (key, t);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | text_t *infodbclass::getinfo (const text_t &key)
|
---|
57 | {
|
---|
58 | iterator here = info.find (key);
|
---|
59 | if (here == info.end()) return NULL;
|
---|
60 |
|
---|
61 | if ((*here).second.empty()) return NULL;
|
---|
62 |
|
---|
63 | return &((*here).second[0]);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | text_t *infodbclass::getinfo (const text_t &key, const text_t& slang)
|
---|
68 | {
|
---|
69 | text_tarray *t = getmultinfo(key, slang);
|
---|
70 | if (t == NULL || t->empty()) return NULL;
|
---|
71 | return &((*t)[0]);
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | int infodbclass::getintinfo (const text_t &key)
|
---|
76 | {
|
---|
77 | text_t *t = getinfo (key);
|
---|
78 | if (t == NULL) return 0;
|
---|
79 | return t->getint();
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | int infodbclass::getintinfo (const text_t &key, const text_t& slang)
|
---|
84 | {
|
---|
85 | text_tarray *t = getmultinfo(key, slang);
|
---|
86 | if (t == NULL || t->empty()) return 0;
|
---|
87 | return (*t)[0].getint();
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | text_t &infodbclass::operator[] (const text_t &key)
|
---|
92 | {
|
---|
93 | text_tarray &tarr = info[key];
|
---|
94 | if (tarr.empty()) {
|
---|
95 | text_t e;
|
---|
96 | tarr.push_back(e);
|
---|
97 | }
|
---|
98 | return tarr[0];
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | void infodbclass::addinfo (const text_t &key, const text_t &value)
|
---|
103 | {
|
---|
104 | text_tarray &tarr = info[key];
|
---|
105 | tarr.push_back (value);
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | void infodbclass::addintinfo (const text_t &key, int value)
|
---|
110 | {
|
---|
111 | addinfo (key, value);
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | void infodbclass::addcinfo (const text_t &key, unsigned short c)
|
---|
116 | {
|
---|
117 | text_t t;
|
---|
118 | t.push_back(c);
|
---|
119 | addinfo (key, t);
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | text_tarray *infodbclass::getmultinfo (const text_t &key)
|
---|
124 | {
|
---|
125 | iterator here = info.find (key);
|
---|
126 | if (here == info.end()) return NULL;
|
---|
127 |
|
---|
128 | return &((*here).second);
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | text_tarray *infodbclass::getmultinfo (const text_t &key, const text_t& slang)
|
---|
133 | {
|
---|
134 | iterator here = info.end();
|
---|
135 | if (slang.empty()) {
|
---|
136 | here = info.find (key);
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | here = info.find (key+":"+slang);
|
---|
140 | if (here == info.end()) {
|
---|
141 | here = info.find (key);
|
---|
142 | }
|
---|
143 | }
|
---|
144 | if (here == info.end()) return NULL;
|
---|
145 |
|
---|
146 | return &((*here).second);
|
---|
147 | }
|
---|