summaryrefslogtreecommitdiffstats
path: root/src/util/funclog.cpp
blob: 5597feac31a563bb5fddc2a1b9e728f52b26af1e (plain)
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
// SPDX-License-Identifier: GPL-2.0-or-later
#include "funclog.h"

namespace Inkscape {
namespace Util {

void FuncLog::exec()
{
    for (auto h = first; h; destroy_and_advance(h)) {
        try {
            (*h)();
        } catch (...) {
            destroy_from(h);
            reset();
            std::rethrow_exception(std::current_exception());
        }
    }
    reset();
}

void FuncLog::destroy_and_advance(Header *&h) noexcept
{
    auto next = h->next;
    h->~Header();
    h = next;
}

void FuncLog::reset() noexcept
{
    pool.free_all();
    first = nullptr;
    lastnext = &first;
}

void FuncLog::movefrom(FuncLog &other) noexcept
{
    pool = std::move(other.pool);
    first = other.first;
    lastnext = first ? other.lastnext : &first;

    other.first = nullptr;
    other.lastnext = &other.first;
}

} // namespace Util
} // namespace Inkscape