2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_VERSIONLIB_H )
23 #define INCLUDED_VERSIONLIB_H
36 inline bool operator<( const Version& version, const Version& other ){
37 return version.major < other.major || ( !( other.major < version.major ) && version.minor < other.minor );
40 template<typename TextOutputStreamType>
41 TextOutputStreamType& ostream_write( TextOutputStreamType& outputStream, const Version& version ){
42 return outputStream << version.major << '.' << version.minor;
45 /// \brief Returns true if \p version (code) is compatible with \p other (data).
46 inline bool version_compatible( const Version& version, const Version& other ){
47 return version.major == other.major // different major-versions are always incompatible
48 && !( version.minor < other.minor ); // data minor-version is incompatible if greater than code minor-version
51 inline int string_range_parse_unsigned_decimal_integer( const char* first, const char* last ){
53 for (; first != last; ++first )
56 result += *first - '0';
61 inline Version version_parse( const char* versionString ){
63 const char* endVersion = versionString + strlen( versionString );
65 const char* endMajor = strchr( versionString, '.' );
66 if ( endMajor == 0 ) {
67 endMajor = endVersion;
73 const char* endMinor = strchr( endMajor + 1, '.' );
74 if ( endMinor == 0 ) {
75 endMinor = endVersion;
77 version.minor = string_range_parse_unsigned_decimal_integer( endMajor + 1, endMinor );
79 version.major = string_range_parse_unsigned_decimal_integer( versionString, endMajor );