00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOOST_LOCALE_FORMATTING_HPP_INCLUDED
00009 #define BOOST_LOCALE_FORMATTING_HPP_INCLUDED
00010
00011 #include <boost/locale/config.hpp>
00012 #ifdef BOOST_MSVC
00013 # pragma warning(push)
00014 # pragma warning(disable : 4275 4251 4231 4660)
00015 #endif
00016 #include <boost/locale/time_zone.hpp>
00017 #include <boost/cstdint.hpp>
00018 #include <ostream>
00019 #include <istream>
00020 #include <string>
00021
00022 namespace boost {
00023 namespace locale {
00024 namespace flags {
00025 typedef enum {
00026 posix = 0,
00027 number = 1,
00028 currency = 2,
00029 percent = 3,
00030 date = 4,
00031 time = 5,
00032 datetime = 6,
00033 strftime = 7,
00034 spellout = 8,
00035 ordinal = 9,
00036
00037 display_flags_mask = 31,
00038
00039 currency_default = 0 << 5,
00040 currency_iso = 1 << 5,
00041 currency_national = 2 << 5,
00042
00043 currency_flags_mask = 3 << 5,
00044
00045 time_default = 0 << 7,
00046 time_short = 1 << 7,
00047 time_medium = 2 << 7,
00048 time_long = 3 << 7,
00049 time_full = 4 << 7,
00050 time_flags_mask = 7 << 7,
00051
00052 date_default = 0 << 10,
00053 date_short = 1 << 10,
00054 date_medium = 2 << 10,
00055 date_long = 3 << 10,
00056 date_full = 4 << 10,
00057 date_flags_mask = 7 << 10,
00058
00059 datetime_flags_mask = date_flags_mask | time_flags_mask
00060
00061 } display_flags_type;
00062
00063 typedef enum {
00064 datetime_pattern,
00065 time_zone_id
00066 } pattern_type;
00067
00068 typedef enum {
00069 domain_id
00070 } value_type;
00071
00072
00073 }
00074
00076
00077 BOOST_LOCALE_DECL uint64_t ext_flags(std::ios_base &);
00078 BOOST_LOCALE_DECL uint64_t ext_flags(std::ios_base &,flags::display_flags_type mask);
00079 BOOST_LOCALE_DECL void ext_setf(std::ios_base &,flags::display_flags_type flags,flags::display_flags_type mask);
00080
00081 BOOST_LOCALE_DECL int ext_value(std::ios_base &,flags::value_type id);
00082 BOOST_LOCALE_DECL void ext_value(std::ios_base &,flags::value_type id,int value);
00083
00084 template<typename CharType>
00085 void ext_pattern(std::ios_base &,flags::pattern_type pat,std::basic_string<CharType> const &);
00086
00087 template<typename CharType>
00088 std::basic_string<CharType> ext_pattern(std::ios_base &,flags::pattern_type pattern);
00089
00091
00092 template<>
00093 BOOST_LOCALE_DECL void ext_pattern(std::ios_base &,flags::pattern_type pattern_id, std::string const &pattern);
00094
00095 template<>
00096 BOOST_LOCALE_DECL std::string ext_pattern(std::ios_base &,flags::pattern_type pattern_id);
00097
00098 #ifndef BOOST_NO_STD_WSTRING
00099
00100 template<>
00101 BOOST_LOCALE_DECL void ext_pattern(std::ios_base &,flags::pattern_type pattern_id, std::wstring const &pattern);
00102
00103 template<>
00104 BOOST_LOCALE_DECL std::wstring ext_pattern(std::ios_base &,flags::pattern_type pattern_id);
00105
00106 #endif // BOOST_NO_STD_WSTRING
00107
00108 #ifdef BOOST_HAS_CHAR16_T
00109 template<>
00110 BOOST_LOCALE_DECL void ext_pattern(std::ios_base &,flags::pattern_type pattern_id, std::u16string const &pattern);
00111
00112 template<>
00113 BOOST_LOCALE_DECL std::u16string ext_pattern(std::ios_base &,flags::pattern_type pattern_id);
00114 #endif // char16_t, u16string
00115
00116 #ifdef BOOST_HAS_CHAR32_T
00117 template<>
00118 BOOST_LOCALE_DECL void ext_pattern(std::ios_base &,flags::pattern_type pattern_id, std::u32string const &pattern);
00119
00120 template<>
00121 BOOST_LOCALE_DECL std::u32string ext_pattern(std::ios_base &,flags::pattern_type pattern_id);
00122 #endif // char32_t, u32string
00123
00125
00129 namespace as {
00135
00140
00141 inline std::ios_base & posix(std::ios_base & ios)
00142 {
00143 ext_setf(ios, flags::posix, flags::display_flags_mask);
00144 return ios;
00145 }
00146
00151 inline std::ios_base & number(std::ios_base & ios)
00152 {
00153 ext_setf(ios, flags::number, flags::display_flags_mask);
00154 return ios;
00155 }
00156
00160 inline std::ios_base & currency(std::ios_base & ios)
00161 {
00162 ext_setf(ios, flags::currency, flags::display_flags_mask);
00163 return ios;
00164 }
00165
00169 inline std::ios_base & percent(std::ios_base & ios)
00170 {
00171 ext_setf(ios, flags::percent, flags::display_flags_mask);
00172 return ios;
00173 }
00174
00178 inline std::ios_base & date(std::ios_base & ios)
00179 {
00180 ext_setf(ios, flags::date, flags::display_flags_mask);
00181 return ios;
00182 }
00183
00187 inline std::ios_base & time(std::ios_base & ios)
00188 {
00189 ext_setf(ios, flags::time, flags::display_flags_mask);
00190 return ios;
00191 }
00192
00196 inline std::ios_base & datetime(std::ios_base & ios)
00197 {
00198 ext_setf(ios, flags::datetime, flags::display_flags_mask);
00199 return ios;
00200 }
00201
00206 inline std::ios_base & strftime(std::ios_base & ios)
00207 {
00208 ext_setf(ios, flags::strftime, flags::display_flags_mask);
00209 return ios;
00210 }
00211
00215 inline std::ios_base & spellout(std::ios_base & ios)
00216 {
00217 ext_setf(ios, flags::spellout, flags::display_flags_mask);
00218 return ios;
00219 }
00220
00224 inline std::ios_base & ordinal(std::ios_base & ios)
00225 {
00226 ext_setf(ios, flags::ordinal, flags::display_flags_mask);
00227 return ios;
00228 }
00229
00233 inline std::ios_base & currency_default(std::ios_base & ios)
00234 {
00235 ext_setf(ios, flags::currency_default, flags::currency_flags_mask);
00236 return ios;
00237 }
00238
00242 inline std::ios_base & currency_iso(std::ios_base & ios)
00243 {
00244 ext_setf(ios, flags::currency_iso, flags::currency_flags_mask);
00245 return ios;
00246 }
00247
00251 inline std::ios_base & currency_national(std::ios_base & ios)
00252 {
00253 ext_setf(ios, flags::currency_national, flags::currency_flags_mask);
00254 return ios;
00255 }
00256
00260 inline std::ios_base & time_default(std::ios_base & ios)
00261 {
00262 ext_setf(ios, flags::time_default, flags::time_flags_mask);
00263 return ios;
00264 }
00265
00269 inline std::ios_base & time_short(std::ios_base & ios)
00270 {
00271 ext_setf(ios, flags::time_short, flags::time_flags_mask);
00272 return ios;
00273 }
00274
00278 inline std::ios_base & time_medium(std::ios_base & ios)
00279 {
00280 ext_setf(ios, flags::time_medium, flags::time_flags_mask);
00281 return ios;
00282 }
00283
00287 inline std::ios_base & time_long(std::ios_base & ios)
00288 {
00289 ext_setf(ios, flags::time_long, flags::time_flags_mask);
00290 return ios;
00291 }
00292
00296 inline std::ios_base & time_full(std::ios_base & ios)
00297 {
00298 ext_setf(ios, flags::time_full, flags::time_flags_mask);
00299 return ios;
00300 }
00301
00305 inline std::ios_base & date_default(std::ios_base & ios)
00306 {
00307 ext_setf(ios, flags::date_default, flags::date_flags_mask);
00308 return ios;
00309 }
00310
00314 inline std::ios_base & date_short(std::ios_base & ios)
00315 {
00316 ext_setf(ios, flags::date_short, flags::date_flags_mask);
00317 return ios;
00318 }
00319
00323 inline std::ios_base & date_medium(std::ios_base & ios)
00324 {
00325 ext_setf(ios, flags::date_medium, flags::date_flags_mask);
00326 return ios;
00327 }
00328
00332 inline std::ios_base & date_long(std::ios_base & ios)
00333 {
00334 ext_setf(ios, flags::date_long, flags::date_flags_mask);
00335 return ios;
00336 }
00337
00341 inline std::ios_base & date_full(std::ios_base & ios)
00342 {
00343 ext_setf(ios, flags::date_full, flags::date_flags_mask);
00344 return ios;
00345 }
00346
00347
00349 namespace details {
00350 template<typename CharType>
00351 struct add_ftime {
00352
00353 std::basic_string<CharType> ftime;
00354
00355 void apply(std::basic_ios<CharType> &ios) const
00356 {
00357 ext_pattern(ios,flags::datetime_pattern,ftime);
00358 as::strftime(ios);
00359 }
00360
00361 };
00362
00363 template<typename CharType>
00364 std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,add_ftime<CharType> const &fmt)
00365 {
00366 fmt.apply(out);
00367 return out;
00368 }
00369
00370 template<typename CharType>
00371 std::basic_istream<CharType> &operator>>(std::basic_istream<CharType> &in,add_ftime<CharType> const &fmt)
00372 {
00373 fmt.apply(in);
00374 return in;
00375 }
00376
00377 }
00379
00414
00415
00416 template<typename CharType>
00417 details::add_ftime<CharType> ftime(std::basic_string<CharType> const &format)
00418 {
00419 details::add_ftime<CharType> fmt;
00420 fmt.ftime=format;
00421 return fmt;
00422 }
00423
00427 template<typename CharType>
00428 details::add_ftime<CharType> ftime(CharType const *format)
00429 {
00430 details::add_ftime<CharType> fmt;
00431 fmt.ftime=format;
00432 return fmt;
00433 }
00434
00436 namespace details {
00437 struct set_timezone {
00438 std::string id;
00439 };
00440 template<typename CharType>
00441 std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,set_timezone const &fmt)
00442 {
00443 ext_pattern(out,flags::time_zone_id,fmt.id);
00444 return out;
00445 }
00446
00447 template<typename CharType>
00448 std::basic_istream<CharType> &operator>>(std::basic_istream<CharType> &in,set_timezone const &fmt)
00449 {
00450 ext_pattern(in,flags::time_zone_id,fmt.id);
00451 return in;
00452 }
00453 }
00455
00459 inline std::ios_base &gmt(std::ios_base &ios)
00460 {
00461 ext_pattern<char>(ios,flags::time_zone_id,"GMT");
00462 return ios;
00463 }
00464
00468 inline std::ios_base &local_time(std::ios_base &ios)
00469 {
00470 ext_pattern(ios,flags::time_zone_id,std::string());
00471 return ios;
00472 }
00473
00477 inline details::set_timezone time_zone(char const *id)
00478 {
00479 details::set_timezone tz;
00480 tz.id=id;
00481 return tz;
00482 }
00483
00487 inline details::set_timezone time_zone(std::string const &id)
00488 {
00489 details::set_timezone tz;
00490 tz.id=id;
00491 return tz;
00492 }
00493
00497 inline details::set_timezone time_zone(boost::locale::time_zone const &id)
00498 {
00499 details::set_timezone tz;
00500 tz.id=id.id();
00501 return tz;
00502 }
00503
00504
00508
00509 }
00510
00511 }
00512 }
00513
00514 #ifdef BOOST_MSVC
00515 #pragma warning(pop)
00516 #endif
00517
00518
00519 #endif
00520