~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/CONCEPT/VersionInfo.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework 
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
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>
 
30
 
 
31
#include <cstdlib>
 
32
#include <fstream>
 
33
 
 
34
 
 
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>
 
39
 
 
40
using namespace std;
 
41
 
 
42
namespace OpenMS
 
43
{
 
44
        const VersionInfo::VersionDetails VersionInfo::VersionDetails::EMPTY;
 
45
  
 
46
  bool VersionInfo::VersionDetails::operator<(const VersionInfo::VersionDetails& rhs) const
 
47
  {
 
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));
 
51
  }
 
52
  
 
53
  bool VersionInfo::VersionDetails::operator==(const VersionInfo::VersionDetails& rhs) const
 
54
  {
 
55
    return (this->version_major == rhs.version_major && this->version_minor == rhs.version_minor && this->version_patch == rhs.version_patch);
 
56
  }
 
57
 
 
58
  bool VersionInfo::VersionDetails::operator>(const VersionInfo::VersionDetails& rhs) const
 
59
  {
 
60
    return !(*this < rhs || *this == rhs);
 
61
  }
 
62
 
 
63
 
 
64
  VersionInfo::VersionDetails VersionInfo::VersionDetails::create(const String& version)
 
65
  {
 
66
    VersionInfo::VersionDetails result;
 
67
 
 
68
    size_t first_dot = version.find('.');
 
69
    // we demand at least one "."
 
70
    if (first_dot == string::npos) return VersionInfo::VersionDetails::EMPTY;
 
71
    try
 
72
    {
 
73
      result.version_major = String(version.substr(0, first_dot)).toInt();
 
74
    }
 
75
    catch (Exception::ConversionError& /*e*/)
 
76
    {
 
77
      return VersionInfo::VersionDetails::EMPTY;        
 
78
    }
 
79
 
 
80
    // returns npos if no second "." is found - which does not hurt
 
81
    size_t second_dot = version.find('.', first_dot + 1);
 
82
    try
 
83
    {
 
84
      result.version_minor = String(version.substr(first_dot+1, second_dot)).toInt();
 
85
    }
 
86
    catch (Exception::ConversionError& /*e*/)
 
87
    {
 
88
      return VersionInfo::VersionDetails::EMPTY;        
 
89
    }
 
90
 
 
91
    // if there is no second dot: return
 
92
    if (second_dot == string::npos) return result;
 
93
    
 
94
    // returns npos if no third "." is found - which does not hurt
 
95
    size_t third_dot = version.find('.', second_dot + 1);
 
96
    try
 
97
    {
 
98
      result.version_patch = String(version.substr(second_dot+1, third_dot)).toInt();
 
99
    }
 
100
    catch (Exception::ConversionError& /*e*/)
 
101
    {
 
102
      return VersionInfo::VersionDetails::EMPTY;        
 
103
    }
 
104
 
 
105
    return result;
 
106
  }
 
107
 
 
108
        String VersionInfo::getTime()
 
109
        {
 
110
                static bool is_initialized = false;
 
111
                static String result;
 
112
                if ( !is_initialized )
 
113
                {
 
114
                        result = String(__DATE__) + ", " + __TIME__;
 
115
                        is_initialized = true;
 
116
                }
 
117
                return result;
 
118
        }
 
119
 
 
120
        String VersionInfo::getVersion()
 
121
        {
 
122
                static bool is_initialized = false;
 
123
                static String result;
 
124
                if ( !is_initialized )
 
125
                {
 
126
                        result = OPENMS_PACKAGE_VERSION;
 
127
                        result.trim();
 
128
                        is_initialized = true;
 
129
                }
 
130
                return result;
 
131
        }
 
132
 
 
133
 
 
134
  VersionInfo::VersionDetails VersionInfo::getVersionStruct()
 
135
  {
 
136
    static bool is_initialized = false;
 
137
    static VersionDetails result;
 
138
    if ( !is_initialized )
 
139
    {
 
140
      result = VersionDetails::create(getVersion());
 
141
      is_initialized = true;
 
142
    }
 
143
    return result;
 
144
  }
 
145
 
 
146
 
 
147
        String VersionInfo::getRevision()
 
148
        {
 
149
                return String(OPENMS_SVN_REVISION); // defined in svn_revision.h
 
150
        }
 
151
 
 
152
}