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 "clang/Basic/LLVM.h"
18 #include "llvm/ADT/Optional.h"
23 /// \brief Represents a version number in the form major[.minor[.subminor]].
27 unsigned Subminor : 31;
28 unsigned HasMinor : 1;
29 unsigned HasSubminor : 1;
33 : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { }
35 explicit VersionTuple(unsigned Major)
36 : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false)
39 explicit VersionTuple(unsigned Major, unsigned Minor)
40 : Major(Major), Minor(Minor), Subminor(0), HasMinor(true),
44 explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
45 : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true),
49 /// \brief Determine whether this version information is empty
50 /// (e.g., all version components are zero).
51 bool empty() const { return Major == 0 && Minor == 0 && Subminor == 0; }
53 /// \brief Retrieve the major version number.
54 unsigned getMajor() const { return Major; }
56 /// \brief Retrieve the minor version number, if provided.
57 llvm::Optional<unsigned> getMinor() const {
59 return llvm::Optional<unsigned>();
63 /// \brief Retrieve the subminor version number, if provided.
64 llvm::Optional<unsigned> getSubminor() const {
66 return llvm::Optional<unsigned>();
70 /// \brief Determine if two version numbers are equivalent. If not
71 /// provided, minor and subminor version numbers are considered to be zero.
72 friend bool operator==(const VersionTuple& X, const VersionTuple &Y) {
73 return X.Major == Y.Major && X.Minor == Y.Minor && X.Subminor == Y.Subminor;
76 /// \brief Determine if two version numbers are not equivalent. If
77 /// not provided, minor and subminor version numbers are considered to be
79 friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
83 /// \brief Determine whether one version number precedes another. If not
84 /// provided, minor and subminor version numbers are considered to be zero.
85 friend bool operator<(const VersionTuple &X, const VersionTuple &Y) {
86 if (X.Major != Y.Major)
87 return X.Major < Y.Major;
89 if (X.Minor != Y.Minor)
90 return X.Minor < Y.Minor;
92 return X.Subminor < Y.Subminor;
95 /// \brief Determine whether one version number follows another. If not
96 /// provided, minor and subminor version numbers are considered to be zero.
97 friend bool operator>(const VersionTuple &X, const VersionTuple &Y) {
101 /// \brief Determine whether one version number precedes or is
102 /// equivalent to another. If not provided, minor and subminor
103 /// version numbers are considered to be zero.
104 friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) {
108 /// \brief Determine whether one version number follows or is
109 /// equivalent to another. If not provided, minor and subminor
110 /// version numbers are considered to be zero.
111 friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
115 /// \brief Retrieve a string representation of the version number/
116 std::string getAsString() const;
119 /// \brief Print a version number.
120 raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V);
122 } // end namespace clang
123 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H