2 dstream.cc -- implement Dstream
4 source file of the Flower Library
6 (c) 1996, 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "dictionary-iter.hh"
12 #include "dictionary.hh"
14 #include "string-convert.hh"
15 #include "rational.hh"
17 /// amount of indentation for each level.
21 should use Regexp library.
24 strip_pretty (String pretty_str
)
26 int i
= pretty_str
.index_i ('(');
28 pretty_str
= pretty_str
.left_str (i
);
30 int l
= pretty_str
.index_last_i (' '); // strip until last ' '
32 pretty_str
= pretty_str
.nomid_str (0,l
+1);
37 strip_member (String pret
)
39 int l
=pret
.index_last_i (':')-1;
41 pret
= pret
.left_str (l
);
46 Dstream::identify_as (String name
)
51 String
mem (strip_pretty (name
));
52 String
cl (strip_member (mem
));
55 if (silent_dict_p_
->elem_b (mem
))
57 else if (silent_dict_p_
->elem_b (cl
))
61 (*silent_dict_p_
)[idx
] = default_silence_b_
;
63 local_silence_b_
= (*silent_dict_p_
)[idx
];
64 if (current_classname_str_
!= idx
&& !local_silence_b_
)
66 current_classname_str_
=idx
;
67 if (!(*silent_dict_p_
)["Dstream"])
68 *os_l_
<< "[" << current_classname_str_
<< ":]"; // messy.
74 Dstream::silent_b (String s
) const
79 if (!silent_dict_p_
->elem_b (s
))
81 return (*silent_dict_p_
)[s
];
85 Dstream::operator<<(void const *v_l
)
87 output (String_convert::pointer_str (v_l
));
92 Dstream::operator <<(String s
)
99 Dstream::operator <<(const char * s
)
106 Dstream::operator <<(char c
)
113 Dstream::operator << (Real r
)
119 Dstream::operator <<(Rational c
)
125 Dstream::operator <<(int i
)
132 Dstream::output (String s
)
134 if (local_silence_b_
|| !os_l_
)
137 for (char const *cp
= s
.ch_C (); *cp
; cp
++)
142 case '(': indent_level_i_
+= INDTAB
;
149 indent_level_i_
-= INDTAB
;
152 assert (indent_level_i_
>=0) ;
156 *os_l_
<< '\n' << to_str (' ', indent_level_i_
) << flush
;
166 Dstream::Dstream (ostream
*r
, char const * cfg_nm
)
169 silent_dict_p_
= new Dictionary
<bool>;
170 default_silence_b_
= false;
175 char const * fn
=cfg_nm
? cfg_nm
: ".dstreamrc";
177 ifstream
ifs (fn
); // can 't open
183 while (!cfg
.eof_b ()){
184 Text_record
r (cfg
++);
187 r
.message (_ ("not enough fields in Dstream init"));
190 (*silent_dict_p_
)[r
[0]] = r
[1] == "1";
193 if ((*silent_dict_p_
).elem_b ("Dstream_default_silence"))
194 default_silence_b_
= (*silent_dict_p_
)["Dstream_default_silence"];
200 delete silent_dict_p_
;
201 assert (!indent_level_i_
) ;
205 Dstream::clear_silence()
207 delete silent_dict_p_
;