1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Chris Bielow $
25
// $Authors: Clemens Groepl, Chris Bielow $
26
// --------------------------------------------------------------------------
27
#include <OpenMS/CONCEPT/VersionInfo.h>
28
#include <OpenMS/DATASTRUCTURES/String.h>
29
#include <OpenMS/CONCEPT/Exception.h>
35
// these headers are generated by the build system
36
// and therefore intentionally break the naming convention (tagging them as automatically build)
37
#include <OpenMS/openms_package_version.h>
38
#include <OpenMS/openms_svn_revision.h>
44
const VersionInfo::VersionDetails VersionInfo::VersionDetails::EMPTY;
46
bool VersionInfo::VersionDetails::operator<(const VersionInfo::VersionDetails& rhs) const
48
return ( (this->version_major < rhs.version_major)
49
|| (this->version_major == rhs.version_major && this->version_minor < rhs.version_minor)
50
|| (this->version_major == rhs.version_major && this->version_minor == rhs.version_minor && this->version_patch < rhs.version_patch));
53
bool VersionInfo::VersionDetails::operator==(const VersionInfo::VersionDetails& rhs) const
55
return (this->version_major == rhs.version_major && this->version_minor == rhs.version_minor && this->version_patch == rhs.version_patch);
58
bool VersionInfo::VersionDetails::operator>(const VersionInfo::VersionDetails& rhs) const
60
return !(*this < rhs || *this == rhs);
64
VersionInfo::VersionDetails VersionInfo::VersionDetails::create(const String& version)
66
VersionInfo::VersionDetails result;
68
size_t first_dot = version.find('.');
69
// we demand at least one "."
70
if (first_dot == string::npos) return VersionInfo::VersionDetails::EMPTY;
73
result.version_major = String(version.substr(0, first_dot)).toInt();
75
catch (Exception::ConversionError& /*e*/)
77
return VersionInfo::VersionDetails::EMPTY;
80
// returns npos if no second "." is found - which does not hurt
81
size_t second_dot = version.find('.', first_dot + 1);
84
result.version_minor = String(version.substr(first_dot+1, second_dot)).toInt();
86
catch (Exception::ConversionError& /*e*/)
88
return VersionInfo::VersionDetails::EMPTY;
91
// if there is no second dot: return
92
if (second_dot == string::npos) return result;
94
// returns npos if no third "." is found - which does not hurt
95
size_t third_dot = version.find('.', second_dot + 1);
98
result.version_patch = String(version.substr(second_dot+1, third_dot)).toInt();
100
catch (Exception::ConversionError& /*e*/)
102
return VersionInfo::VersionDetails::EMPTY;
108
String VersionInfo::getTime()
110
static bool is_initialized = false;
111
static String result;
112
if ( !is_initialized )
114
result = String(__DATE__) + ", " + __TIME__;
115
is_initialized = true;
120
String VersionInfo::getVersion()
122
static bool is_initialized = false;
123
static String result;
124
if ( !is_initialized )
126
result = OPENMS_PACKAGE_VERSION;
128
is_initialized = true;
134
VersionInfo::VersionDetails VersionInfo::getVersionStruct()
136
static bool is_initialized = false;
137
static VersionDetails result;
138
if ( !is_initialized )
140
result = VersionDetails::create(getVersion());
141
is_initialized = true;
147
String VersionInfo::getRevision()
149
return String(OPENMS_SVN_REVISION); // defined in svn_revision.h