[core] Replace time_t with std::chrono::seconds
Added aliases for std::chrono typedefs (eg. 'Seconds' for std::chrono::seconds). These aliases are used together with templated helper functions to replace time_t with std::chrono::seconds for most cases, in particular for 'modified' and 'expires' values in Response.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef MBGL_STORAGE_RESPONSE
|
||||
#define MBGL_STORAGE_RESPONSE
|
||||
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
@@ -25,8 +27,8 @@ public:
|
||||
// The actual data of the response. This is guaranteed to never be empty.
|
||||
std::shared_ptr<const std::string> data;
|
||||
|
||||
int64_t modified = 0;
|
||||
int64_t expires = 0;
|
||||
Seconds modified = Seconds::zero();
|
||||
Seconds expires = Seconds::zero();
|
||||
std::string etag;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,9 +8,40 @@ namespace mbgl {
|
||||
using Clock = std::chrono::steady_clock;
|
||||
using SystemClock = std::chrono::system_clock;
|
||||
|
||||
using Seconds = std::chrono::seconds;
|
||||
using Milliseconds = std::chrono::milliseconds;
|
||||
|
||||
using TimePoint = Clock::time_point;
|
||||
using Duration = Clock::duration;
|
||||
|
||||
using SystemTimePoint = SystemClock::time_point;
|
||||
using SystemDuration = SystemClock::duration;
|
||||
|
||||
template <class _Clock, class _Duration>
|
||||
_Duration toDuration(std::chrono::time_point<_Clock, _Duration> time_point) {
|
||||
return time_point.time_since_epoch();
|
||||
}
|
||||
|
||||
template <class _Duration>
|
||||
Seconds asSeconds(_Duration duration) {
|
||||
return std::chrono::duration_cast<Seconds>(duration);
|
||||
}
|
||||
|
||||
template <class _Clock, class _Duration>
|
||||
Seconds toSeconds(std::chrono::time_point<_Clock, _Duration> time_point) {
|
||||
return asSeconds(toDuration<_Clock, _Duration>(time_point));
|
||||
}
|
||||
|
||||
template <class _Duration>
|
||||
Milliseconds asMilliseconds(_Duration duration) {
|
||||
return std::chrono::duration_cast<Milliseconds>(duration);
|
||||
}
|
||||
|
||||
template <class _Clock, class _Duration>
|
||||
Milliseconds toMilliseconds(std::chrono::time_point<_Clock, _Duration> time_point) {
|
||||
return asMilliseconds(toDuration<_Clock, _Duration>(time_point));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user