+#if 0
+/*
+ scalar.cc -- implement Scalar
+
+ source file of the Flower Library
+
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
#include <assert.h>
#include <stdio.h>
-#include "scalar.hh"
+
+#include "rational.hh"
Scalar::Scalar (Rational r)
- :String (r)
{
+ (*this) = r.str ();
+}
+Scalar::operator Rational ()
+{
+ return to_rat ();
}
-Scalar::operator Rational()
+Rational
+Scalar::to_rat () const
{
- int p = index_i ('/');
- if (p == -1)
- return int (*this);
-
- String s2 = right_str (len()-p-1);
- String s1 = left_str (p);
+ int p = index_i ('/');
+ if (p == -1)
+ return this->to_i ();
+
+ String s2 = right_str (length_i ()-p-1);
+ String s1 = left_str (p);
- return Rational (s1.value_i(), s2.value_i ());
+ return Rational (s1.value_i (), s2.value_i ());
+}
+
+bool
+Scalar::isdir_b () const
+{
+ int conv = length_i ();
+ if (conv)
+ {
+ long l =0;
+ conv = sscanf (strh_.ch_C (), "%ld", &l);
+ conv = conv && (l >= -1 && l <= 1);
+ }
+ return conv;
}
bool
-Scalar::isnum()
+Scalar::isnum_b () const
{
- int conv = false;
- if (len()) {
- long l =0;
- conv = sscanf (strh_.ch_C(), "%ld", &l);
+ int conv = false;
+ if (length_i ())
+ {
+ long l =0;
+ conv = sscanf (strh_.ch_C (), "%lf", &l);
}
- return len() && conv;
+ return length_i () && conv;
}
Scalar::operator Real()
{
- assert (isnum());
- return value_f();
+ return to_f ();
}
-Scalar::operator int()
+Real
+Scalar::to_f () const
{
- assert (isnum());
- return value_i();
+ assert (isnum_b ());
+ return value_f ();
}
+Scalar::operator int ()
+{
+ return to_i ();
+}
+
+int
+Scalar::to_i () const
+{
+ if (!length_i ())
+ return 0; // ugh
+
+ assert (isnum_b());
+ return value_i ();
+}
-Scalar::operator bool() const
+Scalar::operator bool () const
{
- if (!len())
- return false;
- if (*this == "0")
- return false;
- String u (*this);
- if ( u.upper_str() == "FALSE")
- return false;
- return true;
+ return to_bool ();
}
+
+bool
+Scalar::to_bool () const
+{
+ if (!length_i ())
+ return false;
+ if (*this == "0")
+ return false;
+ String u (*this);
+ if (u.upper_str () == "FALSE")
+ return false;
+ return true;
+}
+
+
+#endif