12 #ifndef ECL_FORMATTERS_FLOATS_HPP_ 13 #define ECL_FORMATTERS_FLOATS_HPP_ 25 #define snprintf _snprintf 48 namespace interfaces {
60 template <
typename Number>
208 template <
typename OutputStream,
typename N>
209 friend OutputStream& operator << (OutputStream& ostream, FormatFloat<N>& formatter);
228 template <
typename OutputStream>
void pad(
int n, OutputStream &ostream)
const;
229 template <
typename OutputStream>
void prePad(
int n, OutputStream &ostream)
const;
230 template <
typename OutputStream>
void postPad(
int n, OutputStream &ostream)
const;
235 template <
typename OutputStream>
void formatFixed(OutputStream &ostream)
const;
236 template <
typename OutputStream>
void formatSci(OutputStream &ostream)
const;
247 template <
typename Number>
257 template <
typename Number>
273 template <
typename Number>
288 template <
typename Number>
296 template <
typename Number>
309 template <
typename Number>
319 template <
typename Number>
339 template <
typename Number>
363 template <
typename Number>
364 template <
typename OutputStream>
367 static char format_specifier[6] =
"%.xff";
370 format_specifier[3] =
'f';
371 format_specifier[4] =
'\0';
373 format_specifier[2] =
'1';
375 format_specifier[4] =
'f';
377 format_specifier[2] =
'2';
378 format_specifier[3] =
'0';
379 format_specifier[4] =
'f';
381 static const int buffer_size = 30;
382 static char buffer[buffer_size];
384 snprintf(buffer, buffer_size, format_specifier,
value_);
389 int length = strlen(buffer);
395 template <
typename Number>
396 template <
typename OutputStream>
399 ostream <<
"Scientific format is not yet supported." <<
"\n";
403 template <
typename Number>
404 template <
typename OutputStream>
407 if ( n <= 0 ) {
return; }
418 template <
typename Number>
419 template <
typename OutputStream>
422 if ( n <= 0 ) {
return; }
433 template <
typename Number>
434 template <
typename OutputStream>
437 for (
int i = n; i > 0; --i )
446 template <
typename OutputStream,
typename N>
447 OutputStream& operator << (OutputStream &ostream, FormatFloat<N>& formatter )
449 bool ready = formatter.ready_to_format;
452 "either there is no data available, or you have tried to use the " 453 "formatter more than once in a single streaming operation. " 454 "C++ produces unspecified results when functors are used multiply " 455 "in the same stream sequence, so this is not permitted here.") );
459 switch(*(formatter.base_) )
462 formatter.formatFixed(ostream);
466 formatter.formatSci(ostream);
472 if ( formatter.width_ != &(formatter.prm_width) ) {
473 formatter.width_ = &(formatter.prm_width);
474 formatter.precision_ = &(formatter.prm_precision);
475 formatter.alignment_ = &(formatter.prm_alignment);
476 formatter.base_ = &(formatter.prm_base);
478 formatter.ready_to_format =
false;
Embedded control libraries.
Common formatting definitions.
#define ecl_assert_throw(expression, exception)
Scientific formatting for floats (i.e. exponential representation).
Fixed formatting for floats (i.e. normal decimal representation).
FloatBase
Base format tags for the float formatters.
Alignment
Alignment tags for text formatting.