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)
38 return version.major < other.major || (!(other.major < version.major) && version.minor < other.minor);
41 template<typename TextOutputStreamType>
42 TextOutputStreamType& ostream_write(TextOutputStreamType& outputStream, const Version& version)
44 return outputStream << version.major << '.' << version.minor;
47 /// \brief Returns true if \p version (code) is compatible with \p other (data).
48 inline bool version_compatible(const Version& version, const Version& other)
50 return version.major == other.major // different major-versions are always incompatible
51 && !(version.minor < other.minor); // data minor-version is incompatible if greater than code minor-version
54 inline int string_range_parse_unsigned_decimal_integer(const char* first, const char* last)
57 for(; first != last; ++first)
60 result += *first - '0';
65 inline Version version_parse(const char* versionString)
68 const char* endVersion = versionString + strlen(versionString);
70 const char* endMajor = strchr(versionString, '.');
73 endMajor = endVersion;
79 const char* endMinor = strchr(endMajor + 1, '.');
82 endMinor = endVersion;
84 version.minor = string_range_parse_unsigned_decimal_integer(endMajor + 1, endMinor);
86 version.major = string_range_parse_unsigned_decimal_integer(versionString, endMajor);