libept
vocabulary.h
Go to the documentation of this file.
1 #ifndef EPT_DEBTAGS_VOCABULARY_H
2 #define EPT_DEBTAGS_VOCABULARY_H
3 
9 /*
10  * Copyright (C) 2003,2004,2005,2006,2007 Enrico Zini <enrico@debian.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  */
26 
27 #include <string>
28 #include <vector>
29 #include <set>
30 #include <map>
31 
32 namespace tagcoll {
33 namespace input {
34 struct Input;
35 }
36 }
37 
38 namespace ept {
39 namespace debtags {
40 namespace voc {
41 
43 std::string getfacet(const std::string& tagname);
44 
46 struct Data : public std::map<std::string, std::string>
47 {
48 protected:
49  // Cache the parsed short description
50  mutable std::string m_desc;
51 
52 public:
53  std::string name;
54 
59  std::string shortDescription() const;
60 
66  std::string longDescription() const;
67 };
68 
92 struct TagData : public Data
93 {
94  TagData() {}
95 
96  // Facet facet() const;
97 };
98 
122 class FacetData : public Data
123 {
124 public:
125  std::map<std::string, TagData> m_tags;
126 
128 
129  TagData& obtainTag(const std::string& fullname);
130 
134  bool hasTag(const std::string& name) const;
135 
139  const TagData* tagData(const std::string& name) const;
140 
144  std::set<std::string> tags() const;
145 };
146 
147 }
148 
150 {
151 protected:
152  std::map<std::string, voc::FacetData> m_facets;
153 
154  time_t m_timestamp;
155 
156  // Empty parsed data to return when data is asked for IDs == -1
157  std::map<std::string, std::string> emptyData;
158 
159  void parseVocBuf(std::map<std::string, std::string>& res, size_t ofs, size_t len) const;
160 
161  voc::FacetData& obtainFacet(const std::string& name);
162  voc::TagData& obtainTag(const std::string& fullname);
163 
164 public:
172  Vocabulary(bool empty=false);
173  ~Vocabulary();
174 
176  time_t timestamp() const { return m_timestamp; }
177 
179  bool hasData() const { return m_timestamp != 0; }
180 
184  bool empty() const { return m_facets.empty(); }
185 
189  bool hasFacet(const std::string& name) const;
190 
194  bool hasTag(const std::string& name) const;
195 
199  const voc::FacetData* facetData(const std::string& name) const;
200 
204  const voc::TagData* tagData(const std::string& fullname) const;
205 
209  std::set<std::string> facets() const;
210 
214  std::set<std::string> tags() const;
215 
219  std::set<std::string> tags(const std::string& facet) const;
220 
221 #if 0
222 
223  const DerivedTagList& getEquations() const throw () { return equations; }
224 
226  FacetSet facets(const FacetMatcher& filter) const throw () { return getFiltered(filter); }
227 #endif
228 
233  void read(tagcoll::input::Input& input);
234 
238  void write();
239 
243  void write(const std::string& fname);
244 
248  void write(FILE* out);
249 };
250 
251 }
252 }
253 
254 // vim:set ts=4 sw=4:
255 #endif