PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/library/utility/src/support/ut_version.e

http://github.com/gobo-eiffel/gobo
Specman e | 299 lines | 233 code | 37 blank | 29 comment | 12 complexity | f7aa56a25abfbed503f15447a3b503d1 MD5 | raw file
  1. note
  2. description:
  3. "Version numbers"
  4. remark: "See http://en.wikipedia.org/wiki/Software_versioning"
  5. library: "Gobo Eiffel Utility Library"
  6. copyright: "Copyright (c) 2006-2017, Eric Bezault and others"
  7. license: "MIT License"
  8. date: "$Date$"
  9. revision: "$Revision$"
  10. class UT_VERSION
  11. inherit
  12. ANY
  13. redefine
  14. out
  15. end
  16. KL_COMPARABLE
  17. undefine
  18. is_equal, out
  19. end
  20. create
  21. make,
  22. make_major,
  23. make_major_minor,
  24. make_major_minor_revision,
  25. make_latest
  26. feature {NONE} -- Initialization
  27. make (a_major: like major; a_minor: like minor; a_revision: like revision; a_build: like build)
  28. -- Make new version of the form "major.minor.revision.build".
  29. require
  30. a_major_not_negative: a_major >= 0
  31. a_minor_not_negative: a_minor >= 0
  32. a_revision_not_negative: a_revision >= 0
  33. a_build_not_negative: a_build >= 0
  34. do
  35. internal_major := a_major
  36. internal_minor := a_minor
  37. internal_revision := a_revision
  38. internal_build := a_build
  39. ensure
  40. has_major: has_major
  41. major_set: major = a_major
  42. has_minor: has_minor
  43. minor_set: minor = a_minor
  44. has_revision: has_revision
  45. revision_set: revision = a_revision
  46. has_build: has_build
  47. build_set: build = a_build
  48. end
  49. make_major (a_major: like major)
  50. -- Make new version of the form "major".
  51. -- Note that this version is greater than any other
  52. -- version of the form "major.xxx", "major.xxx.yyy"
  53. -- or "major.xxx.yyy.zzz".
  54. require
  55. a_major_not_negative: a_major >= 0
  56. do
  57. internal_major := a_major
  58. internal_minor := -1
  59. internal_revision := -1
  60. internal_build := -1
  61. ensure
  62. has_major: has_major
  63. major_set: major = a_major
  64. no_minor: not has_minor
  65. no_revision: not has_revision
  66. no_build: not has_build
  67. end
  68. make_major_minor (a_major: like major; a_minor: like minor)
  69. -- Make new version of the form "major.minor".
  70. -- Note that this version is greater than any other
  71. -- version of the form "major.minor.xxx",
  72. -- or "major.minor.xxx.yyy".
  73. require
  74. a_major_not_negative: a_major >= 0
  75. a_minor_not_negative: a_minor >= 0
  76. do
  77. internal_major := a_major
  78. internal_minor := a_minor
  79. internal_revision := -1
  80. internal_build := -1
  81. ensure
  82. has_major: has_major
  83. major_set: major = a_major
  84. has_minor: has_minor
  85. minor_set: minor = a_minor
  86. no_revision: not has_revision
  87. no_build: not has_build
  88. end
  89. make_major_minor_revision (a_major: like major; a_minor: like minor; a_revision: like revision)
  90. -- Make new version of the form "major.minor.revision".
  91. -- Note that this version is greater than any other
  92. -- version of the form "major.minor.revision.xxx".
  93. require
  94. a_major_not_negative: a_major >= 0
  95. a_minor_not_negative: a_minor >= 0
  96. a_revision_not_negative: a_revision >= 0
  97. do
  98. internal_major := a_major
  99. internal_minor := a_minor
  100. internal_revision := a_revision
  101. internal_build := -1
  102. ensure
  103. has_major: has_major
  104. major_set: major = a_major
  105. has_minor: has_minor
  106. minor_set: minor = a_minor
  107. has_revision: has_revision
  108. revision_set: revision = a_revision
  109. no_build: not has_build
  110. end
  111. make_latest
  112. -- Make new version which is greater than any other
  113. -- version.
  114. do
  115. internal_major := -1
  116. internal_minor := -1
  117. internal_revision := -1
  118. internal_build := -1
  119. ensure
  120. no_major: not has_major
  121. no_minor: not has_minor
  122. no_revision: not has_revision
  123. no_build: not has_build
  124. end
  125. feature -- Status report
  126. has_major: BOOLEAN
  127. -- Does current version have a major version?
  128. do
  129. Result := (internal_major >= 0)
  130. end
  131. has_minor: BOOLEAN
  132. -- Does current version have a minor version?
  133. do
  134. Result := (internal_minor >= 0)
  135. end
  136. has_revision: BOOLEAN
  137. -- Does current version have a revision number?
  138. do
  139. Result := (internal_revision >= 0)
  140. end
  141. has_build: BOOLEAN
  142. -- Does current version have a build number?
  143. do
  144. Result := (internal_build >= 0)
  145. end
  146. feature -- Access
  147. major: INTEGER
  148. -- Major version
  149. require
  150. has_major: has_major
  151. do
  152. Result := internal_major
  153. ensure
  154. major_not_negative: Result >= 0
  155. end
  156. minor: INTEGER
  157. -- Minor version
  158. require
  159. has_minor: has_minor
  160. do
  161. Result := internal_minor
  162. ensure
  163. minor_not_negative: Result >= 0
  164. end
  165. revision: INTEGER
  166. -- Revision number
  167. require
  168. has_revision: has_revision
  169. do
  170. Result := internal_revision
  171. ensure
  172. revision_not_negative: Result >= 0
  173. end
  174. build: INTEGER
  175. -- Build number
  176. require
  177. has_build: has_build
  178. do
  179. Result := internal_build
  180. ensure
  181. build_not_negative: Result >= 0
  182. end
  183. feature -- Comparison
  184. is_less alias "<" (other: like Current): BOOLEAN
  185. -- Is current version less than `other'?
  186. do
  187. if other.has_major then
  188. if not has_major then
  189. Result := False
  190. elseif major < other.major then
  191. Result := True
  192. elseif major = other.major then
  193. if other.has_minor then
  194. if not has_minor then
  195. Result := False
  196. elseif minor < other.minor then
  197. Result := True
  198. elseif minor = other.minor then
  199. if other.has_revision then
  200. if not has_revision then
  201. Result := False
  202. elseif revision < other.revision then
  203. Result := True
  204. elseif revision = other.revision then
  205. if other.has_build then
  206. if not has_build then
  207. Result := False
  208. else
  209. Result := (build < other.build)
  210. end
  211. else
  212. Result := has_build
  213. end
  214. end
  215. else
  216. Result := has_revision
  217. end
  218. end
  219. else
  220. Result := has_minor
  221. end
  222. end
  223. else
  224. Result := has_major
  225. end
  226. end
  227. feature -- Output
  228. out: STRING
  229. -- New string containing terse printable representation
  230. -- of current object
  231. do
  232. create Result.make (10)
  233. if has_major then
  234. Result.append_string (major.out)
  235. if has_minor then
  236. Result.append_character ('.')
  237. Result.append_string (minor.out)
  238. if has_revision then
  239. Result.append_character ('.')
  240. Result.append_string (revision.out)
  241. if has_build then
  242. Result.append_character ('.')
  243. Result.append_string (build.out)
  244. end
  245. end
  246. end
  247. end
  248. end
  249. feature {NONE} -- Implementation
  250. internal_major: INTEGER
  251. -- Major version
  252. internal_minor: INTEGER
  253. -- Minor version
  254. internal_revision: INTEGER
  255. -- Revision
  256. internal_build: INTEGER
  257. -- Build number
  258. invariant
  259. no_minor: not has_major implies not has_minor
  260. no_revision: not has_minor implies not has_revision
  261. no_build: not has_revision implies not has_build
  262. end