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
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_
#define MYGUI_EXPORT
friend bool operator!=(Version const &a, Version const &b)
friend bool operator<=(Version const &a, Version const &b)
friend bool operator>=(Version const &a, Version const &b)
friend std::ostream & operator<<(std::ostream &_stream, const Version &_value)
uint8_t getMinor() const
friend bool operator<(Version const &a, Version const &b)
friend bool operator>(Version const &a, Version const &b)
uint16_t getPatch() const
Version(uint8_t _major=0, uint8_t _minor=0, uint16_t _patch=0)
std::string print() const
friend std::istream & operator>>(std::istream &_stream, Version &_value)
static Version parse(std::string_view _value)
uint8_t getMajor() const
friend bool operator==(Version const &a, Version const &b)
std::vector< std::string > split(std::string_view _source, std::string_view _delims="\t\n ")
std::string toString(T _value)
T parseValue(std::string_view _value)