clang API Documentation
00001 //===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header defines the VersionTuple class, which represents a version in 00011 // the form major[.minor[.subminor]]. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 #ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H 00015 #define LLVM_CLANG_BASIC_VERSIONTUPLE_H 00016 00017 #include "clang/Basic/LLVM.h" 00018 #include "llvm/ADT/Optional.h" 00019 #include <string> 00020 00021 namespace clang { 00022 00023 /// \brief Represents a version number in the form major[.minor[.subminor]]. 00024 class VersionTuple { 00025 unsigned Major; 00026 unsigned Minor : 31; 00027 unsigned Subminor : 31; 00028 unsigned HasMinor : 1; 00029 unsigned HasSubminor : 1; 00030 00031 public: 00032 VersionTuple() 00033 : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { } 00034 00035 explicit VersionTuple(unsigned Major) 00036 : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) 00037 { } 00038 00039 explicit VersionTuple(unsigned Major, unsigned Minor) 00040 : Major(Major), Minor(Minor), Subminor(0), HasMinor(true), 00041 HasSubminor(false) 00042 { } 00043 00044 explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor) 00045 : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true), 00046 HasSubminor(true) 00047 { } 00048 00049 /// \brief Determine whether this version information is empty 00050 /// (e.g., all version components are zero). 00051 bool empty() const { return Major == 0 && Minor == 0 && Subminor == 0; } 00052 00053 /// \brief Retrieve the major version number. 00054 unsigned getMajor() const { return Major; } 00055 00056 /// \brief Retrieve the minor version number, if provided. 00057 llvm::Optional<unsigned> getMinor() const { 00058 if (!HasMinor) 00059 return llvm::Optional<unsigned>(); 00060 return Minor; 00061 } 00062 00063 /// \brief Retrieve the subminor version number, if provided. 00064 llvm::Optional<unsigned> getSubminor() const { 00065 if (!HasSubminor) 00066 return llvm::Optional<unsigned>(); 00067 return Subminor; 00068 } 00069 00070 /// \brief Determine if two version numbers are equivalent. If not 00071 /// provided, minor and subminor version numbers are considered to be zero. 00072 friend bool operator==(const VersionTuple& X, const VersionTuple &Y) { 00073 return X.Major == Y.Major && X.Minor == Y.Minor && X.Subminor == Y.Subminor; 00074 } 00075 00076 /// \brief Determine if two version numbers are not equivalent. If 00077 /// not provided, minor and subminor version numbers are considered to be 00078 /// zero. 00079 friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) { 00080 return !(X == Y); 00081 } 00082 00083 /// \brief Determine whether one version number precedes another. If not 00084 /// provided, minor and subminor version numbers are considered to be zero. 00085 friend bool operator<(const VersionTuple &X, const VersionTuple &Y) { 00086 if (X.Major != Y.Major) 00087 return X.Major < Y.Major; 00088 00089 if (X.Minor != Y.Minor) 00090 return X.Minor < Y.Minor; 00091 00092 return X.Subminor < Y.Subminor; 00093 } 00094 00095 /// \brief Determine whether one version number follows another. If not 00096 /// provided, minor and subminor version numbers are considered to be zero. 00097 friend bool operator>(const VersionTuple &X, const VersionTuple &Y) { 00098 return Y < X; 00099 } 00100 00101 /// \brief Determine whether one version number precedes or is 00102 /// equivalent to another. If not provided, minor and subminor 00103 /// version numbers are considered to be zero. 00104 friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) { 00105 return !(Y < X); 00106 } 00107 00108 /// \brief Determine whether one version number follows or is 00109 /// equivalent to another. If not provided, minor and subminor 00110 /// version numbers are considered to be zero. 00111 friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) { 00112 return !(X < Y); 00113 } 00114 00115 /// \brief Retrieve a string representation of the version number/ 00116 std::string getAsString() const; 00117 }; 00118 00119 /// \brief Print a version number. 00120 raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V); 00121 00122 } // end namespace clang 00123 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H