]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Basic/VersionTuple.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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 "clang/Basic/LLVM.h"
18 #include "llvm/ADT/Optional.h"
19 #include <string>
20
21 namespace clang {
22
23 /// \brief Represents a version number in the form major[.minor[.subminor]].
24 class VersionTuple {
25   unsigned Major;
26   unsigned Minor : 31;
27   unsigned Subminor : 31;
28   unsigned HasMinor : 1;
29   unsigned HasSubminor : 1;
30
31 public:
32   VersionTuple() 
33     : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { }
34
35   explicit VersionTuple(unsigned Major)
36     : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false)
37   { }
38
39   explicit VersionTuple(unsigned Major, unsigned Minor)
40     : Major(Major), Minor(Minor), Subminor(0), HasMinor(true), 
41       HasSubminor(false)
42   { }
43
44   explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
45     : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true), 
46       HasSubminor(true)
47   { }
48
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; }
52
53   /// \brief Retrieve the major version number.
54   unsigned getMajor() const { return Major; }
55
56   /// \brief Retrieve the minor version number, if provided.
57   llvm::Optional<unsigned> getMinor() const { 
58     if (!HasMinor)
59       return llvm::Optional<unsigned>();
60     return Minor;
61   }
62
63   /// \brief Retrieve the subminor version number, if provided.
64   llvm::Optional<unsigned> getSubminor() const { 
65     if (!HasSubminor)
66       return llvm::Optional<unsigned>();
67     return Subminor;
68   }
69
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;
74   }
75
76   /// \brief Determine if two version numbers are not equivalent. If
77   /// not provided, minor and subminor version numbers are considered to be 
78   /// zero.
79   friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
80     return !(X == Y);
81   }
82
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;
88
89     if (X.Minor != Y.Minor)
90       return X.Minor < Y.Minor;
91
92     return X.Subminor < Y.Subminor;
93   }
94
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) {
98     return Y < X;
99   }
100
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) {
105     return !(Y < X);
106   }
107
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) {
112     return !(X < Y);
113   }
114
115   /// \brief Retrieve a string representation of the version number/
116   std::string getAsString() const;
117 };
118
119 /// \brief Print a version number.
120 raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V);
121
122 } // end namespace clang
123 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H