MyGUI 3.2.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
14 namespace MyGUI
15 {
16
17 class MYGUI_EXPORT Version
18 {
19 public:
20
21 Version(unsigned int _major = 0, unsigned int _minor = 0, unsigned int _patch = 0) :
22 mMajor(_major),
23 mMinor(_minor),
24 mPatch(_patch)
25 {
26 }
27
28 friend bool operator < (Version const& a, Version const& b)
29 {
30 return (a.mMajor < b.mMajor) ? true : (a.mMinor < b.mMinor);
31 }
32
33 friend bool operator >= (Version const& a, Version const& b)
34 {
35 return !(a < b);
36 }
37
38 friend bool operator > (Version const& a, Version const& b)
39 {
40 return (b < a);
41 }
42
43 friend bool operator <= (Version const& a, Version const& b)
44 {
45 return !(a > b);
46 }
47
48 friend bool operator == (Version const& a, Version const& b)
49 {
50 return !(a < b) && !(a > b);
51 }
52
53 friend bool operator != (Version const& a, Version const& b)
54 {
55 return !(a == b);
56 }
57
58 friend std::ostream& operator << (std::ostream& _stream, const Version& _value)
59 {
60 _stream << _value.print();
61 return _stream;
62 }
63
64 friend std::istream& operator >> (std::istream& _stream, Version& _value)
65 {
66 std::string value;
67 _stream >> value;
68 _value = parse(value);
69 return _stream;
70 }
71
72 unsigned int getMajor() const
73 {
74 return mMajor;
75 }
76
77 unsigned int getMinor() const
78 {
79 return mMinor;
80 }
81
82 unsigned int getPatch() const
83 {
84 return mPatch;
85 }
86
87 std::string print() const
88 {
89 if (mPatch == 0)
90 return utility::toString(mMajor, ".", mMinor);
91 return utility::toString(mMajor, ".", mMinor, ".", mPatch);
92 }
93
94 static Version parse(const std::string& _value)
95 {
96 const std::vector<std::string>& vec = utility::split(_value, ".");
97 if (vec.empty())
98 return Version();
99
100 unsigned int major = utility::parseValue<unsigned int>(vec[0]);
101 unsigned int minor = vec.size() > 1 ? utility::parseValue<unsigned int>(vec[1]) : 0;
102 unsigned int patch = vec.size() > 2 ? utility::parseValue<unsigned int>(vec[2]) : 0;
103
104 return Version(major, minor, patch);
105 }
106
107 private:
108 unsigned mMajor : 8;
109 unsigned mMinor : 8;
110 unsigned mPatch : 16;
111 };
112
113 } // namespace MyGUI
114
115 #endif // MYGUI_VERSION_H_
MyGUI_Prerequest.h
MyGUI::Version::print
std::string print() const
Definition: MyGUI_Version.h:87
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1048
MyGUI_StringUtility.h
MyGUI::Version::Version
Version(unsigned int _major=0, unsigned int _minor=0, unsigned int _patch=0)
Definition: MyGUI_Version.h:21
MyGUI::operator==
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1045
MyGUI::Version::getPatch
unsigned int getPatch() const
Definition: MyGUI_Version.h:82
MyGUI::operator<=
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1054
MyGUI_Types.h
MyGUI::operator>
bool operator>(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1057
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::utility::split
std::vector< std::string > split(const std::string &_source, const std::string &_delims="\t\n ")
Definition: MyGUI_StringUtility.h:291
MyGUI::Version::parse
static Version parse(const std::string &_value)
Definition: MyGUI_Version.h:94
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::utility::toString
std::string toString(T p)
Definition: MyGUI_StringUtility.h:27
MyGUI::Version
Definition: MyGUI_Version.h:17
MyGUI::operator>=
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1060
MyGUI::Version::getMinor
unsigned int getMinor() const
Definition: MyGUI_Version.h:77
MyGUI::Version::getMajor
unsigned int getMajor() const
Definition: MyGUI_Version.h:72
MyGUI::operator<
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1051