forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add boost::date_time & boost::interprocess for dynet
- Loading branch information
Showing
276 changed files
with
62,427 additions
and
0 deletions.
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
thirdparty/boost/include/boost/date_time/adjust_functors.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
#ifndef _DATE_TIME_ADJUST_FUNCTORS_HPP___ | ||
#define _DATE_TIME_ADJUST_FUNCTORS_HPP___ | ||
|
||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc. | ||
* Use, modification and distribution is subject to the | ||
* Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | ||
* Author: Jeff Garland, Bart Garst | ||
* $Date$ | ||
*/ | ||
|
||
#include "boost/date_time/date.hpp" | ||
#include "boost/date_time/wrapping_int.hpp" | ||
|
||
namespace boost { | ||
namespace date_time { | ||
|
||
|
||
//! Functor to iterate a fixed number of days | ||
template<class date_type> | ||
class day_functor | ||
{ | ||
public: | ||
typedef typename date_type::duration_type duration_type; | ||
day_functor(int f) : f_(f) {} | ||
duration_type get_offset(const date_type& d) const | ||
{ | ||
// why is 'd' a parameter??? | ||
// fix compiler warnings | ||
d.year(); | ||
return duration_type(f_); | ||
} | ||
duration_type get_neg_offset(const date_type& d) const | ||
{ | ||
// fix compiler warnings | ||
d.year(); | ||
return duration_type(-f_); | ||
} | ||
private: | ||
int f_; | ||
}; | ||
|
||
|
||
//! Provides calculation to find next nth month given a date | ||
/*! This adjustment function provides the logic for 'month-based' | ||
* advancement on a ymd based calendar. The policy it uses | ||
* to handle the non existant end of month days is to back | ||
* up to the last day of the month. Also, if the starting | ||
* date is the last day of a month, this functor will attempt | ||
* to adjust to the end of the month. | ||
*/ | ||
template<class date_type> | ||
class month_functor | ||
{ | ||
public: | ||
typedef typename date_type::duration_type duration_type; | ||
typedef typename date_type::calendar_type cal_type; | ||
typedef typename cal_type::ymd_type ymd_type; | ||
typedef typename cal_type::day_type day_type; | ||
|
||
month_functor(int f) : f_(f), origDayOfMonth_(0) {} | ||
duration_type get_offset(const date_type& d) const | ||
{ | ||
ymd_type ymd(d.year_month_day()); | ||
if (origDayOfMonth_ == 0) { | ||
origDayOfMonth_ = ymd.day; | ||
day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); | ||
if (endOfMonthDay == ymd.day) { | ||
origDayOfMonth_ = -1; //force the value to the end of month | ||
} | ||
} | ||
typedef date_time::wrapping_int2<short,1,12> wrap_int2; | ||
typedef typename wrap_int2::int_type int_type; | ||
wrap_int2 wi(ymd.month); | ||
//calc the year wrap around, add() returns 0 or 1 if wrapped | ||
int_type year = wi.add(static_cast<int_type>(f_)); | ||
year = static_cast<int_type>(year + ymd.year); //calculate resulting year | ||
// std::cout << "trace wi: " << wi.as_int() << std::endl; | ||
// std::cout << "trace year: " << year << std::endl; | ||
//find the last day for the new month | ||
day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); | ||
//original was the end of month -- force to last day of month | ||
if (origDayOfMonth_ == -1) { | ||
return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; | ||
} | ||
day_type dayOfMonth = origDayOfMonth_; | ||
if (dayOfMonth > resultingEndOfMonthDay) { | ||
dayOfMonth = resultingEndOfMonthDay; | ||
} | ||
return date_type(year, wi.as_int(), dayOfMonth) - d; | ||
} | ||
//! Returns a negative duration_type | ||
duration_type get_neg_offset(const date_type& d) const | ||
{ | ||
ymd_type ymd(d.year_month_day()); | ||
if (origDayOfMonth_ == 0) { | ||
origDayOfMonth_ = ymd.day; | ||
day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); | ||
if (endOfMonthDay == ymd.day) { | ||
origDayOfMonth_ = -1; //force the value to the end of month | ||
} | ||
} | ||
typedef date_time::wrapping_int2<short,1,12> wrap_int2; | ||
typedef typename wrap_int2::int_type int_type; | ||
wrap_int2 wi(ymd.month); | ||
//calc the year wrap around, add() returns 0 or 1 if wrapped | ||
int_type year = wi.subtract(static_cast<int_type>(f_)); | ||
year = static_cast<int_type>(year + ymd.year); //calculate resulting year | ||
//find the last day for the new month | ||
day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); | ||
//original was the end of month -- force to last day of month | ||
if (origDayOfMonth_ == -1) { | ||
return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; | ||
} | ||
day_type dayOfMonth = origDayOfMonth_; | ||
if (dayOfMonth > resultingEndOfMonthDay) { | ||
dayOfMonth = resultingEndOfMonthDay; | ||
} | ||
return date_type(year, wi.as_int(), dayOfMonth) - d; | ||
} | ||
private: | ||
int f_; | ||
mutable short origDayOfMonth_; | ||
}; | ||
|
||
|
||
//! Functor to iterate a over weeks | ||
template<class date_type> | ||
class week_functor | ||
{ | ||
public: | ||
typedef typename date_type::duration_type duration_type; | ||
typedef typename date_type::calendar_type calendar_type; | ||
week_functor(int f) : f_(f) {} | ||
duration_type get_offset(const date_type& d) const | ||
{ | ||
// why is 'd' a parameter??? | ||
// fix compiler warnings | ||
d.year(); | ||
return duration_type(f_*calendar_type::days_in_week()); | ||
} | ||
duration_type get_neg_offset(const date_type& d) const | ||
{ | ||
// fix compiler warnings | ||
d.year(); | ||
return duration_type(-f_*calendar_type::days_in_week()); | ||
} | ||
private: | ||
int f_; | ||
}; | ||
|
||
//! Functor to iterate by a year adjusting for leap years | ||
template<class date_type> | ||
class year_functor | ||
{ | ||
public: | ||
//typedef typename date_type::year_type year_type; | ||
typedef typename date_type::duration_type duration_type; | ||
year_functor(int f) : _mf(f * 12) {} | ||
duration_type get_offset(const date_type& d) const | ||
{ | ||
return _mf.get_offset(d); | ||
} | ||
duration_type get_neg_offset(const date_type& d) const | ||
{ | ||
return _mf.get_neg_offset(d); | ||
} | ||
private: | ||
month_functor<date_type> _mf; | ||
}; | ||
|
||
|
||
} }//namespace date_time | ||
|
||
|
||
#endif | ||
|
69 changes: 69 additions & 0 deletions
69
thirdparty/boost/include/boost/date_time/c_local_time_adjustor.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifndef DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ | ||
#define DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ | ||
|
||
/* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. | ||
* Use, modification and distribution is subject to the | ||
* Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | ||
* Author: Jeff Garland, Bart Garst | ||
* $Date$ | ||
*/ | ||
|
||
/*! @file c_local_time_adjustor.hpp | ||
Time adjustment calculations based on machine | ||
*/ | ||
|
||
#include <stdexcept> | ||
#include <boost/throw_exception.hpp> | ||
#include <boost/date_time/compiler_config.hpp> | ||
#include <boost/date_time/c_time.hpp> | ||
|
||
namespace boost { | ||
namespace date_time { | ||
|
||
//! Adjust to / from utc using the C API | ||
/*! Warning!!! This class assumes that timezone settings of the | ||
* machine are correct. This can be a very dangerous assumption. | ||
*/ | ||
template<class time_type> | ||
class c_local_adjustor { | ||
public: | ||
typedef typename time_type::time_duration_type time_duration_type; | ||
typedef typename time_type::date_type date_type; | ||
typedef typename date_type::duration_type date_duration_type; | ||
//! Convert a utc time to local time | ||
static time_type utc_to_local(const time_type& t) | ||
{ | ||
date_type time_t_start_day(1970,1,1); | ||
time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0)); | ||
if (t < time_t_start_time) { | ||
boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970")); | ||
BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach | ||
} | ||
date_duration_type dd = t.date() - time_t_start_day; | ||
time_duration_type td = t.time_of_day(); | ||
std::time_t t2 = static_cast<std::time_t>(dd.days())*86400 + | ||
static_cast<std::time_t>(td.hours())*3600 + | ||
static_cast<std::time_t>(td.minutes())*60 + | ||
td.seconds(); | ||
std::tm tms, *tms_ptr; | ||
tms_ptr = c_time::localtime(&t2, &tms); | ||
date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900), | ||
static_cast<unsigned short>(tms_ptr->tm_mon + 1), | ||
static_cast<unsigned short>(tms_ptr->tm_mday)); | ||
time_duration_type td2(tms_ptr->tm_hour, | ||
tms_ptr->tm_min, | ||
tms_ptr->tm_sec, | ||
t.time_of_day().fractional_seconds()); | ||
|
||
return time_type(d,td2); | ||
} | ||
}; | ||
|
||
|
||
|
||
} } //namespace date_time | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#ifndef DATE_TIME_C_TIME_HPP___ | ||
#define DATE_TIME_C_TIME_HPP___ | ||
|
||
/* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. | ||
* Use, modification and distribution is subject to the | ||
* Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | ||
* Author: Jeff Garland, Bart Garst | ||
* $Date$ | ||
*/ | ||
|
||
|
||
/*! @file c_time.hpp | ||
Provide workarounds related to the ctime header | ||
*/ | ||
|
||
#include <ctime> | ||
#include <string> // to be able to convert from string literals to exceptions | ||
#include <stdexcept> | ||
#include <boost/throw_exception.hpp> | ||
#include <boost/date_time/compiler_config.hpp> | ||
|
||
//Work around libraries that don't put time_t and time in namespace std | ||
#ifdef BOOST_NO_STDC_NAMESPACE | ||
namespace std { using ::time_t; using ::time; using ::localtime; | ||
using ::tm; using ::gmtime; } | ||
#endif // BOOST_NO_STDC_NAMESPACE | ||
|
||
//The following is used to support high precision time clocks | ||
#ifdef BOOST_HAS_GETTIMEOFDAY | ||
#include <sys/time.h> | ||
#endif | ||
|
||
#ifdef BOOST_HAS_FTIME | ||
#include <time.h> | ||
#endif | ||
|
||
namespace boost { | ||
namespace date_time { | ||
//! Provides a uniform interface to some 'ctime' functions | ||
/*! Provides a uniform interface to some ctime functions and | ||
* their '_r' counterparts. The '_r' functions require a pointer to a | ||
* user created std::tm struct whereas the regular functions use a | ||
* staticly created struct and return a pointer to that. These wrapper | ||
* functions require the user to create a std::tm struct and send in a | ||
* pointer to it. This struct may be used to store the resulting time. | ||
* The returned pointer may or may not point to this struct, however, | ||
* it will point to the result of the corresponding function. | ||
* All functions do proper checking of the C function results and throw | ||
* exceptions on error. Therefore the functions will never return NULL. | ||
*/ | ||
struct c_time { | ||
public: | ||
#if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS) | ||
//! requires a pointer to a user created std::tm struct | ||
inline | ||
static std::tm* localtime(const std::time_t* t, std::tm* result) | ||
{ | ||
// localtime_r() not in namespace std??? | ||
#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64 | ||
std::tm tmp; | ||
if(!localtime_r(t,&tmp)) | ||
result = 0; | ||
else | ||
*result = tmp; | ||
#else | ||
result = localtime_r(t, result); | ||
#endif | ||
if (!result) | ||
boost::throw_exception(std::runtime_error("could not convert calendar time to local time")); | ||
return result; | ||
} | ||
//! requires a pointer to a user created std::tm struct | ||
inline | ||
static std::tm* gmtime(const std::time_t* t, std::tm* result) | ||
{ | ||
// gmtime_r() not in namespace std??? | ||
#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64 | ||
std::tm tmp; | ||
if(!gmtime_r(t,&tmp)) | ||
result = 0; | ||
else | ||
*result = tmp; | ||
#else | ||
result = gmtime_r(t, result); | ||
#endif | ||
if (!result) | ||
boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time")); | ||
return result; | ||
} | ||
#else // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS | ||
|
||
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) | ||
#pragma warning(push) // preserve warning settings | ||
#pragma warning(disable : 4996) // disable depricated localtime/gmtime warning on vc8 | ||
#endif // _MSC_VER >= 1400 | ||
//! requires a pointer to a user created std::tm struct | ||
inline | ||
static std::tm* localtime(const std::time_t* t, std::tm* result) | ||
{ | ||
result = std::localtime(t); | ||
if (!result) | ||
boost::throw_exception(std::runtime_error("could not convert calendar time to local time")); | ||
return result; | ||
} | ||
//! requires a pointer to a user created std::tm struct | ||
inline | ||
static std::tm* gmtime(const std::time_t* t, std::tm* result) | ||
{ | ||
result = std::gmtime(t); | ||
if (!result) | ||
boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time")); | ||
return result; | ||
} | ||
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) | ||
#pragma warning(pop) // restore warnings to previous state | ||
#endif // _MSC_VER >= 1400 | ||
|
||
#endif // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS | ||
}; | ||
}} // namespaces | ||
|
||
#endif // DATE_TIME_C_TIME_HPP___ |
Oops, something went wrong.