12 #ifndef ECL_FORMATTERS_STRINGS_HPP_
13 #define ECL_FORMATTERS_STRINGS_HPP_
62 Format<std::string>& width(
int w) { width_ = w;
return *
this; }
68 Format<std::string>& align(
Alignment a) { alignment_ = a;
return *
this; }
79 Format<std::string>& operator ()(
int w,
Alignment a);
134 bool ready_to_format;
145 template <
typename OutputStream>
void pad(
int n, OutputStream &ostream)
const;
151 template <
typename OutputStream>
void prePad(
int n, OutputStream &ostream)
const;
157 template <
typename OutputStream>
void postPad(
int n, OutputStream &ostream)
const;
166 template <
typename OutputStream>
void format(OutputStream &ostream)
const;
173 template <
typename OutputStream>
178 prePad(width_ - (size),ostream);
180 postPad(width_ - (size),ostream);
183 template <
typename OutputStream>
186 if ( n <= 0 ) {
return; }
187 switch ( alignment_ )
191 case (
RightAlign ) : { pad(n,ostream);
break; }
192 case (
CentreAlign ) : { pad(n/2+ n%2,ostream);
break; }
196 template <
typename OutputStream>
199 if ( n <= 0 ) {
return; }
200 switch ( alignment_ )
205 case (
CentreAlign ) : { pad(n/2,ostream);
break; }
209 template <
typename OutputStream>
212 for (
int i = n; i > 0; --i )
222 template <
typename OutputStream>
228 "either there is no data available, or you have tried to use the "
229 "formatter more than once in a single streaming operation. "
230 "C++ produces unspecified results when functors are used multiply "
231 "in the same stream sequence, so this is not permitted here.") );
234 formatter.format(ostream);
235 formatter.ready_to_format =
false;