#ifndef CTKVERSION_H #define CTKVERSION_H #include #include namespace ctk { /** * Version identifier for plug-ins and packages. * *

* Version identifiers have four components. *

    *
  1. Major version. A non-negative integer.
  2. *
  3. Minor version. A non-negative integer.
  4. *
  5. Micro version. A non-negative integer.
  6. *
  7. Qualifier. A text string. See Version(const QString&) for the * format of the qualifier string.
  8. *
* *

* Version objects are immutable. * * @Immutable */ class Version { private: bool valid; unsigned int major; unsigned int minor; unsigned int micro; QString qualifier; static const QString SEPARATOR; // = "." static const QRegExp RegExp; /** * Called by the Version constructors to validate the version components. * * @return true if the validation was successfull, false otherwise. */ void validate(); public: /** * The empty version "0.0.0". */ static const Version emptyVersion; /** * Creates a version identifier from the specified numerical components. * *

* The qualifier is set to the empty string. * * @param major Major component of the version identifier. * @param minor Minor component of the version identifier. * @param micro Micro component of the version identifier. * */ Version(unsigned int major, unsigned int minor, unsigned int micro); /** * Creates a version identifier from the specified components. * * @param major Major component of the version identifier. * @param minor Minor component of the version identifier. * @param micro Micro component of the version identifier. * @param qualifier Qualifier component of the version identifier. */ Version(unsigned int major, unsigned int minor, unsigned int micro, const QString& qualifier); /** * Created a version identifier from the specified string. * *

* Here is the grammar for version strings. * *

     * version ::= major('.'minor('.'micro('.'qualifier)?)?)?
     * major ::= digit+
     * minor ::= digit+
     * micro ::= digit+
     * qualifier ::= (alpha|digit|'_'|'-')+
     * digit ::= [0..9]
     * alpha ::= [a..zA..Z]
     * 
* * There must be no whitespace in version. * * @param version string representation of the version identifier. */ Version(const QString& version); /** * Create a version identifier from another. * * @param version Another version identifier */ Version(const Version& version); /** * Parses a version identifier from the specified string. * *

* See Version(const QString&) for the format of the version string. * * @param version string representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A Version object representing the version * identifier. If version is the empty string * then emptyVersion will be * returned. */ static Version parseVersion(const QString& version); /** * Returns if the version is valid. */ bool isValid() const; /** * Returns the major component of this version identifier. * * @return The major component. */ unsigned int getMajor() const; /** * Returns the minor component of this version identifier. * * @return The minor component. */ unsigned int getMinor() const; /** * Returns the micro component of this version identifier. * * @return The micro component. */ unsigned int getMicro() const; /** * Returns the qualifier component of this version identifier. * * @return The qualifier component. */ QString getQualifier() const; /** * Returns the string representation of this version identifier. * *

* The format of the version string will be major.minor.micro * if qualifier is the empty string or * major.minor.micro.qualifier otherwise. * * @return The string representation of this version identifier. */ QString toString() const; /** * Compares this Version object to another object. * *

* A version is considered to be equal to another version if the * major, minor and micro components are equal and the qualifier component * is equal. * * @param object The Version object to be compared. * @return true if object is a * Version and is equal to this object; * false otherwise. */ bool operator==(const Version& object) const; /** * Compares this Version object to another object. * *

* A version is considered to be less than another version if its * major component is less than the other version's major component, or the * major components are equal and its minor component is less than the other * version's minor component, or the major and minor components are equal * and its micro component is less than the other version's micro component, * or the major, minor and micro components are equal and it's qualifier * component is less than the other version's qualifier component (using * std::string::compare). * *

* A version is considered to be equal to another version if the * major, minor and micro components are equal and the qualifier component * is equal. * * @param object The Version object to be compared. * @return A negative integer, zero, or a positive integer if this object is * less than, equal to, or greater than the specified * Version object. */ int compare(const Version& object) const; }; } #endif // CTKVERSION_H