~ubuntu-branches/ubuntu/vivid/debtags/vivid-proposed

« back to all changes in this revision

Viewing changes to libapt-front/apt-front/cache/entity/tag.h

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Zini
  • Date: 2006-03-18 20:31:47 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20060318203147-d9uzdeong5f5nk14
Tags: 1.5.5
* Added dumpavail command.
* Don't rebuild the database on install: apt-index-watcher does it instead.
  Closes: #357103.
* Compiles with g++ 4.1.  Closes: #357360.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef APTFRONT_CACHE_ENTITY_TAG_H
2
 
#define APTFRONT_CACHE_ENTITY_TAG_H
3
 
 
4
 
/** \file
5
 
 * Debtags facets and tags
6
 
 */
7
 
 
8
 
/*
9
 
 * Copyright (C) 2005  Enrico Zini <enrico@debian.org>
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or modify
12
 
 * it under the terms of the GNU General Public License as published by
13
 
 * the Free Software Foundation; either version 2 of the License, or
14
 
 * (at your option) any later version.
15
 
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 *
21
 
 * You should have received a copy of the GNU General Public License
22
 
 * along with this program; if not, write to the Free Software
23
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 
 */
25
 
 
26
 
#include <apt-front/cache/entity/entity.h>
27
 
 
28
 
#include <tagcoll/OpSet.h>
29
 
 
30
 
#if 0
31
 
#include <string>
32
 
#include <debtags/fdecls.h>
33
 
#endif
34
 
 
35
 
