summaryrefslogtreecommitdiffhomepage
path: root/src/path-search-result.hpp
blob: 90a4ba3d46d5ecdf2e2a367c8ef3394b0245418e (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
47
48
49
50
51
52
53
54
#pragma once
#include "src/global-coords.hpp"
#include "compat/defs.hpp"
#include <memory>
#include <vector>

namespace floormat {

struct path_search_result final
{
    friend class path_search;
    friend struct astar;
    friend struct test_app;

    struct pair { global_coords pos; Vector2 offset; };

    const pair* data() const;
    const pair& operator[](size_t index) const;
    size_t size() const;

    explicit operator ArrayView<const pair>() const;
    explicit operator bool() const;

private:
    fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(path_search_result);
    path_search_result(const path_search_result& x) noexcept;
    path_search_result& operator=(const path_search_result& x) noexcept;

    static constexpr size_t min_length = TILE_MAX_DIM*2;

    struct node
    {
        friend struct path_search_result;
        friend struct test_app;

        node() noexcept;
        fm_DECLARE_DELETED_COPY_ASSIGNMENT(node);
        fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(node);

        std::vector<pair> vec;

    private:
        std::unique_ptr<node> _next;
    };

    static std::unique_ptr<node> _pool; // NOLINT(*-avoid-non-const-global-variables)

    path_search_result();
    ~path_search_result() noexcept;

    std::unique_ptr<node> _node;
};

} // namespace floormat