6 #include "string-convert.hh"
8 /// indent of each level
12 should use Regexp library.
15 strip_pretty(String pretty_str
)
17 int i
= pretty_str
.index_i('(');
19 pretty_str
= pretty_str
.left_str(i
);
21 int l
= pretty_str
.index_last_i(' '); // strip until last ' '
23 pretty_str
= pretty_str
.nomid_str(0,l
+1);
28 strip_member(String pret
)
30 int l
=pret
.index_last_i(':')-1;
32 pret
= pret
.left_str(l
);
37 Dstream::identify_as(String name
)
42 String
mem(strip_pretty(name
));
43 String
cl(strip_member(mem
));
46 if (silent
->elt_query(mem
))
48 else if (silent
->elt_query(cl
))
51 (*silent
)[idx
] = false;
53 local_silence
= (*silent
)[idx
];
54 if (classname
!= idx
&& !local_silence
) {
56 // *os << "[" << classname << ":]"; // messy.
62 Dstream::silence(String s
)
64 if (!silent
->elt_query(s
))
69 /** Output a string via the Dstream. This is the only output
70 interface. It delegates all conversion to String class. */
72 Dstream::operator<<(String s
)
79 Dstream::operator<<(const void *v_l
)
81 output(String_convert::pointer_str(v_l
));
86 Dstream::operator<<(const char *ch_l
)
93 Dstream::output(String s
)
95 if (local_silence
|| !os
)
98 for (const char *cp
= s
; *cp
; cp
++)
102 case '(': indentlvl
+= INDTAB
;
112 assert (indentlvl
>=0) ;
116 *os
<< '\n' << String (' ', indentlvl
) << flush
;
126 Dstream::Dstream(ostream
*r
, const char * cfg_nm
)
129 silent
= new Assoc
<String
,bool>;
134 const char * fn
=cfg_nm
? cfg_nm
: ".dstreamrc";
136 ifstream
ifs(fn
); // can't open
143 Text_record
r( cfg
++);
145 r
.message("not enough fields in Dstream init.");
148 (*silent
)[r
[0]] = (bool)(int)(Scalar(r
[1]));