]> git.donarmstrong.com Git - lilypond.git/blob - lily/lilypond-version.cc
9c0e938547d6d4c0381a50272e29bb60ca1acdbf
[lilypond.git] / lily / lilypond-version.cc
1 /*
2   lilypond-version.cc -- implement Lilypond_version
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <ctype.h>
10
11 #include "lilypond-version.hh"
12 #include "string-convert.hh"
13 #include "misc.hh"
14
15 Lilypond_version::Lilypond_version (int major, int minor, int patch)
16 {
17   major_ = major;
18   minor_ = minor;
19   patch_ = patch;
20 }
21
22 Lilypond_version::Lilypond_version (string str)
23 {
24   major_ = 0; 
25   minor_ = 0;
26   patch_ = 0;
27   
28   vector<string> version;
29   version = string_split (str, '.');
30
31   if (version.size () > 0 && isdigit (version[0][0]))
32     major_ = String_convert::dec2int (version[0]);
33   if (version.size () > 1 && isdigit (version[1][0]))
34     minor_ = String_convert::dec2int (version[1]);
35   
36   patch_ = 0;
37   if (version.size () >= 3
38       && isdigit (version[2][0]))
39     patch_ = String_convert::dec2int (version[2]);
40
41   if (version.size () >= 4)
42     extra_patch_string_ = version[3];
43 }
44
45 string
46 Lilypond_version::to_string () const
47 {
48   return ::to_string (major_)
49     + "." + ::to_string (minor_)
50     + "." + ::to_string (patch_);
51 }
52
53 Lilypond_version::operator int () const
54 {
55   // ugh
56   return 100000 * major_ + 1000 * minor_ + patch_;
57 }
58