MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_VERSION_H__ 00008 #define __MYGUI_VERSION_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include "MyGUI_Types.h" 00012 #include "MyGUI_StringUtility.h" 00013 00014 namespace MyGUI 00015 { 00016 00017 class MYGUI_EXPORT Version 00018 { 00019 public: 00020 00021 Version(unsigned int _major = 0, unsigned int _minor = 0, unsigned int _patch = 0) : 00022 mMajor(_major), 00023 mMinor(_minor), 00024 mPatch(_patch) 00025 { 00026 } 00027 00028 friend bool operator < (Version const& a, Version const& b) 00029 { 00030 return (a.mMajor < b.mMajor) ? true : (a.mMinor < b.mMinor); 00031 } 00032 00033 friend bool operator >= (Version const& a, Version const& b) 00034 { 00035 return !(a < b); 00036 } 00037 00038 friend bool operator > (Version const& a, Version const& b) 00039 { 00040 return (b < a); 00041 } 00042 00043 friend bool operator <= (Version const& a, Version const& b) 00044 { 00045 return !(a > b); 00046 } 00047 00048 friend bool operator == (Version const& a, Version const& b) 00049 { 00050 return !(a < b) && !(a > b); 00051 } 00052 00053 friend bool operator != (Version const& a, Version const& b) 00054 { 00055 return !(a == b); 00056 } 00057 00058 friend std::ostream& operator << (std::ostream& _stream, const Version& _value) 00059 { 00060 _stream << _value.print(); 00061 return _stream; 00062 } 00063 00064 friend std::istream& operator >> (std::istream& _stream, Version& _value) 00065 { 00066 std::string value; 00067 _stream >> value; 00068 _value = parse(value); 00069 return _stream; 00070 } 00071 00072 unsigned int getMajor() const 00073 { 00074 return mMajor; 00075 } 00076 00077 unsigned int getMinor() const 00078 { 00079 return mMinor; 00080 } 00081 00082 unsigned int getPatch() const 00083 { 00084 return mPatch; 00085 } 00086 00087 std::string print() const 00088 { 00089 if (mPatch == 0) 00090 return utility::toString(mMajor, ".", mMinor); 00091 return utility::toString(mMajor, ".", mMinor, ".", mPatch); 00092 } 00093 00094 static Version parse(const std::string& _value) 00095 { 00096 const std::vector<std::string>& vec = utility::split(_value, "."); 00097 if (vec.empty()) 00098 return Version(); 00099 00100 unsigned int major = utility::parseValue<unsigned int>(vec[0]); 00101 unsigned int minor = vec.size() > 1 ? utility::parseValue<unsigned int>(vec[1]) : 0; 00102 unsigned int patch = vec.size() > 2 ? utility::parseValue<unsigned int>(vec[2]) : 0; 00103 00104 return Version(major, minor, patch); 00105 } 00106 00107 private: 00108 unsigned mMajor : 8; 00109 unsigned mMinor : 8; 00110 unsigned mPatch : 16; 00111 }; 00112 00113 } // namespace MyGUI 00114 00115 #endif // __MYGUI_VERSION_H__