time: more inline implementation into the header

This commit is contained in:
Danny Robson 2017-12-30 13:38:11 +11:00
parent f2fa90d043
commit 59b21e67dd
3 changed files with 20 additions and 39 deletions

View File

@ -400,7 +400,6 @@ list (
term.hpp term.hpp
time.cpp time.cpp
time.hpp time.hpp
time.ipp
tuple.cpp tuple.cpp
tuple.hpp tuple.hpp
typeidx.cpp typeidx.cpp

View File

@ -25,15 +25,24 @@
namespace util { namespace util {
// ------------------------------------------------------------------------ ///////////////////////////////////////////////////////////////////////////
uintmax_t nanoseconds (void); uintmax_t nanoseconds (void);
template <typename T>
void sleep (std::chrono::duration<T,std::nano>);
//-------------------------------------------------------------------------
template <typename T>
void sleep (std::chrono::duration<T,std::nano> dt)
{
auto nano = std::chrono::duration_cast<std::chrono::nanoseconds> (dt);
sleep (nano.count ());
}
//-------------------------------------------------------------------------
void sleep (uint64_t ns); void sleep (uint64_t ns);
// ------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
class delta_clock { class delta_clock {
public: public:
delta_clock (); delta_clock ();
@ -46,7 +55,8 @@ namespace util {
} time; } time;
}; };
// ------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
class period_query { class period_query {
public: public:
explicit period_query (float seconds); explicit period_query (float seconds);
@ -60,7 +70,8 @@ namespace util {
} m_time; } m_time;
}; };
// ------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
class rate_limiter { class rate_limiter {
public: public:
explicit rate_limiter (unsigned rate); explicit rate_limiter (unsigned rate);
@ -72,7 +83,8 @@ namespace util {
unsigned m_target; unsigned m_target;
}; };
// ------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
class polled_duration { class polled_duration {
public: public:
polled_duration (std::string name, uint64_t interval); polled_duration (std::string name, uint64_t interval);
@ -90,6 +102,4 @@ namespace util {
}; };
} }
#include "time.ipp" #endif
#endif // __UTIL_TIME_HPP

View File

@ -1,28 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2016 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_TIME_IPP
#define __UTIL_TIME_IPP
template <typename T>
void
util::sleep (std::chrono::duration<T,std::nano> dt)
{
auto nano = std::chrono::duration_cast<std::chrono::nanoseconds> (dt);
sleep (nano.count ());
}
#endif