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 00085 std::string name() const; 00086 std::string name(const std::string& d) const; 00087 00091 std::string shortDescription() const; 00092 std::string shortDescription(const std::string& d) const; 00093 00097 std::string longDescription() const; 00098 std::string longDescription(const std::string& d) const; 00099 00103 bool hasTag(const std::string& name) const; 00104 00108 std::set<Tag> tags() const; 00109 00117 int id() const { return m_id; } 00118 00119 friend class Vocabulary; 00120 }; 00121 00145 class Tag 00146 { 00147 protected: 00148 const Vocabulary* m_tags; 00149 int m_id; 00150 00151 Tag(const Vocabulary* tags, int id) : m_tags(tags), m_id(id) {} 00152 00153 public: 00154 typedef std::set< Tag > Set; 00155 00156 Tag() : m_tags(0), m_id(-1) {} 00157 ~Tag() {} 00158 00159 bool operator==(const Tag& f) const { return m_id == f.m_id; } 00160 bool operator!=(const Tag& f) const { return m_id != f.m_id; } 00161 bool operator<(const Tag& f) const { return m_id < f.m_id; } 00162 00163 operator bool() const { return m_id != -1; } 00164 bool valid() const { return m_id != -1; } 00165 00166 Facet facet() const; 00167 00171 std::string name() const; 00172 std::string name(const std::string& d) const; 00173 00177 std::string fullname() const; 00178 std::string fullname(const std::string& d) const; 00179 00183 std::string shortDescription() const; 00184 std::string shortDescription(const std::string& d) const; 00185 00189 std::string longDescription() const; 00190 std::string longDescription(const std::string& d) const; 00191 00199 int id() const { return m_id; } 00200 00201 friend class Vocabulary; 00202 }; 00203 00204 } 00205 } 00206 00207 // vim:set ts=3 sw=3: 00208 #endif