]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Basic/VersionTuple.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Basic / VersionTuple.h
1 //===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header defines the VersionTuple class, which represents a version in
11 // the form major[.minor[.subminor]].
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H
15 #define LLVM_CLANG_BASIC_VERSIONTUPLE_H
16
17 #include "llvm/ADT/Optional.h"
18 #include <string>
19
20 namespace llvm {
21   class raw_ostream;
22 }
23
24 namespace clang {
25
26 /// \brief Represents a version number in the form major[.minor[.subminor]].
27 class VersionTuple {
28   unsigned Major;
29   unsigned Minor : 31;
30   unsigned Subminor : 31;
31   unsigned HasMinor : 1;
32   unsigned HasSubminor : 1;
33
34 public:
35   VersionTuple() 
36     : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { }
37
38   explicit VersionTuple(unsigned Major)
39     : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false)
40   { }
41
42   explicit VersionTuple(unsigned Major, unsigned Minor)
43     : Major(Major), Minor(Minor), Subminor(0), HasMinor(true), 
44       HasSubminor(false)
45   { }
46
47   explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
48     : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true), 
49       HasSubminor(true)
50   { }
51
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; }
55
56   /// \brief Retrieve the major version number.
57   unsigned getMajor() const { return Major; }
58
59   /// \brief Retrieve the minor version number, if provided.
60   llvm::Optional<unsigned> getMinor() const { 
61     if (!HasMinor)
62       return llvm::Optional<unsigned>();
63     return Minor;
64   }
65
66   /// \brief Retrieve the subminor version number, if provided.
67   llvm::Optional<unsigned> getSubminor() const { 
68     if (!HasSubminor)
69       return llvm::Optional<unsigned>();
70     return Subminor;
71   }
72
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;
77   }
78
79   /// \brief Determine if two version numbers are not equivalent. If
80   /// not provided, minor and subminor version numbers are considered to be 
81   /// zero.
82   friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
83     return !(X == Y);
84   }
85
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;
91
92     if (X.Minor != Y.Minor)
93       return X.Minor < Y.Minor;
94
95     return X.Subminor < Y.Subminor;
96   }
97
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) {
101     return Y < X;
102   }
103
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) {
108     return !(Y < X);
109   }
110
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) {
115     return !(X < Y);
116   }
117
118   /// \brief Retrieve a string representation of the version number/
119   std::string getAsString() const;
120 };
121
122 /// \brief Print a version number.
123 llvm::raw_ostream& operator<<(llvm::raw_ostream &Out, const VersionTuple &V);
124
125 } // end namespace clang
126 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H