diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2015-11-25 13:30:32 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2015-11-27 17:47:02 +0200 |
commit | 31fd2822f516337f084f85db7e369d0633113b73 (patch) | |
tree | 9ad07f1bc0b3924f225ecfc628955bbd683e1d99 /include | |
parent | 4475f5486000bab8f1121f5cec6091bc04f165f1 (diff) | |
download | qtlocation-mapboxgl-31fd2822f516337f084f85db7e369d0633113b73.tar.gz |
[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.
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/storage/response.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/util/chrono.hpp | 31 |
2 files changed, 35 insertions, 2 deletions
diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp index 8ab6170ba2..852110cb2a 100644 --- a/include/mbgl/storage/response.hpp +++ b/include/mbgl/storage/response.hpp @@ -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; }; diff --git a/include/mbgl/util/chrono.hpp b/include/mbgl/util/chrono.hpp index df8c5e6234..9c99c7bcdf 100644 --- a/include/mbgl/util/chrono.hpp +++ b/include/mbgl/util/chrono.hpp @@ -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 |