00001 // -*- C++ -*- 00002 #ifndef EPT_DEBTAGS_TAG_H 00003 #define EPT_DEBTAGS_TAG_H 00004 00009 /* 00010 * Copyright (C) 2005,2006,2007 Enrico Zini <enrico@debian.org> 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 */ 00026 00027 #include <set> 00028 #include <string> 00029 00030 namespace ept { 00031 namespace debtags { 00032 00033 class Vocabulary; 00034 00035 class Tag; 00036 00060 class Facet 00061 { 00062 protected: 00063 const Vocabulary* m_tags; 00064 int m_id; 00065 00066 Facet(const Vocabulary* tags, int id) : m_tags(tags), m_id(id) {} 00067 00068 public: 00069 Facet() : m_tags(0), m_id(-1) {} 00070 ~Facet() {} 00071 00072 bool operator==(const Facet& f) const { return m_id == f.m_id; } 00073 bool operator!=(const Facet& f) const { return m_id != f.m_id; } 00074 bool operator<(const Facet& f) const { return m_id < f.m_id; } 00075 00079 operator bool() const { return m_id != -1; } 00080 bool valid() const { return m_id != -1; } 00081 00086 std::string name() const; 00092 std::string name(const std::string& d) const; 00093 00098 std::string shortDescription() const; 00104 std::string shortDescription(const std::string& d) const; 00105 00110 std::string longDescription() const; 00116 std::string longDescription(const std::string& d) const; 00117 00121 bool hasTag(const std::string& name) const; 00122 00126 std::set<Tag> tags() const; 00127 00135 int id() const { return m_id; } 00136 00137 friend class Vocabulary; 00138 }; 00139 00163 class Tag 00164 { 00165 protected: 00166 const Vocabulary* m_tags; 00167 int m_id; 00168 00169 Tag(const Vocabulary* tags, int id) : m_tags(tags), m_id(id) {} 00170 00171 public: 00172 typedef std::set< Tag > Set; 00173 00174 Tag() : m_tags(0), m_id(-1) {} 00175 ~Tag() {} 00176 00177 bool operator==(const Tag& f) const { return m_id == f.m_id; } 00178 bool operator!=(const Tag& f) const { return m_id != f.m_id; } 00179 bool operator<(const Tag& f) const { return m_id < f.m_id; } 00180 00181 operator bool() const { return m_id != -1; } 00182 bool valid() const { return m_id != -1; } 00183 00184 Facet facet() const; 00185 00190 std::string name() const; 00196 std::string name(const std::string& d) const; 00197 00202 std::string fullname() const; 00208 std::string fullname(const std::string& d) const; 00209 00214 std::string shortDescription() const; 00220 std::string shortDescription(const std::string& d) const; 00221 00227 std::string longDescription() const; 00233 std::string longDescription(const std::string& d) const; 00234 00242 int id() const { return m_id; } 00243 00244 friend class Vocabulary; 00245 }; 00246 00247 } 00248 } 00249 00250 // vim:set ts=3 sw=3: 00251 #endif