2 dstream.cc -- implement Dstream
4 source file of the Flower Library
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
14 #include "string-convert.hh"
15 #include "assoc-iter.hh"
16 /// indent of each level
20 should use Regexp library.
23 strip_pretty(String pretty_str)
25 int i = pretty_str.index_i('(');
27 pretty_str = pretty_str.left_str(i);
29 int l = pretty_str.index_last_i(' '); // strip until last ' '
31 pretty_str = pretty_str.nomid_str(0,l+1);
36 strip_member(String pret)
38 int l=pret.index_last_i(':')-1;
40 pret = pret.left_str(l );
45 Dstream::identify_as(String name)
50 String mem(strip_pretty(name));
51 String cl(strip_member(mem));
54 if (silent_assoc_p_->elt_b(mem))
56 else if (silent_assoc_p_->elt_b(cl))
59 (*silent_assoc_p_)[idx] = false;
61 local_silence_b_ = (*silent_assoc_p_)[idx];
62 if (current_classname_str_ != idx && !local_silence_b_) {
63 current_classname_str_=idx;
64 if (!(*silent_assoc_p_)["Dstream"])
65 *os_l_ << "[" << current_classname_str_ << ":]"; // messy.
71 Dstream::silence(String s)
73 if (!silent_assoc_p_->elt_b(s))
75 return (*silent_assoc_p_)[s];
78 /** Output a string via the Dstream. This is the only output
79 interface. It delegates all conversion to String class. */
81 Dstream::operator<<(String s)
88 Dstream::operator<<(void const *v_l)
90 output(String_convert::pointer_str(v_l));
95 Dstream::operator<<(char const *ch_l)
102 Dstream::output(String s)
104 if (local_silence_b_|| !os_l_)
107 for (char const *cp = s ; *cp; cp++)
111 case '(': indent_level_i_ += INDTAB;
118 indent_level_i_ -= INDTAB;
121 assert (indent_level_i_>=0) ;
125 *os_l_ << '\n' << String (' ', indent_level_i_) << flush;
135 Dstream::Dstream(ostream *r, char const * cfg_nm )
138 silent_assoc_p_ = new Assoc<String,bool>;
143 char const * fn =cfg_nm ? cfg_nm : ".dstreamrc";
145 ifstream ifs(fn); // can't open
152 Text_record r( cfg++);
154 r.message("not enough fields in Dstream init.");
157 (*silent_assoc_p_)[r[0]] = (bool)(int)(Scalar(r[1]));
165 delete silent_assoc_p_;
166 assert(!indent_level_i_) ;
170 Dstream::clear_silence()
172 for (Assoc_iter<String, bool> i(*silent_assoc_p_); i.ok(); i++) {