This file is indexed.

/usr/include/mircommon/mir/raii.h is in libmircommon-dev 0.31.1-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright © 2013 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2 or 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
 */

#ifndef MIR_RAII_H_
#define MIR_RAII_H_

#include <memory>
#include <type_traits>

namespace mir
{
/// Utilities for exception safe use of paired function calls
namespace raii
{
template <typename Creator, typename Deleter>
struct PairedCalls
{
    PairedCalls(Creator&& creator, Deleter&& deleter) : deleter(std::move(deleter)), owner(true) { creator(); }
    PairedCalls(PairedCalls&& that) : deleter(that.deleter), owner(that.owner) { that.owner = false; }
    ~PairedCalls()  { if (owner) deleter(); }
private:
    PairedCalls(PairedCalls const& that) = delete;
    PairedCalls& operator=(PairedCalls const& that) = delete;
    Deleter const deleter;
    bool owner;
};

/**
 * Creates an RAII object from a creator and deleter.
 * If creator returns a pointer type then the returned object
 * is a std::unique_ptr initialized with the pointer and deleter.
 * Otherwise, the returned object calls creator on construction and deleter on destruction
 *
 * \param creator called to initialize the returned object
 * \param deleter called to finalize the returned object
 */
template <typename Creator, typename Deleter>
inline auto paired_calls(Creator&& creator, Deleter&& deleter)
-> std::unique_ptr<typename std::remove_reference<decltype(*creator())>::type, Deleter>
{
    return {creator(), deleter};
}

///\overload
template <typename Creator, typename Deleter>
inline auto paired_calls(Creator&& creator, Deleter&& deleter)
-> typename std::enable_if<
    std::is_void<decltype(creator())>::value,
    PairedCalls<Creator, Deleter>>::type
{
    return {std::move(creator), std::move(deleter)};
}

/**
 * Creates an RAII object from an owning pointer and deleter.
 * The returned object is a std::unique_ptr initialized with the pointer and deleter.
 *
 * \param owned   the object to take ownership of
 * \param deleter called to finalize the owned object
 */
template <typename Owned, typename Deleter>
inline auto deleter_for(Owned* owned, Deleter&& deleter)
-> std::unique_ptr<Owned, Deleter>
{
    return {owned, deleter};
}
}
}

#endif /* MIR_RAII_H_ */