namespace aptFront {
36
 
namespace cache {
37
 
 
38
 
namespace component { class Tags; }
39
 
 
40
 
namespace entity {
41
 
 
42
 
class Tag;
43
 
 
44
 
/**
45
 
 * Representation of a facet.
46
 
 *
47
 
 * Tagcoll::Facet represents a Facet with all its informations.  It is
48
 
 * implemented via a reference-counted smart pointer, so it can be passed
49
 
 * around freely and efficiently without worrying about memory management
50
 
 * issues.
51
 
 *
52
 
 * The class is normally instantiated using a Vocabulary:
53
 
 * \code
54
 
 *      Facet facet = vocabulary.faceByNamet("made-of");
55
 
 * \endcode
56
 
 *
57
 
 * Facets can contain a "false" value, in which case using any of their
58
 
 * methonds produce a null-pointer dereference segfault.  The "null" facets are
59
 
 * useful as "none" return values:
60
 
 *
61
 
 * \code
62
 
 *    Facet facet = vocabulary.facetByName("made-of");
63
 
 *    if (!facet)
64
 
 *       throw ConsistencyCheckException("facet \"made-of\" has not been defined");
65
 
 * \endcode
66
 
 */
67
 
class Facet : public Implementation<Facet>
68
 
{
69
 
protected:
70
 
        struct Data
71
 
        {
72
 
                std::string name;
73
 
                std::string shortDesc;
74
 
                std::string longDesc;
75
 
                Data(const std::string& name)
76
 
                        : name(name) {}
77
 
                Data(const std::string& name, const std::string& sd, const std::string& ld)
78
 
                        : name(name), shortDesc(sd), longDesc(ld) {}
79
 
        };
80
 
 
81
 
        
82
 
        int index;
83
 
 
84
 
        Facet(Cache *c, int index) : index(index) {
85
 
                setCache( c );
86
 
        }
87
 
 
88
 
public:
89
 
        Facet() : index(-1) {}
90
 
        ~Facet() {}
91
 
 
92
 
        bool operator==(const Facet& f) const { return index == f.index; }
93
 
        bool operator<(const Facet& f) const { return index < f.index; }
94
 
 
95
 
        /**
96
 
         * Return true if the facet is valid
97
 
         */
98
 
        operator bool() const { return index != -1; }
99
 
        bool valid() const { return index != -1; }
100
 
 
101
 
        /**
102
 
         * Return the name of the facet
103
 
         */
104
 
        std::string name() const;
105
 
        std::string name(const std::string& d) const;
106
 
 
107
 
        /**
108
 
         * Return the short description of the facet
109
 
         */
110
 
        std::string shortDescription() const;
111
 
        std::string shortDescription(const std::string& d) const;
112
 
 
113
 
        /**
114
 
         * Return the long description of the facet
115
 
         */
116
 
        std::string longDescription() const;
117
 
        std::string longDescription(const std::string& d) const;
118
 
 
119
 
        /**
120
 
         * Return true if the facet has a tag with the given name (name, not fullname)
121
 
         */
122
 
        bool hasTag(const std::string& name) const;
123
 
 
124
 
        /**
125
 
         * Return the list of tags in this facet
126
 
         */
127
 
        Tagcoll::OpSet<Tag> tags() const;
128
 
 
129
 
        friend class entity::Tag;
130
 
        friend class component::Tags;
131
 
};
132
 
 
133
 
/**
134
 
 * Representation of a tag.
135
 
 *
136
 
 * Tagcoll::Tag represents a Tag with all its informations.  It is implemented
137
 
 * via a reference-counted smart pointer, so it can be passed around freely and
138
 
 * efficiently without worrying about memory management issues.
139
 
 *
140
 
 * The class is normally instantiated using a Vocabulary:
141
 
 * \code
142
 
 *      Tag tag = vocabulary.tagByName("made-of::lang:c++");
143
 
 * \endcode
144
 
 *
145
 
 * Tags can contain a "false" value, in which case using any of their
146
 
 * methonds produce a null-pointer dereference segfault.  The "null" tags are
147
 
 * useful as "none" return values:
148
 
 *
149
 
 * \code
150
 
 *    Tag tag = vocabulary.tagByName("made-of");
151
 
 *    if (!tag)
152
 
 *       throw ConsistencyCheckException("tag \"mytag\" has not been defined");
153
 
 * \endcode
154
 
 */
155
 
class Tag : public Implementation<Tag>
156
 
{
157
 
protected:
158
 
        struct Data
159
 
        {
160
 
                int facet;
161
 
                std::string name;
162
 
                std::string shortDesc;
163
 
                std::string longDesc;
164
 
                Data(int facet, const std::string& name)
165
 
                        : facet(facet), name(name) {}
166
 
                Data(int facet, const std::string& name, const std::string& sd, const std::string& ld)
167
 
                        : facet(facet), name(name), shortDesc(sd), longDesc(ld) {}
168
 
        };
169
 
 
170
 
        int index;
171
 
 
172
 
        Tag(Cache *c, int index) : index(index) {
173
 
                setCache( c );
174
 
        }
175
 
 
176
 
public:
177
 
        Tag() : index(-1) {}
178
 
        ~Tag() {}
179
 
 
180
 
        bool operator==(const Tag& f) const { return index == f.index; }
181
 
        bool operator<(const Tag& f) const { return index < f.index; }
182
 
 
183
 
        operator bool() const { return index != -1; }
184
 
        bool valid() const { return index != -1; }
185
 
 
186
 
        Facet facet() const;
187
 
 
188
 
        /**
189
 
         * Return the name of the tag, without the facet:: prefix
190
 
         */
191
 
        std::string name() const;
192
 
        std::string name(const std::string& d) const;
193
 
 
194
 
        /**
195
 
         * Return the name of the tag, with the facet:: prefix
196
 
         */
197
 
        std::string fullname() const;
198
 
        std::string fullname(const std::string& d) const;
199
 
 
200
 
        /**
201
 
         * Return the short description of the tag
202
 
         */
203
 
        std::string shortDescription() const;
204
 
        std::string shortDescription(const std::string& d) const;
205
 
 
206
 
        /**
207
 
         * Return the long description of the tag
208
 
         */
209
 
        std::string longDescription() const;
210
 
        std::string longDescription(const std::string& d) const;
211
 
 
212
 
        friend class component::Tags;
213
 
};
214
 
 
215
 
}
216
 
}
217
 
}
218
 
 
219
 
// vim:set ts=3 sw=3:
220
 
#endif