libept
tag.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #ifndef EPT_DEBTAGS_TAG_H
3 #define EPT_DEBTAGS_TAG_H
4 
9 /*
10  * Copyright (C) 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 <set>
28 #include <string>
29 
30 namespace ept {
31 namespace debtags {
32 
33 class Vocabulary;
34 
35 class Tag;
36 
60 class Facet
61 {
62 protected:
64  int m_id;
65 
66  Facet(const Vocabulary* tags, int id) : m_tags(tags), m_id(id) {}
67 
68 public:
69  Facet() : m_tags(0), m_id(-1) {}
70  ~Facet() {}
71 
72  bool operator==(const Facet& f) const { return m_id == f.m_id; }
73  bool operator!=(const Facet& f) const { return m_id != f.m_id; }
74  bool operator<(const Facet& f) const { return m_id < f.m_id; }
75 
79  operator bool() const { return m_id != -1; }
80  bool valid() const { return m_id != -1; }
81 
86  std::string name() const;
92  std::string name(const std::string& d) const;
93 
98  std::string shortDescription() const;
104  std::string shortDescription(const std::string& d) const;
105 
110  std::string longDescription() const;
116  std::string longDescription(const std::string& d) const;
117 
121  bool hasTag(const std::string& name) const;
122 
126  std::set<Tag> tags() const;
127 
135  int id() const { return m_id; }
136 
137  friend class Vocabulary;
138 };
139 
163 class Tag
164 {
165 protected:
167  int m_id;
168 
169  Tag(const Vocabulary* tags, int id) : m_tags(tags), m_id(id) {}
170 
171 public:
172  typedef std::set< Tag > Set;
173 
174  Tag() : m_tags(0), m_id(-1) {}
175  ~Tag() {}
176 
177  bool operator==(const Tag& f) const { return m_id == f.m_id; }
178  bool operator!=(const Tag& f) const { return m_id != f.m_id; }
179  bool operator<(const Tag& f) const { return m_id < f.m_id; }
180 
181  operator bool() const { return m_id != -1; }
182  bool valid() const { return m_id != -1; }
183 
184  Facet facet() const;
185 
190  std::string name() const;
196  std::string name(const std::string& d) const;
197 
202  std::string fullname() const;
208  std::string fullname(const std::string& d) const;
209 
214  std::string shortDescription() const;
220  std::string shortDescription(const std::string& d) const;
221 
227  std::string longDescription() const;
233  std::string longDescription(const std::string& d) const;
234 
242  int id() const { return m_id; }
243 
244  friend class Vocabulary;
245 };
246 
247 }
248 }
249 
250 // vim:set ts=3 sw=3:
251 #endif