12 #ifndef ECL_CONTAINERS_COMMON_FORMATTERS_HPP_ 13 #define ECL_CONTAINERS_COMMON_FORMATTERS_HPP_ 30 namespace formatters {
66 template <
typename Container >
84 width_ptr(&prm_width),
87 ready_to_format(false)
118 unsigned int precision()
const {
return format.precision(); }
153 ready_to_format =
true;
157 width_ptr = &tmp_width;
170 template <
typename OutputStream,
typename Container_>
174 long digits(value_type min_coeff, value_type max_coeff);
192 template <
typename Container >
194 long min_digits, max_digits;
196 min_digits =
static_cast<long> ( ceil(log10(fabs(min_coeff)+1)) );
197 max_digits =
static_cast<long> ( ceil(log10(fabs(max_coeff)+1)) );
198 if ( min_digits < max_digits ) {
199 actual_digits = max_digits;
201 if ( ( min_digits == 0 ) && ( max_digits == 0 ) ) {
204 actual_digits = min_digits;
206 if ( min_coeff < 0 ) { actual_digits += 1; }
207 actual_digits += 1 + format.precision();
208 return actual_digits;
215 template <
typename OutputStream,
typename Container_>
218 "either there is no data available, or you have tried to use the " 219 "formatter more than once in a single streaming operation. " 220 "C++ produces unspecified results when functors are used multiply " 221 "in the same stream sequence, so this is not permitted here.") );
223 if ( *(formatter.width_ptr) == -1 ) {
227 typename Container_::value_type min_coeff, max_coeff;
228 const typename Container_::value_type *cur_coeff;
229 min_coeff = (*formatter.container)[0];
230 max_coeff = min_coeff;
233 for (
unsigned int i = 1; i < formatter.container->size(); ++i) {
234 cur_coeff = &(*formatter.container)[i];
235 if ( *cur_coeff > max_coeff ) { max_coeff = *cur_coeff; }
236 if ( *cur_coeff < min_coeff ) { min_coeff = *cur_coeff; }
241 formatter.format.width(formatter.digits(min_coeff,max_coeff));
243 formatter.format.width(*(formatter.width_ptr));
249 typename Container_::const_iterator iter;
251 for ( iter = formatter.container->begin(); iter != formatter.container->end(); ++iter ) {
252 ostream << formatter.format(*iter) <<
" ";
259 if ( formatter.old_precision != -1 ) {
260 formatter.format.precision(formatter.old_precision);
261 formatter.old_precision = -1;
264 formatter.width_ptr = &(formatter.prm_width);
265 formatter.ready_to_format =
false;
Embedded control libraries.
#define ecl_assert_throw(expression, exception)
#define ecl_assert_throw_decl(exception)