/[debian]/mimetic/trunk/mimetic/version.cxx
ViewVC logotype

Contents of /mimetic/trunk/mimetic/version.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 511 - (show annotations)
Sun Jan 21 20:13:31 2007 UTC (14 years, 5 months ago) by gregoa
File size: 3199 byte(s)
* New upstream release.
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: version.cxx,v 1.3 2007/01/21 11:39:04 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/config.h>
18 #include <mimetic/version.h>
19 #include <mimetic/utils.h>
20 #include <mimetic/tokenizer.h>
21
22 namespace mimetic
23 {
24 using namespace std;
25
26 const Version version(VERSION);
27
28
29 Version::Version()
30 : m_maj(0), m_min(0), m_build(0)
31 {
32 }
33
34 Version::Version(const string& s)
35 : m_maj(0), m_min(0), m_build(0)
36 {
37 set(s);
38 }
39
40 Version::Version(ver_type maj, ver_type min, ver_type build)
41 : m_maj(maj), m_min(min), m_build(build)
42 {
43 }
44
45 Version::ver_type Version::maj() const
46 {
47 return m_maj;
48 }
49
50 Version::ver_type Version::min() const
51 {
52 return m_min;
53 }
54
55 Version::ver_type Version::build() const
56 {
57 return m_build;
58 }
59
60 void Version::maj(Version::ver_type maj)
61 {
62 m_maj = maj;
63 }
64
65 void Version::min(Version::ver_type min)
66 {
67 m_min = min;
68 }
69
70 void Version::build(Version::ver_type build)
71 {
72 m_build = build;
73 }
74
75 void Version::set(ver_type maj, ver_type min, ver_type build)
76 {
77 m_maj = maj;
78 m_min = min;
79 m_build = build;
80 }
81
82 string Version::str() const
83 {
84 return utils::int2str(m_maj) + "." + utils::int2str(m_min) +
85 (m_build > 0 ? "." + utils::int2str(m_build) : "");
86 }
87
88 void Version::set(const string& s)
89 {
90 StringTokenizer stok(&s, ".");
91 string tok;
92 if(stok.next(tok))
93 m_maj = utils::str2int(tok);
94 if(stok.next(tok))
95 m_min = utils::str2int(tok);
96 if(stok.next(tok))
97 m_build = utils::str2int(tok);
98 }
99
100 bool Version::operator==(const Version& r) const
101 {
102 return m_maj == r.m_maj && m_min == r.m_min && m_build == r.m_build;
103
104 }
105
106 bool Version::operator!=(const Version& r) const
107 {
108 return m_maj != r.m_maj || m_min != r.m_min || m_build != r.m_build;
109 }
110
111 bool Version::operator<(const Version& r) const
112 {
113 return m_maj < r.m_maj || m_min < r.m_min || m_build < r.m_build;
114 }
115
116 bool Version::operator>(const Version& r) const
117 {
118 return m_maj > r.m_maj || m_min > r.m_min || m_build > r.m_build;
119 }
120
121 bool Version::operator<=(const Version& r) const
122 {
123 return m_maj <= r.m_maj || m_min <= r.m_min || m_build <= r.m_build;
124 }
125
126 bool Version::operator>=(const Version& r) const
127 {
128 return m_maj >= r.m_maj || m_min >= r.m_min || m_build >= r.m_build;
129 }
130
131 ostream& operator<<(ostream& os, const Version& v)
132 {
133 return os << v.str();
134 }
135
136 }

  ViewVC Help
Powered by ViewVC 1.1.26