SFML 3.0.2
Loading...
Searching...
No Matches
Time.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <chrono>
31
32#include <cstdint>
33
34
35 namespace sf
36{
41 class Time
42{
43 public:
50 constexpr Time() = default;
51
56 template <typename Rep, typename Period>
57 constexpr Time(const std::chrono::duration<Rep, Period>& duration);
58
67 [[nodiscard]] constexpr float asSeconds() const;
68
77 [[nodiscard]] constexpr std::int32_t asMilliseconds() const;
78
87 [[nodiscard]] constexpr std::int64_t asMicroseconds() const;
88
95 [[nodiscard]] constexpr std::chrono::microseconds toDuration() const;
96
103 template <typename Rep, typename Period>
104 constexpr operator std::chrono::duration<Rep, Period>() const;
105
107 // Static member data
109 // NOLINTNEXTLINE(readability-identifier-naming)
110 static const Time Zero;
111
112 private:
114 // Member data
116 std::chrono::microseconds m_microseconds{};
117};
118
130[[nodiscard]] constexpr Time seconds(float amount);
131
143[[nodiscard]] constexpr Time milliseconds(std::int32_t amount);
144
156[[nodiscard]] constexpr Time microseconds(std::int64_t amount);
157
168[[nodiscard]] constexpr bool operator==(Time left, Time right);
169
180[[nodiscard]] constexpr bool operator!=(Time left, Time right);
181
192[[nodiscard]] constexpr bool operator<(Time left, Time right);
193
204[[nodiscard]] constexpr bool operator>(Time left, Time right);
205
216[[nodiscard]] constexpr bool operator<=(Time left, Time right);
217
228[[nodiscard]] constexpr bool operator>=(Time left, Time right);
229
239[[nodiscard]] constexpr Time operator-(Time right);
240
251[[nodiscard]] constexpr Time operator+(Time left, Time right);
252
263 constexpr Time& operator+=(Time& left, Time right);
264
275[[nodiscard]] constexpr Time operator-(Time left, Time right);
276
287 constexpr Time& operator-=(Time& left, Time right);
288
299[[nodiscard]] constexpr Time operator*(Time left, float right);
300
311[[nodiscard]] constexpr Time operator*(Time left, std::int64_t right);
312
323[[nodiscard]] constexpr Time operator*(float left, Time right);
324
335[[nodiscard]] constexpr Time operator*(std::int64_t left, Time right);
336
347 constexpr Time& operator*=(Time& left, float right);
348
359 constexpr Time& operator*=(Time& left, std::int64_t right);
360
371[[nodiscard]] constexpr Time operator/(Time left, float right);
372
383[[nodiscard]] constexpr Time operator/(Time left, std::int64_t right);
384
395 constexpr Time& operator/=(Time& left, float right);
396
407 constexpr Time& operator/=(Time& left, std::int64_t right);
408
419[[nodiscard]] constexpr float operator/(Time left, Time right);
420
431[[nodiscard]] constexpr Time operator%(Time left, Time right);
432
443 constexpr Time& operator%=(Time& left, Time right);
444
445} // namespace sf
446
447#include <SFML/System/Time.inl>
448
449
sf::Time::operator-
constexpr Time operator-(Time right)
Overload of unary operator- to negate a time value.
sf::Time::asSeconds
constexpr float asSeconds() const
Return the time value as a number of seconds.
sf::Time::operator%
constexpr Time operator%(Time left, Time right)
Overload of binary operator% to compute remainder of a time value.
sf::Time::operator*=
constexpr Time & operator*=(Time &left, std::int64_t right)
Overload of binary operator*= to scale/assign a time value.
sf::Time::microseconds
constexpr Time microseconds(std::int64_t amount)
Construct a time value from a number of microseconds.
sf::Time::Time
constexpr Time(const std::chrono::duration< Rep, Period > &duration)
Construct from std::chrono::duration
sf::Time::operator-
constexpr Time operator-(Time left, Time right)
Overload of binary operator- to subtract two time values.
sf::Time::operator*
constexpr Time operator*(Time left, std::int64_t right)
Overload of binary operator* to scale a time value.
sf::Time::operator%=
constexpr Time & operator%=(Time &left, Time right)
Overload of binary operator%= to compute/assign remainder of a time value.
sf::Time::seconds
constexpr Time seconds(float amount)
Construct a time value from a number of seconds.
sf::Time::operator*
constexpr Time operator*(std::int64_t left, Time right)
Overload of binary operator* to scale a time value.
sf::Time::operator/
constexpr float operator/(Time left, Time right)
Overload of binary operator/ to compute the ratio of two time values.
sf::Time::operator!=
constexpr bool operator!=(Time left, Time right)
Overload of operator!= to compare two time values.
sf::Time::asMicroseconds
constexpr std::int64_t asMicroseconds() const
Return the time value as a number of microseconds.
sf::Time::toDuration
constexpr std::chrono::microseconds toDuration() const
Return the time value as a std::chrono::duration
sf::Time::operator/
constexpr Time operator/(Time left, std::int64_t right)
Overload of binary operator/ to scale a time value.
sf::Time::Zero
static const Time Zero
Predefined "zero" time value.
Definition Time.hpp:110
sf::Time::operator>
constexpr bool operator>(Time left, Time right)
Overload of operator> to compare two time values.
sf::Time::asMilliseconds
constexpr std::int32_t asMilliseconds() const
Return the time value as a number of milliseconds.
sf::Time::operator+
constexpr Time operator+(Time left, Time right)
Overload of binary operator+ to add two time values.
sf::Time::operator*
constexpr Time operator*(Time left, float right)
Overload of binary operator* to scale a time value.
sf::Time::operator<
constexpr bool operator<(Time left, Time right)
Overload of operator< to compare two time values.
sf::Time::operator-=
constexpr Time & operator-=(Time &left, Time right)
Overload of binary operator-= to subtract/assign two time values.
sf::Time::operator<=
constexpr bool operator<=(Time left, Time right)
Overload of operator<= to compare two time values.
sf::Time::operator*=
constexpr Time & operator*=(Time &left, float right)
Overload of binary operator*= to scale/assign a time value.
sf::Time::Time
constexpr Time()=default
Default constructor.
sf::Time::milliseconds
constexpr Time milliseconds(std::int32_t amount)
Construct a time value from a number of milliseconds.
sf::Time::operator==
constexpr bool operator==(Time left, Time right)
Overload of operator== to compare two time values.
sf::Time::operator*
constexpr Time operator*(float left, Time right)
Overload of binary operator* to scale a time value.
sf::Time::operator/
constexpr Time operator/(Time left, float right)
Overload of binary operator/ to scale a time value.
sf::Time::operator>=
constexpr bool operator>=(Time left, Time right)
Overload of operator>= to compare two time values.
sf::Time::operator/=
constexpr Time & operator/=(Time &left, std::int64_t right)
Overload of binary operator/= to scale/assign a time value.
sf::Time::operator/=
constexpr Time & operator/=(Time &left, float right)
Overload of binary operator/= to scale/assign a time value.
sf::Time::operator+=
constexpr Time & operator+=(Time &left, Time right)
Overload of binary operator+= to add/assign two time values.
sf
Definition AudioResource.hpp:36