paludis Version 3.0.2
The one true package mangler
package_id.hh
Go to the documentation of this file.
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2014 Ciaran McCreesh
5 *
6 * This file is part of the Paludis package manager. Paludis is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU General
8 * Public License version 2, as published by the Free Software Foundation.
9 *
10 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifndef PALUDIS_GUARD_PALUDIS_PACKAGE_ID_HH
21#define PALUDIS_GUARD_PALUDIS_PACKAGE_ID_HH 1
22
24
26#include <paludis/util/fs_path-fwd.hh>
27#include <paludis/util/iterator_range.hh>
28#include <paludis/util/operators.hh>
29#include <paludis/util/pimp.hh>
31#include <paludis/util/set.hh>
32#include <paludis/util/wrapped_forward_iterator.hh>
33#include <paludis/util/wrapped_output_iterator.hh>
34
35#include <paludis/action-fwd.hh>
36#include <paludis/choice-fwd.hh>
39#include <paludis/mask-fwd.hh>
41#include <paludis/metadata_key_holder.hh>
42#include <paludis/name-fwd.hh>
44#include <paludis/slot-fwd.hh>
45#include <paludis/spec_tree-fwd.hh>
47
48#include <memory>
49
50/** \file
51 * Declarations for PackageID classes.
52 *
53 * \ingroup g_package_id
54 *
55 * \section Examples
56 *
57 * - \ref example_package_id.cc "example_package_id.cc" (for package IDs)
58 * - \ref example_action.cc "example_action.cc" (for actions)
59 * - \ref example_metadata_key.cc "example_metadata_key.cc" (for metadata keys)
60 * - \ref example_mask.cc "example_mask.cc" (for masks)
61 */
62
63namespace paludis
64{
65 /**
66 * A PackageID represents a unique package version in a particular
67 * Repository.
68 *
69 * All PackageID instances have some basic identification data:
70 *
71 * - A name
72 * - A version
73 * - An owning repository
74 *
75 * It should be noted that the above together are not sufficient to uniquely
76 * identify a package. Some repositories support multiple slots per version
77 * of a package, and some repositories support additional affixes that
78 * prevent a package from being uniquely identifiable merely by the above.
79 *
80 * PackageID instances also have:
81 *
82 * - A collection of metadata keys. Some of these keys have a particular
83 * specific role in certain places. These can be fetched via blah_key()
84 * methods, all of which may return an empty pointer. Other keys have no
85 * meaningful global role, and can only be fetched using the iteration
86 * methods.
87 *
88 * - A collection (often empty) of masks. A masked package cannot be
89 * installed.
90 *
91 * A PackageID instance may support certain actions, which are represented
92 * via an Action subclass instance.
93 *
94 * \ingroup g_package_id
95 */
96 class PALUDIS_VISIBLE PackageID :
98 public MetadataKeyHolder
99 {
100 private:
101 Pimp<PackageID> _imp;
102
103 protected:
104 /**
105 * Add a new Mask.
106 */
107 virtual void add_mask(const std::shared_ptr<const Mask> &) const;
108
109 /**
110 * Add a new OverriddenMask.
111 *
112 * \since 0.34
113 */
114 virtual void add_overridden_mask(const std::shared_ptr<const OverriddenMask> &) const;
115
116 /**
117 * This method will be called before any of the mask iteration
118 * methods does its work. It can be used by subclasses to implement
119 * as-needed loading of masks.
120 */
121 virtual void need_masks_added() const = 0;
122
123 public:
124 ///\name Basic operations
125 ///\{
126
127 PackageID();
128 ~PackageID() override = 0;
129
130 std::size_t hash() const PALUDIS_ATTRIBUTE((warn_unused_result));
131
132 ///\}
133
134 ///\name Name related operations
135 ///\{
136
137 /**
138 * Return our canonical string representation.
139 *
140 * This method (which is called by paludis::stringify()) should be
141 * used when outputting a PackageID or a PackageID's version. Some
142 * repositories need to display additional information to identify a
143 * package, so outputting merely the name and / or version may be
144 * insufficient.
145 */
146 virtual const std::string canonical_form(const PackageIDCanonicalForm) const = 0;
147
148 /**
149 * What is our package name?
150 *
151 * Use canonical_form instead for outputting.
152 */
153 virtual const QualifiedPackageName name() const = 0;
154
155 /**
156 * What is our package version?
157 *
158 * Use canonical_form instead for outputting.
159 */
160 virtual const VersionSpec version() const = 0;
161
162 /**
163 * What is our owning repository?
164 *
165 * \since 0.58
166 */
167 virtual const RepositoryName repository_name() const = 0;
168
169 /**
170 * Return a PackageDepSpec that uniquely identifies us.
171 *
172 * When stringified, can be turned back into an equivalent unique
173 * PackageDepSpec by using parse_user_package_dep_spec.
174 *
175 * \since 0.36
176 */
178
179 ///\}
180
181 ///\name Specific metadata keys
182 ///\{
183
184 /**
185 * The slot, if specified, controls whether the package can be
186 * installed in parallel with other versions of the same package.
187 *
188 * \since 0.36
189 */
190 virtual const std::shared_ptr<const MetadataValueKey<Slot> > slot_key() const = 0;
191
192 /**
193 * The keywords_key, if non-zero, is used by FindUnusedPackagesTask
194 * to determine whether a package is unused.
195 */
196 virtual const std::shared_ptr<const MetadataCollectionKey<KeywordNameSet> > keywords_key() const = 0;
197
198 /**
199 * The dependencies_key, if non-zero, provides all of a package's
200 * dependencies.
201 *
202 * If dependencies_key is used, the client should ignore
203 * build_dependencies_key, run_dependencies_key and post_dependencies_key.
204 *
205 * Repositories that support this key must also provide the old
206 * split out keys.
207 *
208 * \since 0.41
209 */
210 virtual const std::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > dependencies_key() const = 0;
211
212 /**
213 * The build_dependencies_key, if non-zero, indicates a package's
214 * build-time dependencies.
215 */
216 virtual const std::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > build_dependencies_key() const = 0;
217
218 /**
219 * The run_dependencies_key, if non-zero, indicates a package's
220 * run-time dependencies.
221 */
222 virtual const std::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > run_dependencies_key() const = 0;
223
224 /**
225 * The post_dependencies_key, if non-zero, indicates a package's
226 * post-merge dependencies.
227 */
228 virtual const std::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > post_dependencies_key() const = 0;
229
230 /**
231 * The fetches_key, if non-zero, indicates files that have to be fetched
232 * in order to install a package.
233 */
234 virtual const std::shared_ptr<const MetadataSpecTreeKey<FetchableURISpecTree> > fetches_key() const = 0;
235
236 /**
237 * The homepage_key, if non-zero, describes a package's homepages.
238 */
239 virtual const std::shared_ptr<const MetadataSpecTreeKey<SimpleURISpecTree> > homepage_key() const = 0;
240
241 /**
242 * The short_description_key, if non-zero, provides a short (no more
243 * than a few hundred characters) description of a package.
244 */
245 virtual const std::shared_ptr<const MetadataValueKey<std::string> > short_description_key() const = 0;
246
247 /**
248 * The long_description_key, if non-zero, provides a long
249 * description of a package.
250 */
251 virtual const std::shared_ptr<const MetadataValueKey<std::string> > long_description_key() const = 0;
252
253 /**
254 * The installed_time_key, if non-zero, contains the time a package
255 * was installed. It affects dependency resolution if DepList is
256 * using dl_reinstall_scm_daily or dl_reinstall_scm_weekly.
257 */
258 virtual const std::shared_ptr<const MetadataTimeKey> installed_time_key() const = 0;
259
260 /**
261 * The from_repositories key, if non-zero, contains the set of repositories
262 * that the ID is 'from'. An ID can be 'from' multiple repositories if, for
263 * example, it was built via a binary package.
264 */
265 virtual const std::shared_ptr<const MetadataCollectionKey<Set<std::string> > > from_repositories_key() const = 0;
266
267 /**
268 * The fs_location_key, if non-zero, indicates the filesystem
269 * location (for example, the ebuild file or VDB directory) that
270 * best describes the location of a PackageID.
271 */
272 virtual const std::shared_ptr<const MetadataValueKey<FSPath> > fs_location_key() const = 0;
273
274 /**
275 * The choices_key, if non-zero, contains zero or more
276 * MetadataValueKey<std::shared_ptr<const Choice> > child
277 * keys holding choice information for this ID.
278 */
279 virtual const std::shared_ptr<const MetadataValueKey<std::shared_ptr<const Choices> > > choices_key() const = 0;
280
281 /**
282 * The behaviours_key may contain strings indicating that the PackageID
283 * behaves in a particular way.
284 *
285 * Strings with recognised meanings currently are:
286 *
287 * - "transient", saying that an installed ID's origin is expected not to exist
288 * - "used", saying that an installed ID should not be treated as unused
289 * - "unbinaryable", saying that we should be excluded from requests to create a binary
290 * - "unchrootable", saying that we should be excluded from requests to install to a chroot
291 * - "binary", saying that we are already a binary package
292 *
293 * \since 0.48
294 */
295 virtual const std::shared_ptr<const MetadataCollectionKey<Set<std::string> > > behaviours_key() const = 0;
296
297 ///\}
298
299 ///\name Actions
300 ///\{
301
302 /**
303 * Do we support a particular action?
304 *
305 * Attempting to call perform_action with an unsupported action type
306 * will lead to an UnsupportedActionError. However, in performance
307 * critical code and in situations where creating a full Action
308 * subclass instance is non-trivial, supports_action is much
309 * simpler.
310 */
311 virtual bool supports_action(const SupportsActionTestBase &) const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
312
313 /**
314 * Perform the specified action.
315 */
316 virtual void perform_action(Action &) const = 0;
317
318 /**
319 * The contents, if non-zero, contains the contents of a
320 * package. For installed packages, this means the files installed;
321 * for installable packages, this means the files that will be
322 * installed (if known, which it may be for some binary packages).
323 *
324 * \since 0.66
325 */
326 virtual const std::shared_ptr<const Contents> contents() const = 0;
327
328 ///\}
329
330 ///\name Masks
331 ///\{
332
333 struct MasksConstIteratorTag;
334 typedef WrappedForwardIterator<MasksConstIteratorTag, const std::shared_ptr<const Mask> > MasksConstIterator;
335
336 MasksConstIterator begin_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
337 MasksConstIterator end_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
338 IteratorRange<MasksConstIterator> masks() const;
339
340 /**
341 * Do we have any effective masks? Equivalent to begin_masks() != end_masks().
342 */
343 bool masked() const PALUDIS_ATTRIBUTE((warn_unused_result));
344
345 ///\}
346
347 ///\name Overridden masks
348 ///\{
349 ///\since 0.34
350
351 struct OverriddenMasksConstIteratorTag;
352 typedef WrappedForwardIterator<OverriddenMasksConstIteratorTag, const std::shared_ptr<const OverriddenMask> > OverriddenMasksConstIterator;
353
354 OverriddenMasksConstIterator begin_overridden_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
355 OverriddenMasksConstIterator end_overridden_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
356 IteratorRange<OverriddenMasksConstIterator> overridden_masks() const;
357
358 ///\}
359
360 ///\name Extra comparisons
361 ///\{
362
363 /**
364 * Perform an arbitrary less than comparison on another PackageID.
365 *
366 * Used by PackageIDSetComparator and operator==. This function
367 * should not be used by anything else.
368 *
369 * This function will only be called if the other PackageID has the
370 * same name, version and repository as this. If this is not enough
371 * to uniquely identify an ID (e.g. if there is an affix, or if multiple
372 * slots per version are allowed), then this function's
373 * implementation must differentiate appropriately.
374 */
375 virtual bool arbitrary_less_than_comparison(const PackageID &) const
376 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
377
378 /**
379 * Provide any additional hash information for a PackageID.
380 *
381 * The standard PackageID hash incorporates the repository name, the
382 * package name and the version of the package. If this function is
383 * defined, its value is also used when determining a hash. This can
384 * provide increased performance if a repository uses affixes or
385 * multiple slots per version.
386 */
387 virtual std::size_t extra_hash_value() const
388 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
389
390 ///\}
391
392 /**
393 * Allow the PackageID to drop any memory-cached metadata it holds.
394 *
395 * \since 0.42
396 */
397 virtual void can_drop_in_memory_cache() const;
398 };
399
400 /**
401 * PackageID instances are equality-comparable.
402 *
403 * \ingroup g_package_id
404 * \since 0.26
405 */
406 bool operator== (const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
407
408 /**
409 * A comparison functor that uses PackageID::arbitrary_less_than_comparison
410 * to provide a meaningless but stable ordering for PackageIDSet.
411 *
412 * \ingroup g_package_id
413 * \since 0.26
414 * \nosubgrouping
415 */
417 {
418 public:
419 /**
420 * Perform an arbitrary less-than comparison.
421 */
422 bool operator() (const std::shared_ptr<const PackageID> &,
423 const std::shared_ptr<const PackageID> &) const;
424 };
425
426 /**
427 * A comparison functor that provides a less-than comparison on PackageID
428 * instances according to, in order, their name, their version, their
429 * repository's importance according to the supplied Environment,
430 * and Environment::arbitrary_less_than_comparison.
431 *
432 * \ingroup g_package_id
433 * \since 0.26
434 * \nosubgrouping
435 */
436 class PALUDIS_VISIBLE PackageIDComparator
437 {
438 private:
440
441 public:
442 ///\name Standard library typedefs
443 ///\{
444
445 typedef bool result_type;
446
447 ///\}
448
449 ///\name Basic operations
450 ///\{
451
452 PackageIDComparator(const Environment * const);
453 PackageIDComparator(const PackageIDComparator &);
454 ~PackageIDComparator();
455
456 ///\}
457
458 /**
459 * Perform the less-than comparison.
460 */
461 bool operator() (const std::shared_ptr<const PackageID> &,
462 const std::shared_ptr<const PackageID> &) const;
463 };
464
467 const std::shared_ptr<const PackageID> >;
468 extern template class PALUDIS_VISIBLE WrappedForwardIterator<Sequence<std::shared_ptr<const PackageID> >::ReverseConstIteratorTag,
469 const std::shared_ptr<const PackageID> >;
471 std::shared_ptr<const PackageID> >;
472
475 const std::shared_ptr<const PackageID> >;
477 std::shared_ptr<const PackageID> >;
478
481}
482
483#endif
Definition action.hh:278
Definition choice.hh:152
Definition contents.hh:214
Definition environment.hh:203
Definition fs_path.hh:34
Definition iterator_range.hh:29
Definition mask.hh:75
Definition metadata_key.hh:279
Definition metadata_key.hh:305
Definition metadata_key.hh:253
Definition metadata_key.hh:229
Definition dep_spec.hh:348
Definition package_id.hh:417
Definition package_id.hh:99
virtual const std::shared_ptr< const Contents > contents() const =0
virtual std::size_t extra_hash_value() const PALUDIS_ATTRIBUTE((warn_unused_result))=0
virtual const std::shared_ptr< const MetadataTimeKey > installed_time_key() const =0
virtual const std::shared_ptr< const MetadataCollectionKey< Set< std::string > > > from_repositories_key() const =0
virtual const std::shared_ptr< const MetadataCollectionKey< Set< std::string > > > behaviours_key() const =0
virtual void perform_action(Action &) const =0
virtual void add_overridden_mask(const std::shared_ptr< const OverriddenMask > &) const
virtual const std::shared_ptr< const MetadataValueKey< std::shared_ptr< const Choices > > > choices_key() const =0
virtual bool arbitrary_less_than_comparison(const PackageID &) const PALUDIS_ATTRIBUTE((warn_unused_result))=0
virtual const std::shared_ptr< const MetadataCollectionKey< KeywordNameSet > > keywords_key() const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< DependencySpecTree > > post_dependencies_key() const =0
virtual void can_drop_in_memory_cache() const
virtual const std::shared_ptr< const MetadataValueKey< FSPath > > fs_location_key() const =0
virtual const QualifiedPackageName name() const =0
virtual const std::shared_ptr< const MetadataValueKey< std::string > > short_description_key() const =0
virtual const std::shared_ptr< const MetadataValueKey< std::string > > long_description_key() const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< DependencySpecTree > > build_dependencies_key() const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< DependencySpecTree > > run_dependencies_key() const =0
bool masked() const PALUDIS_ATTRIBUTE((warn_unused_result))
virtual const RepositoryName repository_name() const =0
virtual bool supports_action(const SupportsActionTestBase &) const PALUDIS_ATTRIBUTE((warn_unused_result))=0
virtual const std::string canonical_form(const PackageIDCanonicalForm) const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< FetchableURISpecTree > > fetches_key() const =0
virtual const VersionSpec version() const =0
virtual PackageDepSpec uniquely_identifying_spec() const =0
virtual void need_masks_added() const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< DependencySpecTree > > dependencies_key() const =0
virtual void add_mask(const std::shared_ptr< const Mask > &) const
virtual const std::shared_ptr< const MetadataValueKey< Slot > > slot_key() const =0
virtual const std::shared_ptr< const MetadataSpecTreeKey< SimpleURISpecTree > > homepage_key() const =0
Definition pimp.hh:52
Definition name.hh:112
Definition sequence.hh:51
Definition set.hh:51
Definition action.hh:633
Definition version_spec.hh:109
Definition wrapped_forward_iterator.hh:42
Definition wrapped_output_iterator.hh:38
WrappedValue< RepositoryNameTag > RepositoryName
Definition name-fwd.hh:105
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24
Definition mask.hh:202
Definition slot.hh:44