1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Edition.h
12 #ifndef ZYPP_EDITION_H
13 #define ZYPP_EDITION_H
19 #include "zypp/IdStringType.h"
20 #include "zypp/RelCompare.h"
21 #include "zypp/Range.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 // CLASS NAME : Edition
31 /** Edition represents <code>[epoch:]version[-release]</code>
33 * \li \c epoch (optional) number, Edition::noepoch if not supplied
34 * \li \c version (required) string, may not contain '-'
35 * \li \c release (optional) string, may not contain '-'
37 * Comparison is actually \reg g_BackendSpecific.
39 * \li \b RPM: Edition are ordered according to \c epoch, then \c version,
40 * then \c release. Version and release strings are compared by splitting
41 * them into segments of alpha or digit sequences. Segments are compared
42 * according to their type. On mixed types a string compares less than a
45 * compare( 1.a, 1.0 ) == -1 (<)
46 * compare( 1.0, 1.a ) == 1 (>)
47 * compare( 1.0, 1_0 ) == 0 (==)
50 * \attention operator< defines equivalence classes of version strings, as non
51 * alphanumeric chars are ignored. That' why \c 1.0 and \c 1_0 compare equal
54 * \attention Edition::match compares two editions, treating empty
55 * version or release strings as wildcard. Thus match is not transitive,
56 * and you don't want to use it to order keys in a a std::container.
58 * \ingroup g_BackendSpecific
60 class Edition : public IdStringType<Edition>
63 /** Type of an epoch. */
64 typedef unsigned epoch_t;
66 /** Value representing \c noepoch. */
67 static const epoch_t noepoch = 0;
69 /** Value representing \c noedition (<tt>""</tt>)
70 * This is in fact a valid Edition. It's what the default ctor
71 * creates or will be parsed from an empty string.
73 static const Edition noedition;
76 /** Default ctor: \ref noedition. */
79 /** Ctor taking edition as string. */
80 explicit Edition( IdString::IdType id_r ) : _str( id_r ) {}
81 explicit Edition( const IdString & idstr_r ) : _str( idstr_r ) {}
82 explicit Edition( const std::string & str_r ) : _str( str_r ) {}
83 explicit Edition( const char * cstr_r ) : _str( cstr_r ) {}
85 /** Ctor taking \a version_r, \a release_r and optional \a epoch_r */
86 Edition( const std::string & version_r,
87 const std::string & release_r,
88 epoch_t epoch_r = noepoch );
90 Edition( const char * version_r,
91 const char * release_r,
92 epoch_t epoch_r = noepoch );
94 /** Ctor taking \a version_r, \a release_r and optional \a epoch_r as string. */
95 Edition( const std::string & version_r,
96 const std::string & release_r,
97 const std::string & epoch_r );
99 Edition( const char * version_r,
100 const char * release_r,
101 const char * epoch_r );
105 epoch_t epoch() const;
108 std::string version() const;
111 std::string release() const;
114 /** \ref compare functor.
115 * \see \ref RelCompare.
117 typedef zypp::Compare<Edition> Compare;
119 /** \ref Edition \ref Range based on \ref Compare.
120 * \see \ref RelCompare.
122 typedef Range<Edition> CompareRange;
125 /** \name Match two Editions
126 * Match two Editions returning <tt>-1,0,1</tt>, treating empty
127 * version/release strings as \c ANY.
130 static int match( const Edition & lhs, const Edition & rhs ) { return match( lhs.idStr(), rhs.idStr() ); }
131 static int match( const Edition & lhs, const IdString & rhs ) { return match( lhs.idStr(), rhs ); }
132 static int match( const Edition & lhs, const std::string & rhs ) { return _doMatch( lhs.c_str(), rhs.c_str() ); }
133 static int match( const Edition & lhs, const char * rhs ) { return _doMatch( lhs.c_str(), rhs );}
135 static int match( const IdString & lhs, const Edition & rhs ) { return match( lhs, rhs.idStr() ); }
136 static int match( const IdString & lhs, const IdString & rhs ) { return lhs.compareEQ( rhs ) ? 0 :
137 _doMatch( lhs.c_str(), rhs.c_str() ); }
138 static int match( const IdString & lhs, const std::string & rhs ) { return _doMatch( lhs.c_str(), rhs.c_str() ); }
139 static int match( const IdString & lhs, const char * rhs ) { return _doMatch( lhs.c_str(), rhs ); }
141 static int match( const std::string & lhs, const Edition & rhs ) { return _doMatch( lhs.c_str(), rhs.c_str() );}
142 static int match( const std::string & lhs, const IdString & rhs ) { return _doMatch( lhs.c_str(), rhs.c_str() ); }
143 static int match( const std::string & lhs, const std::string & rhs ) { return _doMatch( lhs.c_str(), rhs.c_str() ); }
144 static int match( const std::string & lhs, const char * rhs ) { return _doMatch( lhs.c_str(), rhs ); }
146 static int match( const char * lhs, const Edition & rhs ) { return _doMatch( lhs, rhs.c_str() );}
147 static int match( const char * lhs, const IdString & rhs ) { return _doMatch( lhs, rhs.c_str() ); }
148 static int match( const char * lhs, const std::string & rhs ) { return _doMatch( lhs, rhs.c_str() ); }
149 static int match( const char * lhs, const char * rhs ) { return _doMatch( lhs, rhs ); }
151 int match( const Edition & rhs ) const { return match( idStr(), rhs.idStr() ); }
152 int match( const IdString & rhs ) const { return match( idStr(), rhs ); }
153 int match( const std::string & rhs ) const { return _doMatch( c_str(), rhs.c_str() ); }
154 int match( const char * rhs ) const { return _doMatch( c_str(), rhs ); }
157 /** \ref match functor.
158 * \see \ref RelCompare.
160 struct Match: public std::binary_function<Edition,Edition,int>
162 int operator()( const Edition & lhs, const Edition & rhs ) const
163 { return Edition::match( lhs, rhs ); }
166 /** \ref Edition \ref Range based on \ref Match.
167 * \see \ref RelCompare.
169 typedef Range<Edition, Match> MatchRange;
172 static int _doCompare( const char * lhs, const char * rhs );
173 static int _doMatch( const char * lhs, const char * rhs );
176 friend class IdStringType<Edition>;
179 ///////////////////////////////////////////////////////////////////
181 /////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////////////////////////////////
184 #endif // ZYPP_EDITION_H