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 #include <cstdio>
32 #include <iosfwd>
33 
34 namespace ept {
35 namespace debtags {
36 namespace voc {
37 
39 std::string getfacet(const std::string& tagname);
40 
42 struct Data : public std::map<std::string, std::string>
43 {
44 protected:
45  // Cache the parsed short description
46  mutable std::string m_desc;
47 
48 public:
49  std::string name;
50 
55  std::string shortDescription() const;
56 
62  std::string longDescription() const;
63 };
64 
88 struct TagData : public Data
89 {
90  TagData() {}
91 
92  // Facet facet() const;
93 };
94 
118 class FacetData : public Data
119 {
120 public:
121  std::map<std::string, TagData> m_tags;
122 
124 
125  TagData& obtainTag(const std::string& fullname);
126 
130  bool hasTag(const std::string& name) const;
131 
135  const TagData* tagData(const std::string& name) const;
136 
140  std::set<std::string> tags() const;
141 };
142 
143 }
144 
146 {
147 protected:
148  std::map<std::string, voc::FacetData> m_facets;
149 
150  time_t m_timestamp;
151 
152  // Empty parsed data to return when data is asked for IDs == -1
153  std::map<std::string, std::string> emptyData;
154 
155  void parseVocBuf(std::map<std::string, std::string>& res, size_t ofs, size_t len) const;
156 
157  voc::FacetData& obtainFacet(const std::string& name);
158  voc::TagData& obtainTag(const std::string& fullname);
159 
163  void write(std::ostream& out);
164 
165 public:
173  Vocabulary(bool empty=false);
174  ~Vocabulary();
175 
177  time_t timestamp() const { return m_timestamp; }
178 
180  bool hasData() const { return m_timestamp != 0; }
181 
185  bool empty() const { return m_facets.empty(); }
186 
190  bool hasFacet(const std::string& name) const;
191 
195  bool hasTag(const std::string& name) const;
196 
200  const voc::FacetData* facetData(const std::string& name) const;
201 
205  const voc::TagData* tagData(const std::string& fullname) const;
206 
210  std::set<std::string> facets() const;
211 
215  std::set<std::string> tags() const;
216 
220  std::set<std::string> tags(const std::string& facet) const;
221 
222 #if 0
223  const DerivedTagList& getEquations() const throw () { return equations; }
225 
227  FacetSet facets(const FacetMatcher& filter) const throw () { return getFiltered(filter); }
228 #endif
229 
231  void load(const std::string& pathname);
232 
237  void read(FILE* input, const std::string& pathname);
238 
242  void write();
243 
247  void write(const std::string& fname);
248 
255  static std::string pathname();
256 };
257 
258 }
259 }
260 
261 // vim:set ts=4 sw=4:
262 #endif
std::map< std::string, std::string > emptyData
Definition: vocabulary.h:153
FacetData()
Definition: vocabulary.h:123
std::string getfacet(const std::string &tagname)
Extract the facet name from a tag name.
Definition: vocabulary.cc:40
std::string name
Definition: vocabulary.h:49
Representation of a tag.
Definition: vocabulary.h:88
std::map< std::string, voc::FacetData > m_facets
Definition: vocabulary.h:148
bool hasData() const
Return true if this data source has data, false if it&#39;s empty.
Definition: vocabulary.h:180
std::string m_desc
Definition: vocabulary.h:46
std::string shortDescription() const
Return the short description of the tag.
Definition: vocabulary.cc:49
TagData()
Definition: vocabulary.h:90
String functions.
Definition: apt.cc:38
std::map< std::string, TagData > m_tags
Definition: vocabulary.h:121
Base class for facet and tag data.
Definition: vocabulary.h:42
bool empty() const
Check if there is any data in the merged vocabulary.
Definition: vocabulary.h:185
std::string longDescription() const
Return the long description of the tag.
Definition: vocabulary.cc:64
Definition: vocabulary.h:145
time_t m_timestamp
Definition: vocabulary.h:150
time_t timestamp() const
Get the timestamp of when the index was last updated.
Definition: vocabulary.h:177
set< string > & res
Definition: packagerecord.cc:73
Representation of a facet.
Definition: vocabulary.h:118