1 //===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines the VersionTuple class, which represents a version in
11 // the form major[.minor[.subminor]].
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H
15 #define LLVM_CLANG_BASIC_VERSIONTUPLE_H
17 #include "llvm/ADT/Optional.h"
26 /// \brief Represents a version number in the form major[.minor[.subminor]].
30 unsigned Subminor : 31;
31 unsigned HasMinor : 1;
32 unsigned HasSubminor : 1;
36 : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { }
38 explicit VersionTuple(unsigned Major)
39 : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false)
42 explicit VersionTuple(unsigned Major, unsigned Minor)
43 : Major(Major), Minor(Minor), Subminor(0), HasMinor(true),
47 explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
48 : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true),
52 /// \brief Determine whether this version information is empty
53 /// (e.g., all version components are zero).
54 bool empty() const { return Major == 0 && Minor == 0 && Subminor == 0; }
56 /// \brief Retrieve the major version number.
57 unsigned getMajor() const { return Major; }
59 /// \brief Retrieve the minor version number, if provided.
60 llvm::Optional<unsigned> getMinor() const {
62 return llvm::Optional<unsigned>();
66 /// \brief Retrieve the subminor version number, if provided.
67 llvm::Optional<unsigned> getSubminor() const {
69 return llvm::Optional<unsigned>();
73 /// \brief Determine if two version numbers are equivalent. If not
74 /// provided, minor and subminor version numbers are considered to be zero.
75 friend bool operator==(const VersionTuple& X, const VersionTuple &Y) {
76 return X.Major == Y.Major && X.Minor == Y.Minor && X.Subminor == Y.Subminor;
79 /// \brief Determine if two version numbers are not equivalent. If
80 /// not provided, minor and subminor version numbers are considered to be
82 friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
86 /// \brief Determine whether one version number precedes another. If not
87 /// provided, minor and subminor version numbers are considered to be zero.
88 friend bool operator<(const VersionTuple &X, const VersionTuple &Y) {
89 if (X.Major != Y.Major)
90 return X.Major < Y.Major;
92 if (X.Minor != Y.Minor)
93 return X.Minor < Y.Minor;
95 return X.Subminor < Y.Subminor;
98 /// \brief Determine whether one version number follows another. If not
99 /// provided, minor and subminor version numbers are considered to be zero.
100 friend bool operator>(const VersionTuple &X, const VersionTuple &Y) {
104 /// \brief Determine whether one version number precedes or is
105 /// equivalent to another. If not provided, minor and subminor
106 /// version numbers are considered to be zero.
107 friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) {
111 /// \brief Determine whether one version number follows or is
112 /// equivalent to another. If not provided, minor and subminor
113 /// version numbers are considered to be zero.
114 friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
118 /// \brief Retrieve a string representation of the version number/
119 std::string getAsString() const;
122 /// \brief Print a version number.
123 llvm::raw_ostream& operator<<(llvm::raw_ostream &Out, const VersionTuple &V);
125 } // end namespace clang
126 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H