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 <time.h>
32 
33 namespace tagcoll {
34 namespace input {
35 struct Input;
36 }
37 }
38 
39 namespace ept {
40 namespace debtags {
41 namespace voc {
42 
44 std::string getfacet(const std::string& tagname);
45 
47 struct Data : public std::map<std::string, std::string>
48 {
49 protected:
50  // Cache the parsed short description
51  mutable std::string m_desc;
52 
53 public:
54  std::string name;
55 
60  std::string shortDescription() const;
61 
67  std::string longDescription() const;
68 };
69 
93 struct TagData : public Data
94 {
95  TagData() {}
96 
97  // Facet facet() const;
98 };
99 
123 class FacetData : public Data
124 {
125 public:
126  std::map<std::string, TagData> m_tags;
127 
129 
130  TagData& obtainTag(const std::string& fullname);
131 
135  bool hasTag(const std::string& name) const;
136 
140  const TagData* tagData(const std::string& name) const;
141 
145  std::set<std::string> tags() const;
146 };
147 
148 }
149 
151 {
152 protected:
153  std::map<std::string, voc::FacetData> m_facets;
154 
155  time_t m_timestamp;
156 
157  // Empty parsed data to return when data is asked for IDs == -1
158  std::map<std::string, std::string> emptyData;
159 
160  void parseVocBuf(std::map<std::string, std::string>& res, size_t ofs, size_t len) const;
161 
162  voc::FacetData& obtainFacet(const std::string& name);
163  voc::TagData& obtainTag(const std::string& fullname);
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 
234  void read(tagcoll::input::Input& input);
235 
239  void write();
240 
244  void write(const std::string& fname);
245 
249  void write(FILE* out);
250 };
251 
252 }
253 }
254 
255 // vim:set ts=4 sw=4:
256 #endif
std::map< std::string, std::string > emptyData
Definition: vocabulary.h:158
FacetData()
Definition: vocabulary.h:128
std::string getfacet(const std::string &tagname)
Extract the facet name from a tag name.
Definition: vocabulary.cc:43
std::string name
Definition: vocabulary.h:54
Representation of a tag.
Definition: vocabulary.h:93
std::map< std::string, voc::FacetData > m_facets
Definition: vocabulary.h:153
void read(tagcoll::input::Input &input)
Parse and import the vocabulary from `input', merging the data with the previously imported ones...
Definition: vocabulary.cc:205
std::set< std::string > tags() const
Return the list of tags in this facet.
Definition: vocabulary.cc:86
std::string m_desc
Definition: vocabulary.h:51
std::set< std::string > tags() const
Return all the tags in the vocabulary.
Definition: vocabulary.cc:187
TagData()
Definition: vocabulary.h:95
voc::FacetData & obtainFacet(const std::string &name)
Definition: vocabulary.cc:130
void parseVocBuf(std::map< std::string, std::string > &res, size_t ofs, size_t len) const
Definition: apt.cc:42
Vocabulary(bool empty=false)
Instantiate the Debtags vocabulary.
Definition: vocabulary.cc:97
std::string shortDescription() const
Return the short description of the tag.
Definition: vocabulary.cc:52
std::map< std::string, TagData > m_tags
Definition: vocabulary.h:126
bool empty() const
Check if there is any data in the merged vocabulary.
Definition: vocabulary.h:185
Base class for facet and tag data.
Definition: vocabulary.h:47
const TagData * tagData(const std::string &name) const
Return the tag data for the given tag, or 0 if not found.
Definition: vocabulary.cc:79
bool hasTag(const std::string &name) const
Check if the vocabulary contains the tag `fullname'.
Definition: vocabulary.cc:155
TagData & obtainTag(const std::string &fullname)
Definition: vocabulary.cc:117
const voc::TagData * tagData(const std::string &fullname) const
Return the tag with the given full name.
Definition: vocabulary.cc:170
Definition: vocabulary.h:150
Definition: debdbparser.h:31
std::set< std::string > facets() const
Return all the facets in the vocabulary.
Definition: vocabulary.cc:178
bool hasTag(const std::string &name) const
Return true if the facet has a tag with the given name (name, not fullname)
Definition: vocabulary.cc:74
bool hasFacet(const std::string &name) const
Check if the vocabulary contains the facet `name'.
Definition: vocabulary.cc:150
void write()
Atomically update the system vocabulary.
Definition: vocabulary.cc:248
bool hasData() const
Return true if this data source has data, false if it's empty.
Definition: vocabulary.h:180
~Vocabulary()
Definition: vocabulary.cc:113
time_t m_timestamp
Definition: vocabulary.h:155
std::string longDescription() const
Return the long description of the tag.
Definition: vocabulary.cc:67
set< string > & res
Definition: packagerecord.cc:73
Representation of a facet.
Definition: vocabulary.h:123
const voc::FacetData * facetData(const std::string &name) const
Return the facet with the given name.
Definition: vocabulary.cc:162
time_t timestamp() const
Get the timestamp of when the index was last updated.
Definition: vocabulary.h:177
voc::TagData & obtainTag(const std::string &fullname)
Definition: vocabulary.cc:143