File indexing completed on 2025-01-30 09:35:19
0001 #ifndef GREGORIAN_SERIALIZE_HPP___
0002 #define GREGORIAN_SERIALIZE_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "boost/date_time/gregorian/gregorian_types.hpp"
0013 #include "boost/date_time/gregorian/parsers.hpp"
0014 #include "boost/core/nvp.hpp"
0015
0016
0017 namespace boost {
0018
0019 namespace gregorian {
0020 std::string to_iso_string(const date&);
0021 }
0022
0023 namespace serialization {
0024
0025
0026
0027
0028 #define BOOST_DATE_TIME_SPLIT_FREE(T) \
0029 template<class Archive> \
0030 inline void serialize(Archive & ar, \
0031 T & t, \
0032 const unsigned int file_version) \
0033 { \
0034 split_free(ar, t, file_version); \
0035 }
0036
0037
0038
0039 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date)
0040 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_duration)
0041 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_duration::duration_rep)
0042 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_period)
0043 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_year)
0044 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_month)
0045 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_day)
0046 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_weekday)
0047 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::partial_date)
0048 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::nth_kday_of_month)
0049 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_of_month)
0050 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::last_kday_of_month)
0051 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_before)
0052 BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_after)
0053
0054 #undef BOOST_DATE_TIME_SPLIT_FREE
0055
0056
0057
0058
0059
0060
0061 template<class Archive>
0062 void save(Archive & ar,
0063 const ::boost::gregorian::date & d,
0064 unsigned int )
0065 {
0066 std::string ds = to_iso_string(d);
0067 ar & make_nvp("date", ds);
0068 }
0069
0070
0071
0072
0073
0074
0075 template<class Archive>
0076 void load(Archive & ar,
0077 ::boost::gregorian::date & d,
0078 unsigned int )
0079 {
0080 std::string ds;
0081 ar & make_nvp("date", ds);
0082 try{
0083 d = ::boost::gregorian::from_undelimited_string(ds);
0084 }catch(bad_lexical_cast&) {
0085 gregorian::special_values sv = gregorian::special_value_from_string(ds);
0086 if(sv == gregorian::not_special) {
0087 throw;
0088 }
0089 else {
0090 d = gregorian::date(sv);
0091 }
0092 }
0093 }
0094
0095
0096
0097 template<class Archive>
0098 inline void load_construct_data(Archive & ,
0099 ::boost::gregorian::date* dp,
0100 const unsigned int )
0101 {
0102
0103
0104 ::new(dp) ::boost::gregorian::date(::boost::gregorian::not_a_date_time);
0105 }
0106
0107
0108
0109
0110 template<class Archive>
0111 void save(Archive & ar, const gregorian::date_duration & dd,
0112 unsigned int )
0113 {
0114 typename gregorian::date_duration::duration_rep dr = dd.get_rep();
0115 ar & make_nvp("date_duration", dr);
0116 }
0117
0118 template<class Archive>
0119 void load(Archive & ar, gregorian::date_duration & dd, unsigned int )
0120 {
0121 typename gregorian::date_duration::duration_rep dr(0);
0122 ar & make_nvp("date_duration", dr);
0123 dd = gregorian::date_duration(dr);
0124 }
0125
0126 template<class Archive>
0127 inline void load_construct_data(Archive & , gregorian::date_duration* dd,
0128 const unsigned int )
0129 {
0130 ::new(dd) gregorian::date_duration(gregorian::not_a_date_time);
0131 }
0132
0133
0134
0135
0136 template<class Archive>
0137 void save(Archive & ar, const gregorian::date_duration::duration_rep & dr,
0138 unsigned int )
0139 {
0140 typename gregorian::date_duration::duration_rep::int_type it = dr.as_number();
0141 ar & make_nvp("date_duration_duration_rep", it);
0142 }
0143
0144 template<class Archive>
0145 void load(Archive & ar, gregorian::date_duration::duration_rep & dr, unsigned int )
0146 {
0147 typename gregorian::date_duration::duration_rep::int_type it(0);
0148 ar & make_nvp("date_duration_duration_rep", it);
0149 dr = gregorian::date_duration::duration_rep::int_type(it);
0150 }
0151
0152 template<class Archive>
0153 inline void load_construct_data(Archive & , gregorian::date_duration::duration_rep* dr,
0154 const unsigned int )
0155 {
0156 ::new(dr) gregorian::date_duration::duration_rep(0);
0157 }
0158
0159
0160
0161
0162
0163
0164
0165 template<class Archive>
0166 void save(Archive & ar, const gregorian::date_period& dp,
0167 unsigned int )
0168 {
0169 gregorian::date d1 = dp.begin();
0170 gregorian::date d2 = dp.end();
0171 ar & make_nvp("date_period_begin_date", d1);
0172 ar & make_nvp("date_period_end_date", d2);
0173 }
0174
0175
0176
0177
0178 template<class Archive>
0179 void load(Archive & ar, gregorian::date_period& dp, unsigned int )
0180 {
0181 gregorian::date d1(gregorian::not_a_date_time);
0182 gregorian::date d2(gregorian::not_a_date_time);
0183 ar & make_nvp("date_period_begin_date", d1);
0184 ar & make_nvp("date_period_end_date", d2);
0185 dp = gregorian::date_period(d1,d2);
0186 }
0187
0188 template<class Archive>
0189 inline void load_construct_data(Archive & , gregorian::date_period* dp,
0190 const unsigned int )
0191 {
0192 gregorian::date d(gregorian::not_a_date_time);
0193 gregorian::date_duration dd(1);
0194 ::new(dp) gregorian::date_period(d,dd);
0195 }
0196
0197
0198
0199
0200 template<class Archive>
0201 void save(Archive & ar, const gregorian::greg_year& gy,
0202 unsigned int )
0203 {
0204 unsigned short us = gy;
0205 ar & make_nvp("greg_year", us);
0206 }
0207
0208 template<class Archive>
0209 void load(Archive & ar, gregorian::greg_year& gy, unsigned int )
0210 {
0211 unsigned short us;
0212 ar & make_nvp("greg_year", us);
0213 gy = gregorian::greg_year(us);
0214 }
0215
0216 template<class Archive>
0217 inline void load_construct_data(Archive & , gregorian::greg_year* gy,
0218 const unsigned int )
0219 {
0220 ::new(gy) gregorian::greg_year(1900);
0221 }
0222
0223
0224
0225
0226 template<class Archive>
0227 void save(Archive & ar, const gregorian::greg_month& gm,
0228 unsigned int )
0229 {
0230 unsigned short us = gm.as_number();
0231 ar & make_nvp("greg_month", us);
0232 }
0233
0234 template<class Archive>
0235 void load(Archive & ar, gregorian::greg_month& gm, unsigned int )
0236 {
0237 unsigned short us;
0238 ar & make_nvp("greg_month", us);
0239 gm = gregorian::greg_month(us);
0240 }
0241
0242 template<class Archive>
0243 inline void load_construct_data(Archive & , gregorian::greg_month* gm,
0244 const unsigned int )
0245 {
0246 ::new(gm) gregorian::greg_month(1);
0247 }
0248
0249
0250
0251
0252 template<class Archive>
0253 void save(Archive & ar, const gregorian::greg_day& gd,
0254 unsigned int )
0255 {
0256 unsigned short us = gd.as_number();
0257 ar & make_nvp("greg_day", us);
0258 }
0259
0260 template<class Archive>
0261 void load(Archive & ar, gregorian::greg_day& gd, unsigned int )
0262 {
0263 unsigned short us;
0264 ar & make_nvp("greg_day", us);
0265 gd = gregorian::greg_day(us);
0266 }
0267
0268 template<class Archive>
0269 inline void load_construct_data(Archive & , gregorian::greg_day* gd,
0270 const unsigned int )
0271 {
0272 ::new(gd) gregorian::greg_day(1);
0273 }
0274
0275
0276
0277
0278 template<class Archive>
0279 void save(Archive & ar, const gregorian::greg_weekday& gd,
0280 unsigned int )
0281 {
0282 unsigned short us = gd.as_number();
0283 ar & make_nvp("greg_weekday", us);
0284 }
0285
0286 template<class Archive>
0287 void load(Archive & ar, gregorian::greg_weekday& gd, unsigned int )
0288 {
0289 unsigned short us;
0290 ar & make_nvp("greg_weekday", us);
0291 gd = gregorian::greg_weekday(us);
0292 }
0293
0294 template<class Archive>
0295 inline void load_construct_data(Archive & , gregorian::greg_weekday* gd,
0296 const unsigned int )
0297 {
0298 ::new(gd) gregorian::greg_weekday(1);
0299 }
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309 template<class Archive>
0310 void save(Archive & ar, const gregorian::partial_date& pd,
0311 unsigned int )
0312 {
0313 gregorian::greg_day gd(pd.day());
0314 gregorian::greg_month gm(pd.month().as_number());
0315 ar & make_nvp("partial_date_day", gd);
0316 ar & make_nvp("partial_date_month", gm);
0317 }
0318
0319
0320
0321
0322 template<class Archive>
0323 void load(Archive & ar, gregorian::partial_date& pd, unsigned int )
0324 {
0325 gregorian::greg_day gd(1);
0326 gregorian::greg_month gm(1);
0327 ar & make_nvp("partial_date_day", gd);
0328 ar & make_nvp("partial_date_month", gm);
0329 pd = gregorian::partial_date(gd,gm);
0330 }
0331
0332 template<class Archive>
0333 inline void load_construct_data(Archive & , gregorian::partial_date* pd,
0334 const unsigned int )
0335 {
0336 gregorian::greg_month gm(1);
0337 gregorian::greg_day gd(1);
0338 ::new(pd) gregorian::partial_date(gd,gm);
0339 }
0340
0341
0342
0343
0344
0345
0346
0347 template<class Archive>
0348 void save(Archive & ar, const gregorian::nth_kday_of_month& nkd,
0349 unsigned int )
0350 {
0351 typename gregorian::nth_kday_of_month::week_num wn(nkd.nth_week());
0352 typename gregorian::nth_kday_of_month::day_of_week_type d(nkd.day_of_week().as_number());
0353 typename gregorian::nth_kday_of_month::month_type m(nkd.month().as_number());
0354 ar & make_nvp("nth_kday_of_month_week_num", wn);
0355 ar & make_nvp("nth_kday_of_month_day_of_week", d);
0356 ar & make_nvp("nth_kday_of_month_month", m);
0357 }
0358
0359
0360
0361
0362 template<class Archive>
0363 void load(Archive & ar, gregorian::nth_kday_of_month& nkd, unsigned int )
0364 {
0365 typename gregorian::nth_kday_of_month::week_num wn(gregorian::nth_kday_of_month::first);
0366 typename gregorian::nth_kday_of_month::day_of_week_type d(gregorian::Monday);
0367 typename gregorian::nth_kday_of_month::month_type m(gregorian::Jan);
0368 ar & make_nvp("nth_kday_of_month_week_num", wn);
0369 ar & make_nvp("nth_kday_of_month_day_of_week", d);
0370 ar & make_nvp("nth_kday_of_month_month", m);
0371
0372 nkd = gregorian::nth_kday_of_month(wn,d,m);
0373 }
0374
0375 template<class Archive>
0376 inline void load_construct_data(Archive & ,
0377 gregorian::nth_kday_of_month* nkd,
0378 const unsigned int )
0379 {
0380
0381 ::new(nkd) gregorian::nth_kday_of_month(gregorian::nth_kday_of_month::first,
0382 gregorian::Monday,gregorian::Jan);
0383 }
0384
0385
0386
0387
0388
0389
0390
0391 template<class Archive>
0392 void save(Archive & ar, const gregorian::first_kday_of_month& fkd,
0393 unsigned int )
0394 {
0395 typename gregorian::first_kday_of_month::day_of_week_type d(fkd.day_of_week().as_number());
0396 typename gregorian::first_kday_of_month::month_type m(fkd.month().as_number());
0397 ar & make_nvp("first_kday_of_month_day_of_week", d);
0398 ar & make_nvp("first_kday_of_month_month", m);
0399 }
0400
0401
0402
0403
0404 template<class Archive>
0405 void load(Archive & ar, gregorian::first_kday_of_month& fkd, unsigned int )
0406 {
0407 typename gregorian::first_kday_of_month::day_of_week_type d(gregorian::Monday);
0408 typename gregorian::first_kday_of_month::month_type m(gregorian::Jan);
0409 ar & make_nvp("first_kday_of_month_day_of_week", d);
0410 ar & make_nvp("first_kday_of_month_month", m);
0411
0412 fkd = gregorian::first_kday_of_month(d,m);
0413 }
0414
0415 template<class Archive>
0416 inline void load_construct_data(Archive & ,
0417 gregorian::first_kday_of_month* fkd,
0418 const unsigned int )
0419 {
0420
0421 ::new(fkd) gregorian::first_kday_of_month(gregorian::Monday,gregorian::Jan);
0422 }
0423
0424
0425
0426
0427
0428
0429
0430 template<class Archive>
0431 void save(Archive & ar, const gregorian::last_kday_of_month& lkd,
0432 unsigned int )
0433 {
0434 typename gregorian::last_kday_of_month::day_of_week_type d(lkd.day_of_week().as_number());
0435 typename gregorian::last_kday_of_month::month_type m(lkd.month().as_number());
0436 ar & make_nvp("last_kday_of_month_day_of_week", d);
0437 ar & make_nvp("last_kday_of_month_month", m);
0438 }
0439
0440
0441
0442
0443 template<class Archive>
0444 void load(Archive & ar, gregorian::last_kday_of_month& lkd, unsigned int )
0445 {
0446 typename gregorian::last_kday_of_month::day_of_week_type d(gregorian::Monday);
0447 typename gregorian::last_kday_of_month::month_type m(gregorian::Jan);
0448 ar & make_nvp("last_kday_of_month_day_of_week", d);
0449 ar & make_nvp("last_kday_of_month_month", m);
0450
0451 lkd = gregorian::last_kday_of_month(d,m);
0452 }
0453
0454 template<class Archive>
0455 inline void load_construct_data(Archive & ,
0456 gregorian::last_kday_of_month* lkd,
0457 const unsigned int )
0458 {
0459
0460 ::new(lkd) gregorian::last_kday_of_month(gregorian::Monday,gregorian::Jan);
0461 }
0462
0463
0464
0465
0466 template<class Archive>
0467 void save(Archive & ar, const gregorian::first_kday_before& fkdb,
0468 unsigned int )
0469 {
0470 typename gregorian::first_kday_before::day_of_week_type d(fkdb.day_of_week().as_number());
0471 ar & make_nvp("first_kday_before_day_of_week", d);
0472 }
0473
0474 template<class Archive>
0475 void load(Archive & ar, gregorian::first_kday_before& fkdb, unsigned int )
0476 {
0477 typename gregorian::first_kday_before::day_of_week_type d(gregorian::Monday);
0478 ar & make_nvp("first_kday_before_day_of_week", d);
0479
0480 fkdb = gregorian::first_kday_before(d);
0481 }
0482
0483 template<class Archive>
0484 inline void load_construct_data(Archive & ,
0485 gregorian::first_kday_before* fkdb,
0486 const unsigned int )
0487 {
0488
0489 ::new(fkdb) gregorian::first_kday_before(gregorian::Monday);
0490 }
0491
0492
0493
0494
0495 template<class Archive>
0496 void save(Archive & ar, const gregorian::first_kday_after& fkda,
0497 unsigned int )
0498 {
0499 typename gregorian::first_kday_after::day_of_week_type d(fkda.day_of_week().as_number());
0500 ar & make_nvp("first_kday_after_day_of_week", d);
0501 }
0502
0503 template<class Archive>
0504 void load(Archive & ar, gregorian::first_kday_after& fkda, unsigned int )
0505 {
0506 typename gregorian::first_kday_after::day_of_week_type d(gregorian::Monday);
0507 ar & make_nvp("first_kday_after_day_of_week", d);
0508
0509 fkda = gregorian::first_kday_after(d);
0510 }
0511
0512 template<class Archive>
0513 inline void load_construct_data(Archive & ,
0514 gregorian::first_kday_after* fkda,
0515 const unsigned int )
0516 {
0517
0518 ::new(fkda) gregorian::first_kday_after(gregorian::Monday);
0519 }
0520
0521 }
0522 }
0523
0524 #endif