On 2014-05-31, at 03:00 PM, Thiago Macieira <thiago.macie...@intel.com> wrote:

> Em sex 09 maio 2014, às 11:36:08, Keith Gardner escreveu:
>> I have been working on adding a class to QtCore (QVersion) to support
>> storing version numbers, convert to/from QString, and having comparison
>> operators.  My goal was to provide an API to assist in the following use
>> cases:
>> 
>>   - Plugin loading where there are multiple versions on the same system.
>>   - File format validation.
>>   - Executing an already installed command line application where the
>>   behavior is dependent on the called application's version.
>>   - Performing software installations and updates.
>>   - QMake support for version number comparisons.
>> 
>> Please share other potential use cases where this might be useful.
> 
> Ok, since we can't seem to agree, let's settle on the maximum common 
> denominator: QVersion will only compare the numeric part of a version number. 
> By default, two versions with the same numeric part will compare equally, 
> regardless of any suffixes that may be present.
> 
> Therefore, by default, given:
>       QVersion a("5.3.0");
>       QVersion b("5.3.0pl1");
>       QVersion c("5.3.0beta1");
> 
>       a != b != c;            // since they aren't equal

This seems to contradict your previous statement, unless you're speaking 
conceptually here.

To confirm, as far as the code goes, ((QVersion("5.3.0pl1") == 
QVersion("5.3.0beta1")) === true), yes?

> 
>       QVersion::compare(a, b) == 0;
>       QVersion::compare(b, c) == 0;
> 
> We will also provide an overload for the QVersion::compare function taking a 
> functor:
> 
>       template <typename SuffixCompare> static inline int
>       compare(const QVersion &a, const QVersion &b, SuffixCompare 
> suffixCompare)
>       {
>               int cmp = compare(a, b);
>               if (cmp)
>                       return cmp;
>               return suffixCompare(a.suffix(), b.suffix());
>       }
> 
> Thus, if you want to implement a comparison like OpenSSL's, you can do:
> 
>       QVersion::compare(a, b, 
>           [](auto a, auto b) { 
>               return QString::compare(a, b, Qt::CaseInsensitive); 
>           });
> 
> If you want a more complex comparison like I had wanted, you'd do:
> 
> static int priorityOrder(const QString &suffix)
> {
>       if (suffix.isEmpty())
>               return 0;
>       return suffix.startsWith("alpha") || suffix.startsWith("beta") ||
>               suffix.startsWith("rc") ? -1 : 1;
> }
> 
> static int myCompare(const QString &a, const QString &b)
> {
>       int a_prio = priorityOrder(a);
>       int b_prio = priorityOrder(b);
>       if (a_prio != b_prio || a_prio == 0)
>               return a_prio - b_prio;
>       return QString::compare(a, b, Qt::CaseInsensitive);
> }
> 
> And then you'd use: QVersion::compare(a, b, myCompare);
> -- 
> Thiago Macieira - thiago.macieira (AT) intel.com
>  Software Architect - Intel Open Source Technology Center
> 
> _______________________________________________
> Development mailing list
> Development@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

Big +1 to everything. This approach should serve everyones' use cases; let's 
get this integration rolling.
-- 
Jake Petroules - jake.petroules at petroules.com
Chief Technology Officer - Petroules Corporation

_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to