]> git.donarmstrong.com Git - lilypond.git/blob - flower/scalar.cc
release: 0.1.9
[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 = 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     {
29         long l =0;
30         conv = sscanf (strh_.ch_C(), "%ld", &l);
31     }
32   return len() && conv;
33 }
34
35 Scalar::operator Real()
36 {
37   assert (isnum());
38   return value_f();
39 }
40
41 Scalar::operator int()
42 {
43   assert (isnum());
44   return value_i();
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   if ( u.upper_str() == "FALSE")
56         return false;
57   return true;
58 }