text.cc (9420:965d857ac791) text.cc (9743:436a74146cbc)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 180 unchanged lines hidden (view full) ---

189 string desc;
190 Flags flags;
191 bool descriptions;
192 int precision;
193 Result pdf;
194 Result cdf;
195
196 void update(Result val, Result total);
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 180 unchanged lines hidden (view full) ---

189 string desc;
190 Flags flags;
191 bool descriptions;
192 int precision;
193 Result pdf;
194 Result cdf;
195
196 void update(Result val, Result total);
197 void operator()(ostream &stream) const;
197 void operator()(ostream &stream, bool oneLine = false) const;
198};
199
200void
201ScalarPrint::update(Result val, Result total)
202{
203 value = val;
204 if (total) {
205 pdf = val / total;
206 cdf += pdf;
207 }
208}
209
210void
198};
199
200void
201ScalarPrint::update(Result val, Result total)
202{
203 value = val;
204 if (total) {
205 pdf = val / total;
206 cdf += pdf;
207 }
208}
209
210void
211ScalarPrint::operator()(ostream &stream) const
211ScalarPrint::operator()(ostream &stream, bool oneLine) const
212{
213 if ((flags.isSet(nozero) && value == 0.0) ||
214 (flags.isSet(nonan) && std::isnan(value)))
215 return;
216
217 stringstream pdfstr, cdfstr;
218
219 if (!std::isnan(pdf))
220 ccprintf(pdfstr, "%.2f%%", pdf * 100.0);
221
222 if (!std::isnan(cdf))
223 ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
224
212{
213 if ((flags.isSet(nozero) && value == 0.0) ||
214 (flags.isSet(nonan) && std::isnan(value)))
215 return;
216
217 stringstream pdfstr, cdfstr;
218
219 if (!std::isnan(pdf))
220 ccprintf(pdfstr, "%.2f%%", pdf * 100.0);
221
222 if (!std::isnan(cdf))
223 ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
224
225 ccprintf(stream, "%-40s %12s %10s %10s", name,
226 ValueToString(value, precision), pdfstr.str(), cdfstr.str());
225 if (oneLine) {
226 ccprintf(stream, " |%12s %10s %10s",
227 ValueToString(value, precision), pdfstr.str(), cdfstr.str());
228 } else {
229 ccprintf(stream, "%-40s %12s %10s %10s", name,
230 ValueToString(value, precision), pdfstr.str(), cdfstr.str());
227
231
228 if (descriptions) {
229 if (!desc.empty())
230 ccprintf(stream, " # %s", desc);
232 if (descriptions) {
233 if (!desc.empty())
234 ccprintf(stream, " # %s", desc);
235 }
236 stream << endl;
231 }
237 }
232 stream << endl;
233}
234
235struct VectorPrint
236{
237 string name;
238 string separatorString;
239 string desc;
240 vector<string> subnames;

--- 33 unchanged lines hidden (view full) ---

274 bool havesub = !subnames.empty();
275
276 if (_size == 1) {
277 print.value = vec[0];
278 print(stream);
279 return;
280 }
281
238}
239
240struct VectorPrint
241{
242 string name;
243 string separatorString;
244 string desc;
245 vector<string> subnames;

--- 33 unchanged lines hidden (view full) ---

279 bool havesub = !subnames.empty();
280
281 if (_size == 1) {
282 print.value = vec[0];
283 print(stream);
284 return;
285 }
286
282 for (off_type i = 0; i < _size; ++i) {
283 if (havesub && (i >= subnames.size() || subnames[i].empty()))
284 continue;
287 if ((!flags.isSet(nozero)) || (total != 0)) {
288 if (flags.isSet(oneline)) {
289 ccprintf(stream, "%-40s", name);
290 print.flags = print.flags & (~nozero);
291 }
285
292
286 print.name = base + (havesub ? subnames[i] : to_string(i));
287 print.desc = subdescs.empty() ? desc : subdescs[i];
293 for (off_type i = 0; i < _size; ++i) {
294 if (havesub && (i >= subnames.size() || subnames[i].empty()))
295 continue;
288
296
289 print.update(vec[i], _total);
290 print(stream);
297 print.name = base + (havesub ? subnames[i] : to_string(i));
298 print.desc = subdescs.empty() ? desc : subdescs[i];
299
300 print.update(vec[i], _total);
301 print(stream, flags.isSet(oneline));
302 }
303
304 if (flags.isSet(oneline)) {
305 if (descriptions) {
306 if (!desc.empty())
307 ccprintf(stream, " # %s", desc);
308 }
309
310 stream << endl;
311 }
291 }
292
293 if (flags.isSet(::Stats::total)) {
294 print.pdf = NAN;
295 print.cdf = NAN;
296 print.name = base + "total";
297 print.desc = desc;
298 print.value = total;
299 print(stream);
300 }
312 }
313
314 if (flags.isSet(::Stats::total)) {
315 print.pdf = NAN;
316 print.cdf = NAN;
317 print.name = base + "total";
318 print.desc = desc;
319 print.value = total;
320 print(stream);
321 }
322
323 if (flags.isSet(oneline) && ((!flags.isSet(nozero)) || (total != 0))) {
324 stream << endl;
325 }
301}
302
303struct DistPrint
304{
305 string name;
306 string separatorString;
307 string desc;
308 Flags flags;

--- 394 unchanged lines hidden ---
326}
327
328struct DistPrint
329{
330 string name;
331 string separatorString;
332 string desc;
333 Flags flags;

--- 394 unchanged lines hidden ---