12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #ifndef __ASIO2_ALIVE_TIME_COMPONENT_HPP__
- #define __ASIO2_ALIVE_TIME_COMPONENT_HPP__
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- #pragma once
- #endif
- #include <chrono>
- namespace asio2::detail
- {
- template<class derived_t, class args_t>
- class alive_time_cp
- {
- public:
-
- alive_time_cp() = default;
-
- ~alive_time_cp() = default;
- alive_time_cp(alive_time_cp&&) noexcept = default;
- alive_time_cp(alive_time_cp const&) = default;
- alive_time_cp& operator=(alive_time_cp&&) noexcept = default;
- alive_time_cp& operator=(alive_time_cp const&) = default;
- public:
-
- inline std::chrono::time_point<std::chrono::system_clock> last_alive_time() const noexcept
- {
- return this->get_last_alive_time();
- }
-
- inline std::chrono::time_point<std::chrono::system_clock> get_last_alive_time() const noexcept
- {
- return this->last_alive_time_;
- }
-
- inline derived_t & update_alive_time() noexcept
- {
- this->last_alive_time_ = std::chrono::system_clock::now();
- return (static_cast<derived_t &>(*this));
- }
-
- inline std::chrono::system_clock::duration get_silence_duration() const noexcept
- {
- return std::chrono::duration_cast<std::chrono::system_clock::duration>(
- std::chrono::system_clock::now() - this->last_alive_time_);
- }
- protected:
-
- decltype(std::chrono::system_clock::now()) last_alive_time_ = std::chrono::system_clock::now();
- };
- }
- #endif
|