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
34namespace ept {
35namespace debtags {
36namespace voc {
37
39std::string getfacet(const std::string& tagname);
40
42struct Data : public std::map<std::string, std::string>
43{
44protected:
45 // Cache the parsed short description
46 mutable std::string m_desc;
47
48public:
49 std::string name;
50
55 std::string shortDescription() const;
56
62 std::string longDescription() const;
63};
64
88struct TagData : public Data
89{
91
92 // Facet facet() const;
93};
94
118class FacetData : public Data
119{
120public:
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{
147protected:
148 std::map<std::string, voc::FacetData> m_facets;
149
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
165public:
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
224 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
Definition vocabulary.h:146
void load(const std::string &pathname)
Load vocabulary data from the given file.
Definition vocabulary.cc:112
std::map< std::string, std::string > emptyData
Definition vocabulary.h:153
const voc::TagData * tagData(const std::string &fullname) const
Return the tag with the given full name.
Definition vocabulary.cc:183
time_t m_timestamp
Definition vocabulary.h:150
std::set< std::string > facets() const
Return all the facets in the vocabulary.
Definition vocabulary.cc:191
void parseVocBuf(std::map< std::string, std::string > &res, size_t ofs, size_t len) const
std::set< std::string > tags() const
Return all the tags in the vocabulary.
Definition vocabulary.cc:200
bool empty() const
Check if there is any data in the merged vocabulary.
Definition vocabulary.h:185
voc::TagData & obtainTag(const std::string &fullname)
Definition vocabulary.cc:156
bool hasTag(const std::string &name) const
Check if the vocabulary contains the tag ‘fullname’.
Definition vocabulary.cc:168
void write()
Atomically update the system vocabulary.
Definition vocabulary.cc:260
static std::string pathname()
Return the default pathname for the vocabulary.
Definition vocabulary.cc:105
void read(FILE *input, const std::string &pathname)
Parse and import the vocabulary from ‘input’, merging the data with the previously imported ones.
Definition vocabulary.cc:218
bool hasFacet(const std::string &name) const
Check if the vocabulary contains the facet ‘name’.
Definition vocabulary.cc:163
bool hasData() const
Return true if this data source has data, false if it's empty.
Definition vocabulary.h:180
voc::FacetData & obtainFacet(const std::string &name)
Definition vocabulary.cc:143
time_t timestamp() const
Get the timestamp of when the index was last updated.
Definition vocabulary.h:177
~Vocabulary()
Definition vocabulary.cc:101
std::map< std::string, voc::FacetData > m_facets
Definition vocabulary.h:148
const voc::FacetData * facetData(const std::string &name) const
Return the facet with the given name.
Definition vocabulary.cc:175
Representation of a facet.
Definition vocabulary.h:119
FacetData()
Definition vocabulary.h:123
TagData & obtainTag(const std::string &fullname)
Definition vocabulary.cc:130
const TagData * tagData(const std::string &name) const
Return the tag data for the given tag, or 0 if not found.
Definition vocabulary.cc:76
std::map< std::string, TagData > m_tags
Definition vocabulary.h:121
std::set< std::string > tags() const
Return the list of tags in this facet.
Definition vocabulary.cc:83
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:71
std::string getfacet(const std::string &tagname)
Extract the facet name from a tag name.
Definition vocabulary.cc:40
String functions.
Definition apt.cc:40
set< string > & res
Definition packagerecord.cc:73
Base class for facet and tag data.
Definition vocabulary.h:43
std::string m_desc
Definition vocabulary.h:46
std::string shortDescription() const
Return the short description of the tag.
Definition vocabulary.cc:49
std::string name
Definition vocabulary.h:49
std::string longDescription() const
Return the long description of the tag.
Definition vocabulary.cc:64
Representation of a tag.
Definition vocabulary.h:89
TagData()
Definition vocabulary.h:90