]> git.donarmstrong.com Git - lilypond.git/blob - flower/scalar.cc
release: 0.0.33
[lilypond.git] / flower / scalar.cc
1 #include <assert.h>
2 #include <stdio.h>
3 #include "scalar.hh"
4
5 Scalar::Scalar(Rational r)
6     :String(r)
7 {
8
9 }
10
11 Scalar::operator Rational()
12 {
13     int p = pos('/');
14     if (!p)
15         return int(*this);
16     
17     String s2 = right(len()-p);
18     p--;
19     String s1 = left(p);
20
21     return Rational(s1.value(), s2.value());
22 }
23
24 bool
25 Scalar::isnum()
26 {
27     int conv = false;
28     if (len()) {
29         long l =0;
30         conv = sscanf(strh_.ch_c_l(), "%ld", &l);
31     }
32     return len() && conv;
33 }
34
35 Scalar::operator Real()
36 {
37     assert (isnum());
38     return fvalue();
39 }
40
41 Scalar::operator int()
42 {
43     assert (isnum());
44     return value();
45 }
46
47
48 Scalar::operator bool() const
49 {
50     if (!len())
51         return false;
52     if (*this == "0")
53         return false;
54     String u (*this);
55     u.upper();
56     if (u== "FALSE")
57         return false;
58     return true;
59 }