1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
27 namespace slideshow::internal
{
29 /** Event, which delays the functor call the given amount of time
31 class Delay
: public Event
34 typedef ::std::function
<void ()> FunctorT
;
36 template <typename FuncT
>
37 Delay( FuncT
const& func
,
39 , const OUString
& rsDescription
40 ) : Event(rsDescription
),
41 mnTimeout(nTimeout
), maFunc(func
), mbWasFired(false) {}
43 Delay( std::function
<void ()> func
,
45 , const OUString
& rsDescription
46 ) : Event(rsDescription
),
48 maFunc(std::move(func
)),
50 Delay(const Delay
&) = delete;
51 Delay
& operator=(const Delay
&) = delete;
54 virtual bool fire() override
;
55 virtual bool isCharged() const override
;
56 virtual double getActivationTime( double nCurrentTime
) const override
;
58 virtual void dispose() override
;
61 double const mnTimeout
;
66 #if OSL_DEBUG_LEVEL <= 1
68 /** Generate delay event
71 Functor to call when the event fires.
74 Timeout in seconds, to wait until functor is called.
76 @return generated delay event
78 template <typename FuncT
>
79 inline EventSharedPtr
makeDelay_( FuncT
const& func
, double nTimeout
, OUString
const& rsDescription
)
81 return std::make_shared
<Delay
>( func
, nTimeout
, rsDescription
);
84 /** Generate immediate event
87 Functor to call when the event fires.
89 @return generated immediate event.
91 template <typename FuncT
>
92 inline EventSharedPtr
makeEvent_( FuncT
const& func
, OUString
const& rsDescription
)
94 return std::make_shared
<Delay
>( func
, 0.0, rsDescription
);
98 #define makeDelay(f, t, d) makeDelay_(f, t, d)
99 #define makeEvent(f, d) makeEvent_(f, d)
101 #else // OSL_DEBUG_LEVEL > 0
103 class Delay_
: public Delay
{
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
) {}
113 char const* const FROM_FUNCTION
;
114 char const* const FROM_FILE
;
118 template <typename FuncT
>
119 inline EventSharedPtr
makeDelay_(
120 FuncT
const& func
, double nTimeout
,
121 char const* from_function
, char const* from_file
, int from_line
,
122 const OUString
& rsDescription
)
124 return EventSharedPtr( new Delay_( func
, nTimeout
,
125 from_function
, from_file
, from_line
, rsDescription
) );
128 #define makeDelay(f, t, d) makeDelay_(f, t, \
129 __func__, __FILE__, __LINE__, \
131 #define makeEvent(f, d) makeDelay_(f, 0.0, \
132 __func__, __FILE__, __LINE__, \
135 #endif // OSL_DEBUG_LEVEL <= 1
137 } // namespace presentation::internal
139 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */