MyGUI: MyGUI_Version.h Source File

MyGUI 3.4.3

MyGUI_Version.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_VERSION_H_
8#define MYGUI_VERSION_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Types.h"
12#include "MyGUI_StringUtility.h"
13
14namespace MyGUI
15{
16
17 class MYGUI_EXPORT Version
18 {
19 public:
20 Version(uint8_t _major = 0, uint8_t _minor = 0, uint16_t _patch = 0) :
21 mMajor(_major),
22 mMinor(_minor),
23 mPatch(_patch)
24 {
25 }
26
27 friend bool operator<(Version const& a, Version const& b)
28 {
29 return (a.mMajor < b.mMajor) ? true : (a.mMinor < b.mMinor);
30 }
31
32 friend bool operator>=(Version const& a, Version const& b)
33 {
34 return !(a < b);
35 }
36
37 friend bool operator>(Version const& a, Version const& b)
38 {
39 return (b < a);
40 }
41
42 friend bool operator<=(Version const& a, Version const& b)
43 {
44 return !(a > b);
45 }
46
47 friend bool operator==(Version const& a, Version const& b)
48 {
49 return !(a < b) && !(a > b);
50 }
51
52 friend bool operator!=(Version const& a, Version const& b)
53 {
54 return !(a == b);
55 }
56
57 friend std::ostream& operator<<(std::ostream& _stream, const Version& _value)
58 {
59 _stream << _value.print();
60 return _stream;
61 }
62
63 friend std::istream& operator>>(std::istream& _stream, Version& _value)
64 {
65 std::string value;
66 _stream >> value;
67 _value = parse(value);
68 return _stream;
69 }
70
71 uint8_t getMajor() const
72 {
73 return mMajor;
74 }
75
76 uint8_t getMinor() const
77 {
78 return mMinor;
79 }
80
81 uint16_t getPatch() const
82 {
83 return mPatch;
84 }
85
86 std::string print() const
87 {
88 if (mPatch == 0)
89 return utility::toString(mMajor, ".", mMinor);
90 return utility::toString(mMajor, ".", mMinor, ".", mPatch);
91 }
92
93 static Version parse(std::string_view _value)
94 {
95 const std::vector<std::string>& vec = utility::split(_value, ".");
96 if (vec.empty())
97 return {};
98
99 uint8_t major = utility::parseValue<uint8_t>(vec[0]);
100 uint8_t minor = vec.size() > 1 ? utility::parseValue<uint8_t>(vec[1]) : 0;
101 uint16_t patch = vec.size() > 2 ? utility::parseValue<uint16_t>(vec[2]) : 0;
102
103 return {major, minor, patch};
104 }
105
106 private:
107 uint8_t mMajor;
108 uint8_t mMinor;
109 uint16_t mPatch;
110 };
111
112} // namespace MyGUI
113
114#endif // MYGUI_VERSION_H_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_StringUtility.h
MyGUI_Types.h
MyGUI::Version::operator!=
friend bool operator!=(Version const &a, Version const &b)
Definition MyGUI_Version.h:52
MyGUI::Version::operator<=
friend bool operator<=(Version const &a, Version const &b)
Definition MyGUI_Version.h:42
MyGUI::Version::operator>=
friend bool operator>=(Version const &a, Version const &b)
Definition MyGUI_Version.h:32
MyGUI::Version::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const Version &_value)
Definition MyGUI_Version.h:57
MyGUI::Version::getMinor
uint8_t getMinor() const
Definition MyGUI_Version.h:76
MyGUI::Version::operator<
friend bool operator<(Version const &a, Version const &b)
Definition MyGUI_Version.h:27
MyGUI::Version::operator>
friend bool operator>(Version const &a, Version const &b)
Definition MyGUI_Version.h:37
MyGUI::Version::getPatch
uint16_t getPatch() const
Definition MyGUI_Version.h:81
MyGUI::Version::Version
Version(uint8_t _major=0, uint8_t _minor=0, uint16_t _patch=0)
Definition MyGUI_Version.h:20
MyGUI::Version::print
std::string print() const
Definition MyGUI_Version.h:86
MyGUI::Version::operator>>
friend std::istream & operator>>(std::istream &_stream, Version &_value)
Definition MyGUI_Version.h:63
MyGUI::Version::parse
static Version parse(std::string_view _value)
Definition MyGUI_Version.h:93
MyGUI::Version::getMajor
uint8_t getMajor() const
Definition MyGUI_Version.h:71
MyGUI::Version::operator==
friend bool operator==(Version const &a, Version const &b)
Definition MyGUI_Version.h:47
MyGUI::utility::split
std::vector< std::string > split(std::string_view _source, std::string_view _delims="\t\n ")
Definition MyGUI_StringUtility.h:153
MyGUI::utility::toString
std::string toString(T _value)
Definition MyGUI_StringUtility.h:26
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15