~ubuntu-branches/ubuntu/natty/mimetic/natty

« back to all changes in this revision

Viewing changes to mimetic/version.cxx

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2006-06-16 13:16:07 UTC
  • Revision ID: james.westby@ubuntu.com-20060616131607-245mqjypkjuahq6b
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2002-2005 by Stefano Barbato
 
3
    email                : stefano@codesink.org
 
4
 
 
5
    $Id: version.cxx,v 1.2 2005/02/23 10:26:14 tat Exp $
 
6
 ***************************************************************************/
 
7
 
 
8
/***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
#include <iostream>
 
17
#include <mimetic/version.h>
 
18
#include <mimetic/utils.h>
 
19
#include <mimetic/tokenizer.h>
 
20
 
 
21
namespace mimetic
 
22
{
 
23
using namespace std;
 
24
 
 
25
const Version version(VERSION);
 
26
 
 
27
 
 
28
Version::Version()
 
29
: m_maj(0), m_min(0), m_build(0)
 
30
{
 
31
}
 
32
 
 
33
Version::Version(const string& s)
 
34
: m_maj(0), m_min(0), m_build(0)
 
35
{
 
36
    set(s);
 
37
}
 
38
 
 
39
Version::Version(ver_type maj, ver_type min, ver_type build)
 
40
: m_maj(maj), m_min(min), m_build(build)
 
41
{
 
42
}
 
43
 
 
44
Version::ver_type Version::maj() const
 
45
{
 
46
    return m_maj;
 
47
}
 
48
 
 
49
Version::ver_type Version::min() const
 
50
{
 
51
    return m_min;
 
52
}
 
53
 
 
54
Version::ver_type Version::build() const
 
55
{
 
56
    return m_build;
 
57
}
 
58
 
 
59
void Version::maj(Version::ver_type maj)
 
60
{
 
61
    m_maj = maj;
 
62
}
 
63
 
 
64
void Version::min(Version::ver_type min)
 
65
{
 
66
    m_min = min;
 
67
}
 
68
 
 
69
void Version::build(Version::ver_type build)
 
70
{
 
71
    m_build = build;
 
72
}
 
73
 
 
74
void Version::set(ver_type maj, ver_type min, ver_type build)
 
75
{
 
76
    m_maj = maj;
 
77
    m_min = min;
 
78
    m_build = build;
 
79
}
 
80
 
 
81
string Version::str() const
 
82
{
 
83
    return utils::int2str(m_maj) + "." + utils::int2str(m_min) + 
 
84
        (m_build > 0 ? "." + utils::int2str(m_build) : "");
 
85
}
 
86
 
 
87
void Version::set(const string& s)
 
88
{
 
89
    StringTokenizer stok(&s, ".");
 
90
    string tok;
 
91
    if(stok.next(tok))
 
92
        m_maj = utils::str2int(tok);    
 
93
    if(stok.next(tok))
 
94
        m_min = utils::str2int(tok);    
 
95
    if(stok.next(tok))
 
96
        m_build = utils::str2int(tok);    
 
97
}
 
98
 
 
99
bool Version::operator==(const Version& r) const
 
100
{
 
101
    return m_maj == r.m_maj && m_min == r.m_min && m_build == r.m_build;
 
102
        
 
103
}
 
104
 
 
105
bool Version::operator!=(const Version& r) const
 
106
{
 
107
    return m_maj != r.m_maj || m_min != r.m_min || m_build != r.m_build;
 
108
}
 
109
 
 
110
bool Version::operator<(const Version& r) const
 
111
{
 
112
    return m_maj < r.m_maj || m_min < r.m_min || m_build < r.m_build;
 
113
}
 
114
 
 
115
bool Version::operator>(const Version& r) const
 
116
{
 
117
    return m_maj > r.m_maj || m_min > r.m_min || m_build > r.m_build;
 
118
}
 
119
 
 
120
bool Version::operator<=(const Version& r) const
 
121
{
 
122
    return m_maj <= r.m_maj || m_min <= r.m_min || m_build <= r.m_build;
 
123
}
 
124
 
 
125
bool Version::operator>=(const Version& r) const
 
126
{
 
127
    return m_maj >= r.m_maj || m_min >= r.m_min || m_build >= r.m_build;
 
128
}
 
129
 
 
130
ostream& operator<<(ostream& os, const Version& v)
 
131
{
 
132
    return os << v.str();
 
133
}
 
134
 
 
135
}