Blender V4.3
time.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __UTIL_TIME_H__
6#define __UTIL_TIME_H__
7
8#include "util/function.h"
9#include "util/string.h"
10
12
13/* Give current time in seconds in double precision, with good accuracy. */
14
15double time_dt();
16
17/* Sleep for the specified number of seconds. */
18
19void time_sleep(double t);
20
21/* Scoped timer. */
22
24 public:
25 explicit scoped_timer(double *value = NULL) : value_(value)
26 {
28 }
29
31 {
32 if (value_ != NULL) {
33 *value_ = get_time();
34 }
35 }
36
37 double get_start() const
38 {
39 return time_start_;
40 }
41
42 double get_time() const
43 {
44 return time_dt() - time_start_;
45 }
46
47 protected:
48 double *value_;
50};
51
53 public:
54 using callback_type = function<void(double)>;
55
57
59 {
60 if (cb) {
61 cb(timer.get_time());
62 }
63 }
64
65 protected:
68};
69
70/* Make human readable string from time, compatible with Blender metadata. */
71
72string time_human_readable_from_seconds(const double seconds);
73double time_human_readable_to_seconds(const string &str);
74
76
77#endif
function< void(double)> callback_type
Definition time.h:54
callback_type cb
Definition time.h:67
scoped_callback_timer(callback_type cb)
Definition time.h:56
scoped_timer timer
Definition time.h:66
double * value_
Definition time.h:48
double get_start() const
Definition time.h:37
~scoped_timer()
Definition time.h:30
double get_time() const
Definition time.h:42
scoped_timer(double *value=NULL)
Definition time.h:25
double time_start_
Definition time.h:49
#define CCL_NAMESPACE_END
#define NULL
#define str(s)
void time_sleep(double t)
Definition time.cpp:45
double time_human_readable_to_seconds(const string &str)
Definition time.cpp:82
string time_human_readable_from_seconds(const double seconds)
Definition time.cpp:67
CCL_NAMESPACE_BEGIN double time_dt()
Definition time.cpp:36