8 #ifndef BOOST_LOCALE_FORMAT_HPP_INCLUDED
9 #define BOOST_LOCALE_FORMAT_HPP_INCLUDED
11 #include <boost/locale/config.hpp>
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
16 #include <boost/locale/message.hpp>
17 #include <boost/locale/formatting.hpp>
36 template<
typename CharType>
38 typedef std::basic_ostream<CharType> stream_type;
39 typedef void (*writer_type)(stream_type &output,
void const *ptr);
43 writer_(&formattible::void_write)
47 formattible(formattible
const &other) :
48 pointer_(other.pointer_),
49 writer_(other.writer_)
53 formattible
const &operator=(formattible
const &other)
56 pointer_=other.pointer_;
57 writer_=other.writer_;
62 template<
typename Type>
63 formattible(Type
const &value)
65 pointer_ =
static_cast<void const *
>(&value);
66 writer_ = &write<Type>;
69 template<
typename Type>
70 formattible
const &operator=(Type
const &other)
72 *
this = formattible(other);
76 friend stream_type &
operator<<(stream_type &out,formattible
const &fmt)
78 fmt.writer_(out,fmt.pointer_);
83 static void void_write(stream_type &output,
void const * )
85 CharType empty_string[1]={0};
89 template<
typename Type>
90 static void write(stream_type &output,
void const *ptr)
92 output << *static_cast<Type const *>(ptr);
99 class BOOST_LOCALE_DECL format_parser {
101 format_parser(std::ios_base &ios,
void *,
void (*imbuer)(
void *,std::locale
const &));
104 unsigned get_position();
106 void set_one_flag(std::string
const &key,std::string
const &value);
108 template<
typename CharType>
109 void set_flag_with_str(std::string
const &key,std::basic_string<CharType>
const &value)
111 if(key==
"ftime" || key==
"strftime") {
118 void imbue(std::locale
const &);
119 format_parser(format_parser
const &);
120 void operator=(format_parser
const &);
124 std::auto_ptr<data> d;
203 template<
typename CharType>
208 typedef details::formattible<CharType> formattible_type;
220 format_(format_string),
240 template<
typename Formattible>
243 add(formattible_type(
object));
252 std::basic_ostringstream<CharType> buffer;
269 format_output(out,format);
278 format_guard(details::format_parser &fmt) :
299 details::format_parser *fmt_;
312 size_t size=sformat.size();
313 CharType
const *
format=sformat.c_str();
314 while(format[pos]!=0) {
315 if(format[pos] != obrk) {
316 if(format[pos]==cbrk && format[pos+1]==cbrk) {
327 if(pos+1 < size && format[pos+1]==obrk) {
334 details::format_parser fmt(out,static_cast<void *>(&out),&basic_format::imbue_locale);
336 format_guard guard(fmt);
342 bool use_svalue =
true;
343 for(;format[pos];pos++) {
345 if(c==comma || c==eq || c==cbrk)
348 key+=
static_cast<char>(c);
352 if(format[pos]==eq) {
354 if(format[pos]==quote) {
358 if(format[pos]==quote) {
359 if(format[pos+1]==quote) {
376 while((c=format[pos])!=0 && c!=comma && c!=cbrk) {
377 svalue+=
static_cast<char>(c);
384 fmt.set_one_flag(key,svalue);
387 fmt.set_flag_with_str(key,value);
389 if(format[pos]==comma) {
393 else if(format[pos]==cbrk) {
394 unsigned position = fmt.get_position();
395 out <<
get(position);
415 void add(formattible_type
const ¶m)
417 if(parameters_count_ >= base_params_)
418 ext_params_.push_back(param);
420 parameters_[parameters_count_] = param;
424 formattible_type
get(
unsigned id)
const
426 if(
id >= parameters_count_)
427 return formattible_type();
428 else if(
id >= base_params_)
429 return ext_params_[
id - base_params_];
431 return parameters_[id];
434 static void imbue_locale(
void *ptr,std::locale
const &l)
441 static unsigned const base_params_ = 8;
448 formattible_type parameters_[base_params_];
449 unsigned parameters_count_;
450 std::vector<formattible_type> ext_params_;
458 template<
typename CharType>
476 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
483 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
std::ios_base & strftime(std::ios_base &ios)
Definition: formatting.hpp:347
string_type str() const
Definition: message.hpp:353
static ios_info & get(std::ios_base &ios)
std::basic_ostream< CharType > & operator<<(std::basic_ostream< CharType > &out, date_time const &t)
Definition: date_time.hpp:874
void date_time_pattern(std::basic_string< CharType > const &str)
Definition: formatting.hpp:155