paludis  Version 2.6.0
version_spec.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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_VERSION_SPEC_HH
21 #define PALUDIS_GUARD_PALUDIS_VERSION_SPEC_HH 1
22 
25 #include <paludis/util/pimp.hh>
26 #include <paludis/util/operators.hh>
27 #include <paludis/util/named_value.hh>
28 #include <paludis/util/wrapped_forward_iterator.hh>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 /** \file
34  * Declarations for VersionSpec classes.
35  *
36  * \ingroup g_names
37  *
38  * \section Examples
39  *
40  * - \ref example_version_spec.cc "example_version_spec.cc"
41  * - \ref example_version_operator.cc "example_version_operator.cc"
42  */
43 
44 namespace paludis
45 {
46  /**
47  * Thrown if a VersionSpec is created from an invalid version string.
48  *
49  * \ingroup g_exceptions
50  * \ingroup g_names
51  */
53  public NameError
54  {
55  public:
56  ///\name Basic operations
57  ///\{
58 
59  BadVersionSpecError(const std::string & name) noexcept;
60  BadVersionSpecError(const std::string & name, const std::string & msg) noexcept;
61 
62  ///\}
63  };
64 
65  namespace n
66  {
67  typedef Name<struct name_number_value> number_value;
68  typedef Name<struct name_text> text;
69  typedef Name<struct name_type> type;
70  }
71 
72  /**
73  * A VersionSpec component part.
74  *
75  * This is mostly for use by the Exheres 'ever' API.
76  *
77  * The version 1.2x_pre3_rc-scm would be split up into these parts:
78  *
79  * - (type, number_value, text)
80  * - (vsct_number, "1", "1")
81  * - (vsct_number, "2", ".2")
82  * - (vsct_letter, "x", "x")
83  * - (vsct_pre, "3", "_pre3")
84  * - (vsct_rc, "MAX" "_rc0")
85  * - (vsct_scm, "0" "-scm")
86  *
87  * The type and number_value are mostly for internal use. In particular, the
88  * number_value is not always what you might expect it to be.
89  *
90  * The text includes any preceeding delimiter.
91  *
92  * \ingroup g_names
93  * \since 0.32
94  */
96  {
100  };
101 
102  /**
103  * A VersionSpec represents a version number (for example, 1.2.3b-r1).
104  *
105  * \ingroup g_names
106  */
109  {
110  friend std::ostream & operator<< (std::ostream &, const VersionSpec &);
111 
112  private:
113  Pimp<VersionSpec> _imp;
114 
115  public:
116  ///\name Basic operations
117  ///\{
118 
119  /**
120  * Constructor.
121  *
122  * \param options \since 0.38
123  */
124  VersionSpec(const std::string & text, const VersionSpecOptions & options);
125 
126  /**
127  * Copy constructor.
128  */
129  VersionSpec(const VersionSpec & other);
130 
131  /**
132  * Destructor.
133  */
134  ~VersionSpec();
135 
136  /**
137  * Assignment.
138  */
139  const VersionSpec & operator= (const VersionSpec & other);
140 
141  std::size_t hash() const PALUDIS_ATTRIBUTE((warn_unused_result));
142 
143  ///\}
144 
145  ///\name Comparison operators
146  ///\{
147 
148  /**
149  * Comparison function for ~ depend operator.
150  */
151  bool tilde_compare(const VersionSpec & other) const;
152 
153  /**
154  * Comparison function for ~> depend operator (gems).
155  */
156  bool tilde_greater_compare(const VersionSpec & other) const;
157 
158  /**
159  * Comparison function for =* depend operator.
160  */
161  bool equal_star_compare(const VersionSpec & other) const;
162 
163  /**
164  * Compare to another version.
165  */
166  int compare(const VersionSpec & other) const;
167 
168  bool operator== (const VersionSpec &) const;
169 
170  bool operator< (const VersionSpec &) const;
171 
172  ///\}
173 
174  /**
175  * Remove the revision part.
176  */
177  VersionSpec remove_revision() const;
178 
179  /**
180  * Revision part only (or "r0").
181  */
182  std::string revision_only() const;
183 
184  /**
185  * Bump ourself.
186  *
187  * This is used by the ~> operator. It returns a version where the
188  * next to last number is one greater (e.g. 5.3.1 => 5.4). Any non
189  * number parts are stripped (e.g. 1.2.3_alpha4-r5 => 1.3).
190  */
191  VersionSpec bump() const;
192 
193  /**
194  * Are we an -scm package, or something pretending to be one?
195  */
196  bool is_scm() const;
197 
198  /**
199  * Do we have a -try part?
200  */
201  bool has_try_part() const;
202 
203  /**
204  * Do we have an -scm part?
205  *
206  * Use is_scm() if -9999 etc is desired.
207  */
208  bool has_scm_part() const;
209 
210  /**
211  * Do we have a local revision (-r1.2...)?
212  */
213  bool has_local_revision() const;
214 
215  struct ConstIteratorTag;
217  ConstIterator begin() const;
218  ConstIterator end() const;
219  };
220 
222 }
223 
224 #endif
Definition: named_value-fwd.hh:29
Definition: pimp.hh:51
Definition: about_metadata-fwd.hh:23
Definition: exception.hh:171
Definition: version_spec.hh:107
Definition: version_spec.hh:52
std::ostream & operator<<(std::ostream &, const WantPhase &) PALUDIS_VISIBLE
Definition: wrapped_forward_iterator-fwd.hh:26
Definition: options-fwd.hh:34
Definition: version_spec.hh:95
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:53
#define PALUDIS_VISIBLE
Definition: attributes.hh:59
bool operator==(const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE