1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_GN_VERSION_H_ 6 #define TOOLS_GN_VERSION_H_ 7 8 #include <optional> 9 #include <string> 10 11 #ifdef major 12 #undef major 13 #endif 14 #ifdef minor 15 #undef minor 16 #endif 17 18 // Represents a semantic version. 19 class Version { 20 public: 21 Version(int major, int minor, int patch); 22 23 static std::optional<Version> FromString(std::string s); 24 major()25 int major() const { return major_; } minor()26 int minor() const { return minor_; } patch()27 int patch() const { return patch_; } 28 29 bool operator==(const Version& other) const; 30 bool operator<(const Version& other) const; 31 bool operator!=(const Version& other) const; 32 bool operator>=(const Version& other) const; 33 bool operator>(const Version& other) const; 34 bool operator<=(const Version& other) const; 35 36 std::string Describe() const; 37 38 private: 39 int major_; 40 int minor_; 41 int patch_; 42 }; 43 44 #endif // TOOLS_GN_VERSION_H_ 45