MyGUI
3.0.3
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #ifndef __MYGUI_VERSION_H__ 00024 #define __MYGUI_VERSION_H__ 00025 00026 #include "MyGUI_Prerequest.h" 00027 #include "MyGUI_Types.h" 00028 #include "MyGUI_Utility.h" 00029 00030 namespace MyGUI 00031 { 00032 00033 class MYGUI_EXPORT Version 00034 { 00035 public: 00036 Version() : value(0) { } 00037 Version(uint8 _major, uint8 _minor, uint16 _patch) : value((uint32(_major) << 24) + (uint32(_minor) << 16) + uint32(_patch)) { } 00038 Version(uint8 _major, uint8 _minor) : value((uint32(_major) << 24) + (uint32(_minor) << 16)) { } 00039 explicit Version(const std::string& _value) : value(parse(_value).value) { } 00040 00041 friend bool operator < (Version const& a, Version const& b) { return a.getPoorVersion() < b.getPoorVersion(); } 00042 friend bool operator >= (Version const& a, Version const& b) { return !(a < b); } 00043 friend bool operator > (Version const& a, Version const& b) { return (b < a); } 00044 friend bool operator <= (Version const& a, Version const& b) { return !(a > b); } 00045 00046 friend bool operator == (Version const& a, Version const& b) { return !(a < b) && !(a > b); } 00047 friend bool operator != (Version const& a, Version const& b) { return !(a == b); } 00048 00049 friend std::ostream& operator << ( std::ostream& _stream, const Version& _value ) 00050 { 00051 _stream << _value.print(); 00052 return _stream; 00053 } 00054 00055 friend std::istream& operator >> ( std::istream& _stream, Version& _value ) 00056 { 00057 std::string value; 00058 _stream >> value; 00059 _value = Version::parse(value); 00060 return _stream; 00061 } 00062 00063 uint8 getMajor() const { return uint8((value & 0xFF000000) >> 24); } 00064 uint8 getMinor() const { return uint8((value & 0x00FF0000) >> 16); } 00065 uint16 getPatch() const { return uint16(value & 0x0000FFFF); } 00066 00067 uint32 getPoorVersion() const { return value & 0xFFFF0000; } 00068 uint32 getFullVersion() const { return value; } 00069 00070 std::string print() const 00071 { 00072 if (getPatch() == 0) return utility::toString(getMajor(), ".", getMinor()); 00073 return utility::toString(getMajor(), ".", getMinor(), ".", getPatch()); 00074 } 00075 00076 static Version parse(const std::string& _value) 00077 { 00078 const std::vector<std::string>& vec = utility::split(_value, "."); 00079 if (vec.empty()) return Version(); 00080 uint8 major = (uint8)utility::parseValue<int>(vec[0]); 00081 uint8 minor = vec.size() > 1 ? (uint8)utility::parseValue<int>(vec[1]) : uint8(0); 00082 uint16 patch = vec.size() > 2 ? (uint16)utility::parseValue<int>(vec[2]) : uint16(0); 00083 return Version(major, minor, patch); 00084 } 00085 00086 private: 00087 union 00088 { 00089 uint32 value; 00090 uint8 value_data[4]; 00091 }; 00092 }; 00093 00094 } // namespace MyGUI 00095 00096 #endif // __MYGUI_VERSION_H__