Coverage Report

Created: 2025-10-12 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opendnp3/_deps/exe4cpp-src/src/exe4cpp/Timer.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018, Automatak LLC
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6
 * following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9
 * disclaimer.
10
 *
11
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12
 * disclaimer in the documentation and/or other materials provided with the distribution.
13
 *
14
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
15
 * products derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
#ifndef EXE4CPP_TIMER_H
26
#define EXE4CPP_TIMER_H
27
28
#include "exe4cpp/ITimer.h"
29
30
#include <memory>
31
32
namespace exe4cpp
33
{
34
35
/**
36
 * Timer is a wrapper around an implementation of ITimer
37
 */
38
class Timer final
39
{
40
public:
41
28.1k
    Timer() : timer{}
42
28.1k
    {}
43
44
6.41k
    explicit Timer(const std::shared_ptr<ITimer>& timer) : timer{timer}
45
6.41k
    {}
46
47
    inline bool cancel()
48
22.3k
    {
49
22.3k
        if (auto impl = timer.lock())
50
13
        {
51
13
            impl->cancel();
52
13
            return true;
53
13
        }
54
22.2k
        else
55
22.2k
        {
56
22.2k
            return false;
57
22.2k
        }
58
22.3k
    }
59
60
    inline steady_time_t expires_at()
61
0
    {
62
0
        if (auto impl = timer.lock())
63
0
        {
64
0
            return impl->expires_at();
65
0
        }
66
0
        else
67
0
        {
68
0
            return steady_time_t::min();
69
0
        }
70
0
    }
71
72
private:
73
    std::weak_ptr<ITimer> timer;
74
};
75
76
}
77
78
#endif