lilypond-1.3.9
[lilypond.git] / flower / scalar.cc
blob48d4889a4eaed7f1a49fd917ebf604c121b10bb8
1 #if 0
2 /*
3 scalar.cc -- implement Scalar
5 source file of the Flower Library
7 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include <assert.h>
11 #include <stdio.h>
13 #include "rational.hh"
15 Scalar::Scalar (Rational r)
17 (*this) = r.str ();
20 Scalar::operator Rational ()
22 return to_rat ();
25 Rational
26 Scalar::to_rat () const
28 int p = index_i ('/');
29 if (p == -1)
30 return this->to_i ();
32 String s2 = right_str (length_i ()-p-1);
33 String s1 = left_str (p);
35 return Rational (s1.value_i (), s2.value_i ());
38 bool
39 Scalar::isdir_b () const
41 int conv = length_i ();
42 if (conv)
44 long l =0;
45 conv = sscanf (strh_.ch_C (), "%ld", &l);
46 conv = conv && (l >= -1 && l <= 1);
48 return conv;
51 bool
52 Scalar::isnum_b () const
54 int conv = false;
55 if (length_i ())
57 long l =0;
58 conv = sscanf (strh_.ch_C (), "%lf", &l);
60 return length_i () && conv;
63 Scalar::operator Real()
65 return to_f ();
68 Real
69 Scalar::to_f () const
71 assert (isnum_b ());
72 return value_f ();
75 Scalar::operator int ()
77 return to_i ();
80 int
81 Scalar::to_i () const
83 if (!length_i ())
84 return 0; // ugh
86 assert (isnum_b());
87 return value_i ();
90 Scalar::operator bool () const
92 return to_bool ();
95 bool
96 Scalar::to_bool () const
98 if (!length_i ())
99 return false;
100 if (*this == "0")
101 return false;
102 String u (*this);
103 if (u.upper_str () == "FALSE")
104 return false;
105 return true;
109 #endif