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