LibreOffice Module slideshow (master) 1
delayevent.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
20#define INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
21
22#include "event.hxx"
23
24#include <functional>
25#include <utility>
26
27namespace slideshow::internal {
28
31class Delay : public Event
32{
33public:
34 typedef ::std::function<void ()> FunctorT;
35
36 template <typename FuncT>
37 Delay( FuncT const& func,
38 double nTimeout
39 , const OUString& rsDescription
40 ) : Event(rsDescription),
41 mnTimeout(nTimeout), maFunc(func), mbWasFired(false) {}
42
43 Delay( std::function<void ()> func,
44 double nTimeout
45 , const OUString& rsDescription
46 ) : Event(rsDescription),
47 mnTimeout(nTimeout),
48 maFunc(std::move(func)),
49 mbWasFired(false) {}
50 Delay(const Delay&) = delete;
51 Delay& operator=(const Delay&) = delete;
52
53 // Event:
54 virtual bool fire() override;
55 virtual bool isCharged() const override;
56 virtual double getActivationTime( double nCurrentTime ) const override;
57 // Disposable:
58 virtual void dispose() override;
59
60private:
61 double const mnTimeout;
64};
65
66#if OSL_DEBUG_LEVEL <= 1
67
78template <typename FuncT>
79inline EventSharedPtr makeDelay_( FuncT const& func, double nTimeout, OUString const& rsDescription )
80{
81 return std::make_shared<Delay>( func, nTimeout, rsDescription );
82}
83
91template <typename FuncT>
92inline EventSharedPtr makeEvent_( FuncT const& func, OUString const& rsDescription)
93{
94 return std::make_shared<Delay>( func, 0.0, rsDescription );
95}
96
97
98#define makeDelay(f, t, d) makeDelay_(f, t, d)
99#define makeEvent(f, d) makeEvent_(f, d)
100
101#else // OSL_DEBUG_LEVEL > 0
102
103class Delay_ : public Delay {
104public:
105 template <typename FuncT>
106 Delay_( FuncT const& func, double nTimeout,
107 char const* from_function, char const* from_file, int from_line,
108 const OUString& rsDescription)
109 : Delay(func, nTimeout, rsDescription),
110 FROM_FUNCTION(from_function),
111 FROM_FILE(from_file), FROM_LINE(from_line) {}
112
113 char const* const FROM_FUNCTION;
114 char const* const FROM_FILE;
115 int const FROM_LINE;
116};
117
118template <typename FuncT>
120 FuncT const& func, double nTimeout,
121 char const* from_function, char const* from_file, int from_line,
122 const OUString& rsDescription)
123{
124 return EventSharedPtr( new Delay_( func, nTimeout,
125 from_function, from_file, from_line, rsDescription) );
126}
127
128#define makeDelay(f, t, d) makeDelay_(f, t, \
129 __func__, __FILE__, __LINE__, \
130 d)
131#define makeEvent(f, d) makeDelay_(f, 0.0, \
132 __func__, __FILE__, __LINE__, \
133 d)
134
135#endif // OSL_DEBUG_LEVEL <= 1
136
137} // namespace presentation::internal
138
139#endif // INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
char const *const FROM_FUNCTION
Definition: delayevent.hxx:113
Delay_(FuncT const &func, double nTimeout, char const *from_function, char const *from_file, int from_line, const OUString &rsDescription)
Definition: delayevent.hxx:106
char const *const FROM_FILE
Definition: delayevent.hxx:114
Event, which delays the functor call the given amount of time.
Definition: delayevent.hxx:32
Delay(const Delay &)=delete
virtual bool isCharged() const override
Query whether this event is still charged, i.e.
Definition: delayevent.cxx:37
virtual void dispose() override
Dispose all object references.
Definition: delayevent.cxx:47
virtual double getActivationTime(double nCurrentTime) const override
Query the activation time instant this event shall be fired, if it was inserted at instant nCurrentTi...
Definition: delayevent.cxx:42
::std::function< void()> FunctorT
Definition: delayevent.hxx:34
Delay(std::function< void()> func, double nTimeout, const OUString &rsDescription)
Definition: delayevent.hxx:43
virtual bool fire() override
Execute the event.
Definition: delayevent.cxx:26
Delay(FuncT const &func, double nTimeout, const OUString &rsDescription)
Definition: delayevent.hxx:37
Delay & operator=(const Delay &)=delete
Definition of Event interface.
Definition: event.hxx:33
::std::shared_ptr< Event > EventSharedPtr
Definition: event.hxx:76
EventSharedPtr makeDelay_(FuncT const &func, double nTimeout, char const *from_function, char const *from_file, int from_line, const OUString &rsDescription)
Definition: delayevent.hxx:119