8 #ifndef BOOSTER_LOCALE_FORMAT_H_INCLUDED 9 #define BOOSTER_LOCALE_FORMAT_H_INCLUDED 11 #include <booster/config.h> 13 # pragma warning(push) 14 # pragma warning(disable : 4275 4251 4231 4660) 16 #include <booster/locale/message.h> 17 #include <booster/locale/formatting.h> 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 BOOSTER_API 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));
250 string_type
str(std::locale
const &loc = std::locale())
const 252 std::basic_ostringstream<CharType> buffer;
269 format_output(out,format);
278 format_guard(details::format_parser &fmt) :
299 details::format_parser *fmt_;
303 void format_output(stream_type &out,string_type
const &sformat)
const 309 char_type quote=
'\'';
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++) {
344 char_type c=format[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)
436 reinterpret_cast<stream_type *
>(ptr)->imbue(l);
441 static unsigned const base_params_ = 8;
443 message_type message_;
448 formattible_type parameters_[base_params_];
449 unsigned parameters_count_;
450 std::vector<formattible_type> ext_params_;
458 template<
typename CharType>
476 #ifdef BOOSTER_HAS_CHAR16_T 483 #ifdef BOOSTER_HAS_CHAR32_T
std::basic_ostream< CharType > & operator<<(std::basic_ostream< CharType > &out, date_time const &t)
Definition: date_time.h:874
static ios_info & get(std::ios_base &ios)
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
void date_time_pattern(std::basic_string< CharType > const &str)
Definition: formatting.h:155
std::ios_base & strftime(std::ios_base &ios)
Definition: formatting.h:347
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23