]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/dstream.cc
release: 1.3.0
[lilypond.git] / flower / dstream.cc
index 7857d33338a7e36841d430054e82776ec1947b1f..e51f97a39e1ef5ea2f802d57f7f17c91f0f77e57 100644 (file)
@@ -3,19 +3,19 @@
 
   source file of the Flower Library
 
-  (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include <fstream.h>
-#include "assoc.hh"
+#include "dictionary-iter.hh"
 #include "dstream.hh"
-#include "scalar.hh"
+
 #include "text-db.hh"
 #include "string-convert.hh"
-#include "assoc-iter.hh"
+#include "rational.hh"
 
-/// indent of each level
-const INDTAB = 2;
+/// amount of indentation for each level.
+const int INDTAB = 2;
 
 /*
   should use Regexp library.
@@ -52,19 +52,19 @@ Dstream::identify_as (String name)
   String cl (strip_member (mem));
   String idx = cl;
 
-  if (silent_assoc_p_->elt_b (mem))
+  if (silent_dict_p_->elem_b (mem))
     idx  = mem;
-  else if (silent_assoc_p_->elt_b (cl))
+  else if (silent_dict_p_->elem_b (cl))
     idx = cl;
   else
     {
-      (*silent_assoc_p_)[idx] = default_silence_b_;
+      (*silent_dict_p_)[idx] = default_silence_b_;
     }
-  local_silence_b_ = (*silent_assoc_p_)[idx];
+  local_silence_b_ = (*silent_dict_p_)[idx];
   if (current_classname_str_ != idx && !local_silence_b_)
     {
       current_classname_str_=idx;
-      if (!(*silent_assoc_p_)["Dstream"])
+      if (!(*silent_dict_p_)["Dstream"])
        *os_l_ << "[" << current_classname_str_ << ":]"; // messy.
     }
   return *this;
@@ -73,32 +73,58 @@ Dstream::identify_as (String name)
 bool
 Dstream::silent_b (String s) const
 {
-  if (!silent_assoc_p_->elt_b (s))
+  if (!silent_dict_p_->elem_b (s))
     return false;
-  return (*silent_assoc_p_)[s];
+  return (*silent_dict_p_)[s];
+}
+
+Dstream &
+Dstream::operator<<(void const *v_l)
+{
+  output (String_convert::pointer_str (v_l));
+  return *this;
 }
 
 Dstream &
-Dstream::operator<<(String s)
+Dstream::operator <<(String s)
 {
   output (s);
   return *this;
 }
 
 Dstream &
-Dstream::operator<<(void const *v_l)
+Dstream::operator <<(const char * s)
 {
-  output (String_convert::pointer_str (v_l));
+  output (String (s));
   return *this;
 }
 
 Dstream &
-Dstream::operator<<(char const *ch_l)
+Dstream::operator <<(char c)
 {
-  output (ch_l);
+  output (to_str (c));
   return *this;
 }
 
+Dstream&
+Dstream::operator << (Real r)
+{
+  output (to_str  (r));
+  return *this;
+}
+Dstream &
+Dstream::operator <<(Rational c)
+{
+  output (c.str ());
+  return *this;
+}
+Dstream &
+Dstream::operator <<(int i)
+{
+  output (to_str(i));
+  return *this;
+}
+  
 void
 Dstream::output (String s)
 {
@@ -124,7 +150,7 @@ Dstream::output (String s)
        break;
 
       case '\n':
-       *os_l_ << '\n' << String (' ', indent_level_i_) << flush;
+       *os_l_ << '\n' << to_str (' ', indent_level_i_) << flush;
        break;
       default:
        *os_l_ << *cp;
@@ -137,7 +163,7 @@ Dstream::output (String s)
 Dstream::Dstream (ostream *r, char const * cfg_nm)
 {
   os_l_ = r;
-  silent_assoc_p_ = new Assoc<String,bool>;
+  silent_dict_p_ = new Dictionary<bool>;
   default_silence_b_ = false;
   indent_level_i_ = 0;
   if (!os_l_)
@@ -145,38 +171,39 @@ Dstream::Dstream (ostream *r, char const * cfg_nm)
 
   char const * fn =cfg_nm ? cfg_nm : ".dstreamrc";
   {
-    ifstream ifs (fn); // can't open
+    ifstream ifs (fn); // can 't open
     if (!ifs)
       return;
   }
 
   Text_db cfg (fn);
-  while (! cfg.eof()){
+  while (!cfg.eof_b ()){
     Text_record  r (cfg++);
     if (r.size() != 2)
       {
-       r.message (_("not enough fields in Dstream init."));
+       r.message (_ ("not enough fields in Dstream init"));
        continue;
       }
-    (*silent_assoc_p_)[r[0]] = (bool)(int)(Scalar (r[1]));
+    (*silent_dict_p_)[r[0]] = r[1] == "1";
   }
 
-  if ((*silent_assoc_p_).elt_b ("Dstream_default_silence"))
-    default_silence_b_ = (*silent_assoc_p_)["Dstream_default_silence"];
+  if ((*silent_dict_p_).elem_b ("Dstream_default_silence"))
+    default_silence_b_ = (*silent_dict_p_)["Dstream_default_silence"];
 }
 
 
 Dstream::~Dstream()
 {
-  delete silent_assoc_p_;
+  delete silent_dict_p_;
   assert (!indent_level_i_) ;
 }
 
 void
 Dstream::clear_silence()
 {
-  for (Assoc_iter<String, bool> i (*silent_assoc_p_); i.ok(); i++)
+  for (Dictionary_iter<bool> i (*silent_dict_p_); i.ok(); i++)
     {
-      i.val() = false;
+      i.val_ref() = false;
     }
 }
+