00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh 00005 * 00006 * This file is part of the Paludis package manager. Paludis is free software; 00007 * you can redistribute it and/or modify it under the terms of the GNU General 00008 * Public License version 2, as published by the Free Software Foundation. 00009 * 00010 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00013 * details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 * Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #ifndef PALUDIS_GUARD_PALUDIS_VERSION_SPEC_HH 00021 #define PALUDIS_GUARD_PALUDIS_VERSION_SPEC_HH 1 00022 00023 #include <paludis/version_spec-fwd.hh> 00024 #include <paludis/util/exception.hh> 00025 #include <paludis/util/private_implementation_pattern.hh> 00026 #include <paludis/util/operators.hh> 00027 #include <paludis/util/named_value.hh> 00028 #include <paludis/util/wrapped_forward_iterator-fwd.hh> 00029 00030 #include <iosfwd> 00031 #include <string> 00032 00033 /** \file 00034 * Declarations for VersionSpec classes. 00035 * 00036 * \ingroup g_names 00037 * 00038 * \section Examples 00039 * 00040 * - \ref example_version_spec.cc "example_version_spec.cc" 00041 * - \ref example_version_operator.cc "example_version_operator.cc" 00042 */ 00043 00044 namespace paludis 00045 { 00046 /** 00047 * Thrown if a VersionSpec is created from an invalid version string. 00048 * 00049 * \ingroup g_exceptions 00050 * \ingroup g_names 00051 */ 00052 class PALUDIS_VISIBLE BadVersionSpecError : 00053 public NameError 00054 { 00055 public: 00056 ///\name Basic operations 00057 ///\{ 00058 00059 BadVersionSpecError(const std::string & name) throw (); 00060 BadVersionSpecError(const std::string & name, const std::string & msg) throw (); 00061 00062 ///\} 00063 }; 00064 00065 namespace n 00066 { 00067 struct number_value; 00068 struct text; 00069 struct type; 00070 } 00071 00072 /** 00073 * A VersionSpec component part. 00074 * 00075 * This is mostly for use by the Exheres 'ever' API. 00076 * 00077 * The version 1.2x_pre3_rc-scm would be split up into these parts: 00078 * 00079 * - (type, number_value, text) 00080 * - (vsct_number, "1", "1") 00081 * - (vsct_number, "2", ".2") 00082 * - (vsct_letter, "x", "x") 00083 * - (vsct_pre, "3", "_pre3") 00084 * - (vsct_rc, "MAX" "_rc0") 00085 * - (vsct_scm, "0" "-scm") 00086 * 00087 * The type and number_value are mostly for internal use. In particular, the 00088 * number_value is not always what you might expect it to be. 00089 * 00090 * The text includes any preceeding delimiter. 00091 * 00092 * \ingroup g_names 00093 * \since 0.32 00094 */ 00095 struct VersionSpecComponent 00096 { 00097 NamedValue<n::number_value, std::string> number_value; 00098 NamedValue<n::text, std::string> text; 00099 NamedValue<n::type, VersionSpecComponentType> type; 00100 }; 00101 00102 /** 00103 * A VersionSpec represents a version number (for example, 1.2.3b-r1). 00104 * 00105 * \ingroup g_names 00106 */ 00107 class PALUDIS_VISIBLE VersionSpec : 00108 private PrivateImplementationPattern<VersionSpec>, 00109 public relational_operators::HasRelationalOperators 00110 { 00111 friend std::ostream & operator<< (std::ostream &, const VersionSpec &); 00112 00113 public: 00114 ///\name Basic operations 00115 ///\{ 00116 00117 /** 00118 * Constructor. 00119 * 00120 * \param options \since 0.38 00121 */ 00122 VersionSpec(const std::string & text, const VersionSpecOptions & options); 00123 00124 /** 00125 * Copy constructor. 00126 */ 00127 VersionSpec(const VersionSpec & other); 00128 00129 /** 00130 * Destructor. 00131 */ 00132 ~VersionSpec(); 00133 00134 /** 00135 * Assignment. 00136 */ 00137 const VersionSpec & operator= (const VersionSpec & other); 00138 00139 std::size_t hash() const PALUDIS_ATTRIBUTE((warn_unused_result)); 00140 00141 ///\} 00142 00143 ///\name Comparison operators 00144 ///\{ 00145 00146 /** 00147 * Comparison function for ~ depend operator. 00148 */ 00149 bool tilde_compare(const VersionSpec & other) const; 00150 00151 /** 00152 * Comparison function for ~> depend operator (gems). 00153 */ 00154 bool tilde_greater_compare(const VersionSpec & other) const; 00155 00156 /** 00157 * Comparison function for =* depend operator in sensible EAPIs. 00158 */ 00159 bool nice_equal_star_compare(const VersionSpec & other) const; 00160 00161 /** 00162 * Comparison function for =* depend operator in Gentooish EAPIs. 00163 */ 00164 bool stupid_equal_star_compare(const VersionSpec & other) const; 00165 00166 /** 00167 * Compare to another version. 00168 */ 00169 int compare(const VersionSpec & other) const; 00170 00171 bool operator== (const VersionSpec &) const; 00172 00173 bool operator< (const VersionSpec &) const; 00174 00175 ///\} 00176 00177 /** 00178 * Remove the revision part. 00179 */ 00180 VersionSpec remove_revision() const; 00181 00182 /** 00183 * Revision part only (or "r0"). 00184 */ 00185 std::string revision_only() const; 00186 00187 /** 00188 * Bump ourself. 00189 * 00190 * This is used by the ~> operator. It returns a version where the 00191 * next to last number is one greater (e.g. 5.3.1 => 5.4). Any non 00192 * number parts are stripped (e.g. 1.2.3_alpha4-r5 => 1.3). 00193 */ 00194 VersionSpec bump() const; 00195 00196 /** 00197 * Are we an -scm package, or something pretending to be one? 00198 */ 00199 bool is_scm() const; 00200 00201 /** 00202 * Do we have a -try part? 00203 */ 00204 bool has_try_part() const; 00205 00206 /** 00207 * Do we have an -scm part? 00208 * 00209 * Use is_scm() if -9999 etc is desired. 00210 */ 00211 bool has_scm_part() const; 00212 00213 /** 00214 * Do we have a local revision (-r1.2...)? 00215 */ 00216 bool has_local_revision() const; 00217 00218 struct ConstIteratorTag; 00219 typedef WrappedForwardIterator<ConstIteratorTag, const VersionSpecComponent> ConstIterator; 00220 ConstIterator begin() const; 00221 ConstIterator end() const; 00222 }; 00223 } 00224 00225 #endif