1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef __ASIO2_CONNECT_TIME_COMPONENT_HPP__
- #define __ASIO2_CONNECT_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 connect_time_cp
- {
- public:
-
- connect_time_cp() = default;
-
- ~connect_time_cp() = default;
- connect_time_cp(connect_time_cp&&) noexcept = default;
- connect_time_cp(connect_time_cp const&) = default;
- connect_time_cp& operator=(connect_time_cp&&) noexcept = default;
- connect_time_cp& operator=(connect_time_cp const&) = default;
- public:
-
- inline std::chrono::time_point<std::chrono::system_clock> get_connect_time() const noexcept
- {
- return this->connect_time_;
- }
-
- inline derived_t & reset_connect_time() noexcept
- {
- this->connect_time_ = std::chrono::system_clock::now();
- return (static_cast<derived_t &>(*this));
- }
-
- inline std::chrono::system_clock::duration get_connect_duration() const noexcept
- {
- return std::chrono::duration_cast<std::chrono::system_clock::duration>(
- std::chrono::system_clock::now() - this->connect_time_);
- }
- protected:
-
- decltype(std::chrono::system_clock::now()) connect_time_ = std::chrono::system_clock::now();
- };
- }
- #endif
|