8 #include "string-convert.hh"
10 /// indent of each level
14 should use Regexp library.
17 strip_pretty(String pretty_str)
19 int i = pretty_str.index_i('(');
21 pretty_str = pretty_str.left_str(i);
23 int l = pretty_str.index_last_i(' '); // strip until last ' '
25 pretty_str = pretty_str.nomid_str(0,l+1);
30 strip_member(String pret)
32 int l=pret.index_last_i(':')-1;
34 pret = pret.left_str(l );
39 Dstream::identify_as(String name)
44 String mem(strip_pretty(name));
45 String cl(strip_member(mem));
48 if (silent->elt_query(mem))
50 else if (silent->elt_query(cl))
53 (*silent)[idx] = false;
55 local_silence = (*silent)[idx];
56 if (classname != idx && !local_silence) {
58 if (!(*silent)["Dstream"])
59 *os << "[" << classname << ":]"; // messy.
65 Dstream::silence(String s)
67 if (!silent->elt_query(s))
72 /** Output a string via the Dstream. This is the only output
73 interface. It delegates all conversion to String class. */
75 Dstream::operator<<(String s)
82 Dstream::operator<<(const void *v_l)
84 output(String_convert::pointer_str(v_l));
89 Dstream::operator<<(const char *ch_l)
96 Dstream::output(String s)
98 if (local_silence|| !os)
101 for (const char *cp = s ; *cp; cp++)
105 case '(': indentlvl += INDTAB;
115 assert (indentlvl>=0) ;
119 *os << '\n' << String (' ', indentlvl) << flush;
129 Dstream::Dstream(ostream *r, const char * cfg_nm )
132 silent = new Assoc<String,bool>;
137 const char * fn =cfg_nm ? cfg_nm : ".dstreamrc";
139 ifstream ifs(fn); // can't open
146 Text_record r( cfg++);
148 r.message("not enough fields in Dstream init.");
151 (*silent)[r[0]] = (bool)(int)(Scalar(r[1]));