• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/src/base/func_util.hh
1
/**
2
 * Copyright (c) 2020, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#ifndef lnav_func_util_hh
31
#define lnav_func_util_hh
32

33
#include <functional>
34
#include <utility>
35

36
#include "progress.hh"
37

38
template<typename F, typename FrontArg>
39
decltype(auto)
UNCOV
40
bind_mem(F&& f, FrontArg&& frontArg)
×
41
{
UNCOV
42
    return [f = std::forward<F>(f),
×
UNCOV
43
            frontArg = std::forward<FrontArg>(frontArg)](auto&&... backArgs) {
×
UNCOV
44
        return (frontArg->*f)(std::forward<decltype(backArgs)>(backArgs)...);
×
45
    };
46
}
47

48
struct noop_func {
49
    struct anything {
50
        template<class T>
51
        operator T()
52
        {
53
            return {};
54
        }
55
        // optional reference support.  Somewhat evil.
56
        template<class T>
57
        operator T&() const
58
        {
59
            static T t{};
60
            return t;
61
        }
62
    };
63
    template<class... Args>
64
    anything operator()(Args&&...) const
42,019✔
65
    {
66
        return {};
42,019✔
67
    }
68
};
69

70
namespace lnav::func {
71

72
enum class op_type {
73
    blocking,
74
    interactive,
75
};
76

77
class scoped_cb {
78
public:
79
    using callback_type = std::function<progress_result_t(op_type)>;
80

81
    class guard {
82
    public:
UNCOV
83
        explicit guard(scoped_cb* owner) : g_owner(owner) {}
×
84

85
        guard(const guard&) = delete;
86
        guard& operator=(const guard&) = delete;
87

88
        guard(guard&& gu) noexcept : g_owner(std::exchange(gu.g_owner, nullptr))
89
        {
90
        }
91

92
        guard& operator=(guard&& gu) noexcept
93
        {
94
            this->g_owner = std::exchange(gu.g_owner, nullptr);
95
            return *this;
96
        }
97

UNCOV
98
        ~guard()
×
99
        {
UNCOV
100
            if (this->g_owner != nullptr) {
×
UNCOV
101
                this->g_owner->s_callback = {};
×
102
            }
103
        }
104

105
    private:
106
        scoped_cb* g_owner;
107
    };
108

UNCOV
109
    guard install(callback_type cb)
×
110
    {
UNCOV
111
        this->s_callback = std::move(cb);
×
112

UNCOV
113
        return guard{this};
×
114
    }
115

116
    progress_result_t operator()(op_type ot) const
124✔
117
    {
118
        if (s_callback) {
124✔
UNCOV
119
            return s_callback(ot);
×
120
        }
121

122
        return progress_result_t::ok;
124✔
123
    }
124

125
private:
126
    callback_type s_callback;
127
};
128

129
template<typename Fn,
130
         typename... Args,
131
         std::enable_if_t<std::is_member_pointer<std::decay_t<Fn>>{}, int> = 0>
132
constexpr decltype(auto)
133
invoke(Fn&& f, Args&&... args) noexcept(
885✔
134
    noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
135
{
136
    return std::mem_fn(f)(std::forward<Args>(args)...);
885✔
137
}
138

139
template<typename Fn,
140
         typename... Args,
141
         std::enable_if_t<!std::is_member_pointer<std::decay_t<Fn>>{}, int> = 0>
142
constexpr decltype(auto)
143
invoke(Fn&& f, Args&&... args) noexcept(
51,027✔
144
    noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
145
{
146
    return std::forward<Fn>(f)(std::forward<Args>(args)...);
51,027✔
147
}
148

149
template<class F, class... Args>
150
struct is_invocable {
151
    template<typename U, typename Obj, typename... FuncArgs>
152
    static auto test(U&& p)
153
        -> decltype((std::declval<Obj>().*p)(std::declval<FuncArgs>()...),
154
                    void(),
155
                    std::true_type());
156
    template<typename U, typename... FuncArgs>
157
    static auto test(U* p) -> decltype((*p)(std::declval<FuncArgs>()...),
158
                                       void(),
159
                                       std::true_type());
160
    template<typename U, typename... FuncArgs>
161
    static auto test(...) -> decltype(std::false_type());
162

163
    static constexpr bool value = decltype(test<F, Args...>(0))::value;
164
};
165

166
}  // namespace lnav::func
167

168
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc