]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/scalar.cc
partial: 0.0.42.pre3.hanjan
[lilypond.git] / flower / lib / 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 = index_i('/');
14     if (p == -1)
15         return int(*this);
16     
17     String s2 = right_str(len()-p-1);
18     String s1 = left_str(p);
19
20     return Rational(s1.value_i(), s2.value_i());
21 }
22
23 bool
24 Scalar::isnum()
25 {
26     int conv = false;
27     if (len()) {
28         long l =0;
29         conv = sscanf(strh_.ch_c_l(), "%ld", &l);
30     }
31     return len() && conv;
32 }
33
34 Scalar::operator Real()
35 {
36     assert (isnum());
37     return value_f();
38 }
39
40 Scalar::operator int()
41 {
42     assert (isnum());
43     return value_i();
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     if ( u.upper_str() == "FALSE")
55         return false;
56     return true;
57 }