本文整理汇总了C++中milliseconds类的典型用法代码示例。如果您正苦于以下问题:C++ milliseconds类的具体用法?C++ milliseconds怎么用?C++ milliseconds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了milliseconds类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadImage
Image ReadImage(tjhandle tj, int width, int height, int quality = 75) {
static std::vector< char > img;
static int count = 0;
img.resize(3 * width * height);
glReadBuffer(GL_FRONT);
#ifdef TIME_READPIXEL
using namespace std::chrono;
steady_clock::time_point t = steady_clock::now();
#endif
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &img[0]);
#ifdef TIME_READPIXEL
const milliseconds E =
duration_cast< milliseconds >(steady_clock::now() - t);
cout << E.count() << ' '; //doesn't flush, prints after closing window
#endif
char* out = nullptr;
unsigned long size = 0;
tjCompress2(tj,
(unsigned char*) &img[0],
width,
3 * width,
height,
TJPF_RGB,
(unsigned char **) &out,
&size,
TJSAMP_444,
quality,
0);
return Image(ImagePtr((char*) out, TJDeleter()), size, count++);
}
示例2: addFunctionUniformDistribution
void FunctionScheduler::addFunctionUniformDistribution(
Function<void()>&& cb,
milliseconds minInterval,
milliseconds maxInterval,
StringPiece nameID,
milliseconds startDelay) {
addFunctionGenericDistribution(
std::move(cb),
UniformDistributionFunctor(minInterval, maxInterval),
nameID.str(),
to<std::string>(
"[", minInterval.count(), " , ", maxInterval.count(), "] ms"),
startDelay);
}
示例3: set_timeout
void SocketImpl::set_timeout( const milliseconds& value )
{
tcp::socket::native_handle_type native_socket(0);
#ifdef BUILD_SSL
if ( m_socket not_eq nullptr )
{
#endif
native_socket = m_socket->native_handle( );
#ifdef BUILD_SSL
}
else
{
native_socket = m_ssl_socket->lowest_layer( ).native_handle( );
}
#endif
struct timeval timeout = { 0, 0 };
timeout.tv_usec = static_cast< long >( value.count( ) * 1000 );
int status = setsockopt( native_socket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) );
if ( status == -1 and m_logger not_eq nullptr )
{
m_logger->log( Logger::Level::WARNING, "Failed to set socket option, send timeout." );
}
status = setsockopt( native_socket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) );
if ( status == -1 and m_logger not_eq nullptr )
{
m_logger->log( Logger::Level::WARNING, "Failed to set socket option, receive timeout." );
}
}
示例4: addFunction
void FunctionScheduler::addFunction(Function<void()>&& cb,
milliseconds interval,
StringPiece nameID,
milliseconds startDelay) {
addFunctionGenericDistribution(
std::move(cb),
ConstIntervalFunctor(interval),
nameID.str(),
to<std::string>(interval.count(), "ms"),
startDelay);
}
示例5: mLogger
log_entry::log_entry(logger& l, logger::LogLevel level):
mLogger(l),
mLevel(level)
{
if(mLevel < 0) return;
using namespace std::chrono;
const milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
const seconds s = duration_cast<seconds>(ms);
const std::time_t t = s.count();
const std::size_t fractional_seconds = ms.count() % 1000;
mLogger.lock();
const char timeFormat[] = "%Y-%m-%d %H:%M:%S";
const size_t buffSize = 100;
char buff[buffSize];
if(0 != std::strftime(buff, buffSize, timeFormat, std::localtime(&t)))
{
mLogger.get() << buff;
}
else
{
size_t dBuffSize = buffSize;
std::unique_ptr<char[]> dbuff;
do
{
dBuffSize *= 2;
dbuff.reset(new char[dBuffSize]);
}
while(0 == std::strftime(dbuff.get(), dBuffSize, timeFormat, std::localtime(&t)));
mLogger.get() << dbuff.get();
}
mLogger.get() << '.' << fractional_seconds << " ";
if(level >= 0 && level <= logger::logDEBUG)
{
const char* levels[] = {"ERROR","WARNING","INFO","DEBUG"};
mLogger.get() << levels[level];
}
mLogger.get() << ": ";
}
示例6: dist
bool
WeightedLoadBalancerStrategy::mySendInterest(const Interest& interest,
shared_ptr<MyMeasurementInfo>& measurementsEntryInfo,
shared_ptr<pit::Entry>& pitEntry)
{
typedef MyMeasurementInfo::WeightedFaceSetByDelay WeightedFaceSetByDelay;
const WeightedFaceSetByDelay& facesByDelay =
measurementsEntryInfo->weightedFaces.get<MyMeasurementInfo::ByDelay>();
const milliseconds totalDelay = measurementsEntryInfo->totalDelay;
const milliseconds inverseTotalDelay =
MyMeasurementInfo::calculateInverseDelaySum(measurementsEntryInfo);
boost::random::uniform_int_distribution<> dist(0, inverseTotalDelay.count());
const uint64_t selection = dist(m_randomGenerator);
NFD_LOG_TRACE("selection = " << selection);
uint64_t cumulativeWeight = 0;
for (WeightedFaceSetByDelay::const_iterator i = facesByDelay.begin();
i != facesByDelay.end();
++i)
{
NFD_LOG_TRACE("cumulative weight = " << cumulativeWeight);
// weight = inverted delay measurement
const uint64_t weight = totalDelay.count() - i->lastDelay.count();
cumulativeWeight += weight;
if(selection <= cumulativeWeight && pitEntry->canForwardTo(i->face))
{
NFD_LOG_TRACE("fowarding " << interest.getName() << " out face " << i->face.getId());
this->sendInterest(pitEntry, this->getFace(i->face.getId()));
return true;
}
}
return false;
}
示例7: ReadImage
Image ReadImage(int width, int height,
float quality = 100) {
static std::vector< char > img;
static int count = 0;
img.resize(3 * width * height);
glReadBuffer(GL_FRONT);
#ifdef TIME_READPIXEL
using namespace std::chrono;
steady_clock::time_point t = steady_clock::now();
#endif
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &img[0]);
#ifdef TIME_READPIXEL
const milliseconds E =
duration_cast< milliseconds >(steady_clock::now() - t);
cout << E.count() << ' '; //doesn't flush, prints after closing window
#endif
uint8_t* out;
const size_t size =
WebPEncodeRGB((uint8_t*) &img[0], width, height, 3 * width,
quality, &out);
return Image(ImagePtr((char*) out, WebpDeleter()), size, count++);
}
示例8: update
void Transition::update(milliseconds elapsed)
{
switch (state_)
{
case State::empty:
case State::full:
return;
case State::increase:
progress_ += static_cast<float>(elapsed.count()) / time_to_complete_.count();
if (progress_ >= 1.0f) {
progress_ = 1.0f;
state_ = State::full;
}
break;
case State::decrease:
progress_ -= static_cast<float>(elapsed.count()) / time_to_complete_.count();
if (progress_ <= 0.0f) {
progress_ = 0.0f;
state_ = State::empty;
}
break;
}
}
示例9: interval
void AppState::initTimerEngine() {
const milliseconds interval(1);
const milliseconds dueTime(0);
//创建定时器,无属性,自动复位,匿名
HANDLE handle = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -(nanoseconds(dueTime).count() / 100);
if (!SetWaitableTimer(handle, &liDueTime, interval.count(), NULL, NULL, FALSE)) {
throw std::runtime_error("dispatcherTimerEngine init error!");
}
DispatcherTimerEngine& engine = DispatcherTimerEngine::instance();
engine.setInterval(interval);
engine.start(dueTime);
//添加等待对象,以及触发事件
addEventHandle(handle, std::bind(&DispatcherTimerEngine::update, &engine));
}
示例10: output
void SimpleThinkingWriter::output(const ChessBoard& board,
const SearchResult& result,
const vector<Move>& main_variation,
const int nodes,
const milliseconds& time,
const Searcher::depth_t depth)
{
if (!post()) {
return;
}
ostringstream oss;
int turn_number = board.turn_number();
int ply = 0;
if (board.turn_color() == Color::Black) {
oss << turn_number << ". ... ";
++turn_number;
++ply;
}
for (const Move move : main_variation) {
if (ply % 2 == 0) {
oss << " " << turn_number << ".";
++turn_number;
}
oss << " " << move.source() << move.destination();
if (move.is_promotion()) {
oss << PieceSet::instance().piece(move.created_piece()).symbol(Color::Black);
}
++ply;
}
const int score = board.turn_color() == Color::White ? result.score : -result.score;
m_writer->thinking_output(depth,
score,
time.count() / 10,
nodes,
oss.str());
} // namespace olaf
示例11: set_resend_interval
void set_resend_interval(socket &s, milliseconds i)
{ s.setopt(REQ, REQ_RESEND_IVL, static_cast<int>(i.count())); }
示例12: AppState
//.........这里部分代码省略.........
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void AppState::initWindow() {
const wchar_t WINDOW_CLASS_NAME[] = L"Sample Window Class";
WNDCLASSW wc = { };
wc.lpfnWndProc = windowProc;
wc.hInstance = hInstance_;
wc.lpszClassName = WINDOW_CLASS_NAME;
if (!RegisterClassW(&wc)) {
throw std::runtime_error("RegisterClassW error!");
}
windowHwnd = CreateWindowExW(
0, // Optional window styles.
WINDOW_CLASS_NAME, // Window class
L"dddd", //Window Title
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, // Parent window
NULL, // Menu
hInstance_, // Instance handle
NULL // Additional application data
);
if (!windowHwnd) {
throw std::runtime_error("CreateWindowExW error!");
}
}
void AppState::initTimerEngine() {
const milliseconds interval(1);
const milliseconds dueTime(0);
//创建定时器,无属性,自动复位,匿名
HANDLE handle = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -(nanoseconds(dueTime).count() / 100);
if (!SetWaitableTimer(handle, &liDueTime, interval.count(), NULL, NULL, FALSE)) {
throw std::runtime_error("dispatcherTimerEngine init error!");
}
DispatcherTimerEngine& engine = DispatcherTimerEngine::instance();
engine.setInterval(interval);
engine.start(dueTime);
//添加等待对象,以及触发事件
addEventHandle(handle, std::bind(&DispatcherTimerEngine::update, &engine));
}
void AppState::initInputDevices() {
//创建DirectInput8对象
IDirectInput8A* direct_input;
dx::throwIfFailed(
DirectInput8Create(
hInstance_,
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void **) &direct_input,
nullptr)
);
direct_input_.reset(direct_input);
示例13: sleep_for
void sleep_for(milliseconds d) {
// usleep is nanoseconds.
usleep (d.count() * 1000);
}
示例14:
Timer::Timer(milliseconds expiration_time, bool start_active) :
current_time_{ start_active ? 0 : expiration_time.count() + 1},
expiration_time_{expiration_time}
{
timers_.insert(this);
}
示例15: onTimer
void PoolingAcceptor::onTimer(const milliseconds& delta) {
LOG(INFO)<< "[" << __FUNCTION__ << "] " << delta.count();
}