xtd 1.0.0
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "component.hpp"
6#include <xtd/chrono>
7#include <xtd/event>
8#include <xtd/event_handler>
9#include <xtd/time_span>
10#include <cstdint>
11#include <memory>
12
14namespace xtd {
16 namespace forms {
38 class forms_export_ timer : public component {
39 struct data;
40
41 public:
43
50
52 timer(const timer&) = delete;
53 timer& operator =(const timer&) = delete;
54 timer(timer&&) = default;
55 timer& operator =(timer&&) = default;
56 ~timer();
58
60
65 [[nodiscard]] virtual auto enabled() const noexcept -> bool;
69 virtual auto enabled(bool value) -> timer&;
70
73 [[nodiscard]] virtual auto interval() const noexcept -> xtd::time_span;
76 virtual auto interval(const xtd::time_span& value) -> timer&;
77
81 [[nodiscard]] virtual auto interval_milliseconds() const noexcept -> xtd::int32;
85 virtual auto interval_milliseconds(xtd::int32 value) -> timer&;
87
89
93 auto start() -> void;
94
97 auto stop() -> void;
99
101
105 [[nodiscard]] static auto create() -> timer;
109 [[nodiscard]] static auto create(const xtd::time_span& interval) -> timer;
114 [[nodiscard]] static auto create(const xtd::time_span& interval, bool enable) -> timer;
118 [[nodiscard]] static auto create(xtd::int32 interval_milliseconds) -> timer;
123 [[nodiscard]] static auto create(xtd::int32 interval_milliseconds, bool enable) -> timer;
125
127
134
135 protected:
137
141 virtual auto on_tick(const xtd::event_args& e) -> void;
143
144 private:
145 auto restart() -> void;
146
147 xtd::sptr<data> data_;
148 };
149 }
150}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents an event.
Definition event.hpp:23
component()
Initialises a new instance of the component class.
virtual auto on_tick(const xtd::event_args &e) -> void
Raises the xtd::forms::timer::tick event.
virtual auto interval_milliseconds() const noexcept -> xtd::int32
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of th...
auto stop() -> void
Starts the timer.
static auto create() -> timer
A factory to create an xtd::forms::timer.
auto start() -> void
Stops the timer.
virtual auto enabled() const noexcept -> bool
Gets whether the timer is running.
timer()
Initializes a new instance of the timer class.
xtd::event< timer, xtd::event_handler > tick
Occurs when the specified timer interval has elapsed and the timer is enabled.
Definition timer.hpp:132
virtual auto interval() const noexcept -> xtd::time_span
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of th...
Represents a time interval.
Definition time_span.hpp:29
Contains xtd::forms::component class.
generic_event_handler< const xtd::event_args & > event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.hpp:24
#define forms_export_
Define shared library export.
Definition forms_export.hpp:13
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:219
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197