]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.11
authorfred <fred>
Wed, 4 Dec 1996 21:39:43 +0000 (21:39 +0000)
committerfred <fred>
Wed, 4 Dec 1996 21:39:43 +0000 (21:39 +0000)
flower/dstream.cc
flower/scalar.cc [new file with mode: 0644]
flower/scalar.hh [new file with mode: 0644]
flower/string.cc

index 6cfc62eb3ded390c3a96555f3a1a9f36e4a6f4ac..b4267f35021cb7cb2b795b41069d624f5f1d9629 100644 (file)
@@ -1,7 +1,7 @@
 #include <fstream.h>
 #include "assoc.hh"
 #include "dstream.hh"
-#include "string.hh"
+#include "scalar.hh"
 #include "textdb.hh"
 
 /// indent of each level 
@@ -118,7 +118,7 @@ Dstream::Dstream(ostream *r, const char * cfg_nm )
             r.message("not enough fields in Dstream init.");
             continue;
         }
-        (*silent)[r[0]] = r[1].to_bool();
+        (*silent)[r[0]] = Scalar(r[1]).to_bool();
     }
 
 }
diff --git a/flower/scalar.cc b/flower/scalar.cc
new file mode 100644 (file)
index 0000000..b536939
--- /dev/null
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include "scalar.hh"
+
+bool
+Scalar::isnum()
+{
+    int conv = false;
+    if (len()) {
+       long l =0;
+       conv = sscanf(data, "%ld", &l);
+    }
+    return len() && conv;
+}
+
+Scalar::operator Real()
+{
+    assert (isnum());
+    return fvalue();
+}
+
+Scalar::operator int()
+{
+    assert (isnum());
+    return value();
+}
+bool
+Scalar::to_bool() const
+{
+    if (!len())
+       return false;
+    if (*this == "0")
+       return false;
+    String u (*this);
+    u.upper();
+    if (u== "FALSE")
+       return false;
+    return true;
+}
diff --git a/flower/scalar.hh b/flower/scalar.hh
new file mode 100644 (file)
index 0000000..5d02d69
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+  scalar.hh -- part of LilyPond
+
+  (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef SCALAR_HH
+#define SCALAR_HH
+#include "string.hh"
+#include "real.hh"
+
+/// Perl -like scalar type.
+struct Scalar : public String {
+    
+    Scalar(Real r) : String(r) {}
+    Scalar(int i) : String(i) {}
+    Scalar(char c) : String(c) {}
+    Scalar(const char *c) : String(c) {}    
+    Scalar(String s ):String(s) {}
+    Scalar() {}
+    bool isnum();
+    operator Real();
+    operator int();
+    ///
+    bool to_bool() const;
+    /** perl -like string to bool conversion
+     */
+
+};
+
+#endif // SCALAR_HH
+
index 2e8e8bf5c6f33e5f7849fefaf4a1a70c2faee518..9c6792c0217cb86d523e4aa68ba82f077ec63b3b 100644 (file)
 #include <stdio.h>
 #include <ctype.h>
 #include <assert.h>
-//#include "globals.hh"
+
 #include "string.hh"
 
+
 static char* strlwr( char* s )
 {
     char* p = s;
@@ -108,41 +109,14 @@ String::String( const int i, const int n, const char c )
     // String convd to const char *
 }
 
- const char*
-String::ptr() const
+const char*
+String::cptr() const
 {
     return data;
 }
 
 
 
-#ifdef CENTRAL_OBJECT // everything derived from Sortable object
-// comparisons.
-int
-String::operator ==( const Sortable& test ) const
-{
-    const String *s = (const String *) &test; 
-    return *this == *s;
-}
-
-int
-String::operator &&(const Object& test) const
-{
-    const String *s = (const String *) &test;
-    
-    int i = min( len(), s->len() );
-    return ( i > 0 ) ?
-        ( !strncmp( data, s->data, i ) ) : 0;
-}
-
-int
-String::operator >( const Sortable& test ) const
-{
-    const String *s = (const String *) &test;
-    return strcmp( data, s->data ) > 0;
-}
-#endif
-
 // signed comparison,  analogous to strcmp;
 int
 String::compare( const char* test ) const
@@ -386,16 +360,3 @@ String::reversed() const
     strrev(s);
     return retval;    
 }
-bool
-String::to_bool() const
-{
-    if (!len())
-       return false;
-    if (*this == "0")
-       return false;
-    String u (*this);
-    u.upper();
-    if (u== "FALSE")
-       return false;
-    return true;
-}