]> git.donarmstrong.com Git - lilypond.git/blob - flower/scalar.cc
release: 0.1.13
[lilypond.git] / flower / scalar.cc
1 /*
2   scalar.cc -- implement 
3
4   source file of the Flower Library
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <assert.h>
10 #include <stdio.h>
11 #include "scalar.hh"
12
13 Scalar::Scalar (Rational r)
14   :String (r)
15 {
16
17 }
18
19 Scalar::operator Rational()
20 {
21   int p = index_i ('/');
22   if (p == -1)
23     return int (*this);
24   
25   String s2 = right_str (len()-p-1);
26   String s1 = left_str (p);
27
28   return Rational (s1.value_i(), s2.value_i ());
29 }
30
31 bool
32 Scalar::isnum()
33 {
34   int conv = false;
35   if (len()) 
36     {
37       long l =0;
38       conv = sscanf (strh_.ch_C(), "%ld", &l);
39     }
40   return len() && conv;
41 }
42
43 Scalar::operator Real()
44 {
45   assert (isnum());
46   return value_f();
47 }
48
49 Scalar::operator int()
50 {
51   if (!length_i ())
52     return 0;                   // ugh
53   
54   assert (isnum());
55   return value_i();
56 }
57
58
59 Scalar::operator bool() const
60 {
61   if (!len())
62     return false;
63   if (*this == "0")
64     return false;
65   String u (*this);
66   if (u.upper_str() == "FALSE")
67     return false;
68   return true;
69 }