ctkVersion.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKVERSION_H
  16. #define CTKVERSION_H
  17. #include <QString>
  18. #include <QRegExp>
  19. #include "ctkPluginFrameworkExport.h"
  20. /**
  21. * \ingroup PluginFramework
  22. *
  23. * Version identifier for plug-ins and packages.
  24. *
  25. * <p>
  26. * Version identifiers have four components.
  27. * <ol>
  28. * <li>Major version. A non-negative integer.</li>
  29. * <li>Minor version. A non-negative integer.</li>
  30. * <li>Micro version. A non-negative integer.</li>
  31. * <li>Qualifier. A text string. See <code>ctkVersion(const QString&)</code> for the
  32. * format of the qualifier string.</li>
  33. * </ol>
  34. *
  35. * <p>
  36. * <code>ctkVersion</code> objects are immutable.
  37. *
  38. * @Immutable
  39. */
  40. class CTK_PLUGINFW_EXPORT ctkVersion {
  41. private:
  42. friend class ctkPluginPrivate;
  43. friend class ctkVersionRange;
  44. unsigned int majorVersion;
  45. unsigned int minorVersion;
  46. unsigned int microVersion;
  47. QString qualifier;
  48. static const QString SEPARATOR; // = "."
  49. static const QRegExp RegExp;
  50. bool undefined;
  51. /**
  52. * Called by the ctkVersion constructors to validate the version components.
  53. *
  54. * @return <code>true</code> if the validation was successfull, <code>false</code> otherwise.
  55. */
  56. void validate();
  57. ctkVersion& operator=(const ctkVersion& v);
  58. ctkVersion(bool undefined = false);
  59. public:
  60. /**
  61. * The empty version "0.0.0".
  62. */
  63. static ctkVersion emptyVersion();
  64. /**
  65. * Creates an undefined version identifier, representing either
  66. * infinity or minus infinity.
  67. */
  68. static ctkVersion undefinedVersion();
  69. /**
  70. * Creates a version identifier from the specified numerical components.
  71. *
  72. * <p>
  73. * The qualifier is set to the empty string.
  74. *
  75. * @param majorVersion Major component of the version identifier.
  76. * @param minorVersion Minor component of the version identifier.
  77. * @param microVersion Micro component of the version identifier.
  78. *
  79. */
  80. ctkVersion(unsigned int majorVersion, unsigned int minorVersion, unsigned int microVersion);
  81. /**
  82. * Creates a version identifier from the specified components.
  83. *
  84. * @param majorVersion Major component of the version identifier.
  85. * @param minorVersion Minor component of the version identifier.
  86. * @param microVersion Micro component of the version identifier.
  87. * @param qualifier Qualifier component of the version identifier.
  88. */
  89. ctkVersion(unsigned int majorVersion, unsigned int minorVersion, unsigned int microVersion, const QString& qualifier);
  90. /**
  91. * Created a version identifier from the specified string.
  92. *
  93. * <p>
  94. * Here is the grammar for version strings.
  95. *
  96. * <pre>
  97. * version ::= majorVersion('.'minorVersion('.'microVersion('.'qualifier)?)?)?
  98. * majorVersion ::= digit+
  99. * minorVersion ::= digit+
  100. * microVersion ::= digit+
  101. * qualifier ::= (alpha|digit|'_'|'-')+
  102. * digit ::= [0..9]
  103. * alpha ::= [a..zA..Z]
  104. * </pre>
  105. *
  106. * There must be no whitespace in version.
  107. *
  108. * @param version string representation of the version identifier.
  109. */
  110. ctkVersion(const QString& version);
  111. /**
  112. * Create a version identifier from another.
  113. *
  114. * @param version Another version identifier
  115. */
  116. ctkVersion(const ctkVersion& version);
  117. /**
  118. * Parses a version identifier from the specified string.
  119. *
  120. * <p>
  121. * See <code>ctkVersion(const QString&)</code> for the format of the version string.
  122. *
  123. * @param version string representation of the version identifier. Leading
  124. * and trailing whitespace will be ignored.
  125. * @return A <code>ctkVersion</code> object representing the version
  126. * identifier. If <code>version</code> is the empty string
  127. * then <code>emptyVersion</code> will be
  128. * returned.
  129. */
  130. static ctkVersion parseVersion(const QString& version);
  131. /**
  132. * Returns the undefined state of this version identifier.
  133. *
  134. * @return <code>true</code> if this version identifier is undefined,
  135. * <code>false</code> otherwise.
  136. */
  137. bool isUndefined() const;
  138. /**
  139. * Returns the majorVersion component of this version identifier.
  140. *
  141. * @return The majorVersion component.
  142. */
  143. unsigned int getMajor() const;
  144. /**
  145. * Returns the minorVersion component of this version identifier.
  146. *
  147. * @return The minorVersion component.
  148. */
  149. unsigned int getMinor() const;
  150. /**
  151. * Returns the microVersion component of this version identifier.
  152. *
  153. * @return The microVersion component.
  154. */
  155. unsigned int getMicro() const;
  156. /**
  157. * Returns the qualifier component of this version identifier.
  158. *
  159. * @return The qualifier component.
  160. */
  161. QString getQualifier() const;
  162. /**
  163. * Returns the string representation of this version identifier.
  164. *
  165. * <p>
  166. * The format of the version string will be <code>majorVersion.minorVersion.microVersion</code>
  167. * if qualifier is the empty string or
  168. * <code>majorVersion.minorVersion.microVersion.qualifier</code> otherwise.
  169. *
  170. * @return The string representation of this version identifier.
  171. */
  172. QString toString() const;
  173. /**
  174. * Compares this <code>ctkVersion</code> object to another object.
  175. *
  176. * <p>
  177. * A version is considered to be <b>equal to </b> another version if the
  178. * majorVersion, minorVersion and microVersion components are equal and the qualifier component
  179. * is equal.
  180. *
  181. * @param object The <code>ctkVersion</code> object to be compared.
  182. * @return <code>true</code> if <code>object</code> is a
  183. * <code>ctkVersion</code> and is equal to this object;
  184. * <code>false</code> otherwise.
  185. */
  186. bool operator==(const ctkVersion& object) const;
  187. /**
  188. * Compares this <code>ctkVersion</code> object to another object.
  189. *
  190. * <p>
  191. * A version is considered to be <b>less than </b> another version if its
  192. * majorVersion component is less than the other version's majorVersion component, or the
  193. * majorVersion components are equal and its minorVersion component is less than the other
  194. * version's minorVersion component, or the majorVersion and minorVersion components are equal
  195. * and its microVersion component is less than the other version's microVersion component,
  196. * or the majorVersion, minorVersion and microVersion components are equal and it's qualifier
  197. * component is less than the other version's qualifier component (using
  198. * <code>std::string::compare</code>).
  199. *
  200. * <p>
  201. * A version is considered to be <b>equal to</b> another version if the
  202. * majorVersion, minorVersion and microVersion components are equal and the qualifier component
  203. * is equal.
  204. *
  205. * @param object The <code>ctkVersion</code> object to be compared.
  206. * @return A negative integer, zero, or a positive integer if this object is
  207. * less than, equal to, or greater than the specified
  208. * <code>ctkVersion</code> object.
  209. */
  210. int compare(const ctkVersion& object) const;
  211. };
  212. /**
  213. * \ingroup PluginFramework
  214. */
  215. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkVersion& v);
  216. #endif // CTKVERSION_H