File indexing completed on 2025-01-30 09:35:22
0001 #ifndef DATE_TIME_DATE_NAMES_PUT_HPP___
0002 #define DATE_TIME_DATE_NAMES_PUT_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <boost/date_time/locale_config.hpp> // set BOOST_DATE_TIME_NO_LOCALE
0014
0015 #ifndef BOOST_DATE_TIME_NO_LOCALE
0016
0017 #include <boost/date_time/compiler_config.hpp>
0018 #include <boost/date_time/special_defs.hpp>
0019 #include <boost/date_time/date_defs.hpp>
0020 #include <boost/date_time/parse_format_base.hpp>
0021 #include <boost/lexical_cast.hpp>
0022 #include <locale>
0023
0024
0025 namespace boost {
0026 namespace date_time {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 template<class Config,
0041 class charT = char,
0042 class OutputIterator = std::ostreambuf_iterator<charT> >
0043 class BOOST_SYMBOL_VISIBLE date_names_put : public std::locale::facet
0044 {
0045 public:
0046 date_names_put() {}
0047 typedef OutputIterator iter_type;
0048 typedef typename Config::month_type month_type;
0049 typedef typename Config::month_enum month_enum;
0050 typedef typename Config::weekday_enum weekday_enum;
0051 typedef typename Config::special_value_enum special_value_enum;
0052
0053 typedef std::basic_string<charT> string_type;
0054 typedef charT char_type;
0055 static const char_type default_special_value_names[3][17];
0056 static const char_type separator[2];
0057
0058 static std::locale::id id;
0059
0060 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
0061 std::locale::id& __get_id (void) const { return id; }
0062 #endif
0063
0064 void put_special_value(iter_type& oitr, special_value_enum sv) const
0065 {
0066 do_put_special_value(oitr, sv);
0067 }
0068 void put_month_short(iter_type& oitr, month_enum moy) const
0069 {
0070 do_put_month_short(oitr, moy);
0071 }
0072 void put_month_long(iter_type& oitr, month_enum moy) const
0073 {
0074 do_put_month_long(oitr, moy);
0075 }
0076 void put_weekday_short(iter_type& oitr, weekday_enum wd) const
0077 {
0078 do_put_weekday_short(oitr, wd);
0079 }
0080 void put_weekday_long(iter_type& oitr, weekday_enum wd) const
0081 {
0082 do_put_weekday_long(oitr, wd);
0083 }
0084 bool has_date_sep_chars() const
0085 {
0086 return do_has_date_sep_chars();
0087 }
0088 void year_sep_char(iter_type& oitr) const
0089 {
0090 do_year_sep_char(oitr);
0091 }
0092
0093 void month_sep_char(iter_type& oitr) const
0094 {
0095 do_month_sep_char(oitr);
0096 }
0097
0098 void day_sep_char(iter_type& oitr) const
0099 {
0100 do_day_sep_char(oitr);
0101 }
0102
0103 ymd_order_spec date_order() const
0104 {
0105 return do_date_order();
0106 }
0107
0108 month_format_spec month_format() const
0109 {
0110 return do_month_format();
0111 }
0112
0113 protected:
0114
0115 virtual void do_put_month_short(iter_type& oitr, month_enum moy) const
0116 {
0117 month_type gm(moy);
0118 charT c = '\0';
0119 put_string(oitr, gm.as_short_string(c));
0120 }
0121
0122 virtual void do_put_month_long(iter_type& oitr,
0123 month_enum moy) const
0124 {
0125 month_type gm(moy);
0126 charT c = '\0';
0127 put_string(oitr, gm.as_long_string(c));
0128 }
0129
0130 virtual void do_put_special_value(iter_type& oitr, special_value_enum sv) const
0131 {
0132 if(sv <= 2) {
0133 string_type s(default_special_value_names[sv]);
0134 put_string(oitr, s);
0135 }
0136 }
0137 virtual void do_put_weekday_short(iter_type&, weekday_enum) const
0138 {
0139 }
0140 virtual void do_put_weekday_long(iter_type&, weekday_enum) const
0141 {
0142 }
0143 virtual bool do_has_date_sep_chars() const
0144 {
0145 return true;
0146 }
0147 virtual void do_year_sep_char(iter_type& oitr) const
0148 {
0149 string_type s(separator);
0150 put_string(oitr, s);
0151 }
0152
0153 virtual void do_month_sep_char(iter_type& oitr) const
0154 {
0155 string_type s(separator);
0156 put_string(oitr, s);
0157 }
0158
0159 virtual void do_day_sep_char(iter_type& oitr) const
0160 {
0161 string_type s(separator);
0162 put_string(oitr, s);
0163 }
0164
0165 virtual ymd_order_spec do_date_order() const
0166 {
0167 return ymd_order_iso;
0168 }
0169
0170 virtual month_format_spec do_month_format() const
0171 {
0172 return month_as_short_string;
0173 }
0174 void put_string(iter_type& oi, const charT* const s) const
0175 {
0176 string_type s1(boost::lexical_cast<string_type>(s));
0177 typename string_type::iterator si,end;
0178 for (si=s1.begin(), end=s1.end(); si!=end; si++, oi++) {
0179 *oi = *si;
0180 }
0181 }
0182 void put_string(iter_type& oi, const string_type& s1) const
0183 {
0184 typename string_type::const_iterator si,end;
0185 for (si=s1.begin(), end=s1.end(); si!=end; si++, oi++) {
0186 *oi = *si;
0187 }
0188 }
0189 };
0190
0191 template<class Config, class charT, class OutputIterator>
0192 const typename date_names_put<Config, charT, OutputIterator>::char_type
0193 date_names_put<Config, charT, OutputIterator>::default_special_value_names[3][17] = {
0194 {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'},
0195 {'-','i','n','f','i','n','i','t','y'},
0196 {'+','i','n','f','i','n','i','t','y'} };
0197
0198 template<class Config, class charT, class OutputIterator>
0199 const typename date_names_put<Config, charT, OutputIterator>::char_type
0200 date_names_put<Config, charT, OutputIterator>::separator[2] =
0201 {'-', '\0'} ;
0202
0203
0204
0205 template<class Config, class charT, class OutputIterator>
0206 std::locale::id date_names_put<Config, charT, OutputIterator>::id;
0207
0208
0209 template<class Config,
0210 class charT = char,
0211 class OutputIterator = std::ostreambuf_iterator<charT> >
0212 class BOOST_SYMBOL_VISIBLE all_date_names_put : public date_names_put<Config, charT, OutputIterator>
0213 {
0214 public:
0215 all_date_names_put(const charT* const month_short_names[],
0216 const charT* const month_long_names[],
0217 const charT* const special_value_names[],
0218 const charT* const weekday_short_names[],
0219 const charT* const weekday_long_names[],
0220 charT separator_char = '-',
0221 ymd_order_spec order_spec = ymd_order_iso,
0222 month_format_spec month_format = month_as_short_string) :
0223 month_short_names_(month_short_names),
0224 month_long_names_(month_long_names),
0225 special_value_names_(special_value_names),
0226 weekday_short_names_(weekday_short_names),
0227 weekday_long_names_(weekday_long_names),
0228 order_spec_(order_spec),
0229 month_format_spec_(month_format)
0230 {
0231 separator_char_[0] = separator_char;
0232 separator_char_[1] = '\0';
0233
0234 }
0235 typedef OutputIterator iter_type;
0236 typedef typename Config::month_enum month_enum;
0237 typedef typename Config::weekday_enum weekday_enum;
0238 typedef typename Config::special_value_enum special_value_enum;
0239
0240 const charT* const* get_short_month_names() const
0241 {
0242 return month_short_names_;
0243 }
0244 const charT* const* get_long_month_names() const
0245 {
0246 return month_long_names_;
0247 }
0248 const charT* const* get_special_value_names() const
0249 {
0250 return special_value_names_;
0251 }
0252 const charT* const* get_short_weekday_names()const
0253 {
0254 return weekday_short_names_;
0255 }
0256 const charT* const* get_long_weekday_names()const
0257 {
0258 return weekday_long_names_;
0259 }
0260
0261 protected:
0262
0263 virtual void do_put_month_short(iter_type& oitr, month_enum moy) const
0264 {
0265 this->put_string(oitr, month_short_names_[moy-1]);
0266 }
0267
0268 virtual void do_put_month_long(iter_type& oitr, month_enum moy) const
0269 {
0270 this->put_string(oitr, month_long_names_[moy-1]);
0271 }
0272
0273 virtual void do_put_special_value(iter_type& oitr, special_value_enum sv) const
0274 {
0275 this->put_string(oitr, special_value_names_[sv]);
0276 }
0277 virtual void do_put_weekday_short(iter_type& oitr, weekday_enum wd) const
0278 {
0279 this->put_string(oitr, weekday_short_names_[wd]);
0280 }
0281 virtual void do_put_weekday_long(iter_type& oitr, weekday_enum wd) const
0282 {
0283 this->put_string(oitr, weekday_long_names_[wd]);
0284 }
0285
0286 virtual void do_month_sep_char(iter_type& oitr) const
0287 {
0288 this->put_string(oitr, separator_char_);
0289 }
0290
0291 virtual void do_day_sep_char(iter_type& oitr) const
0292 {
0293 this->put_string(oitr, separator_char_);
0294 }
0295
0296 virtual ymd_order_spec do_date_order() const
0297 {
0298 return order_spec_;
0299 }
0300
0301 virtual month_format_spec do_month_format() const
0302 {
0303 return month_format_spec_;
0304 }
0305
0306 private:
0307 const charT* const* month_short_names_;
0308 const charT* const* month_long_names_;
0309 const charT* const* special_value_names_;
0310 const charT* const* weekday_short_names_;
0311 const charT* const* weekday_long_names_;
0312 charT separator_char_[2];
0313 ymd_order_spec order_spec_;
0314 month_format_spec month_format_spec_;
0315 };
0316
0317 } }
0318
0319 #endif
0320
0321 #endif