-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlobby_view_item.cpp
63 lines (57 loc) · 1.45 KB
/
lobby_view_item.cpp
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
#include "lobby_view_item.h"
#include <algorithm>
#include <cassert>
#include "../magic_enum/include/magic_enum.hpp"
std::vector<lobby_view_item> get_all_lobby_view_items() noexcept
{
const auto a{magic_enum::enum_values<lobby_view_item>()};
std::vector<lobby_view_item> v;
v.reserve(a.size());
std::copy(std::begin(a), std::end(a), std::back_inserter(v));
assert(a.size() == v.size());
return v;
}
lobby_view_item get_next(const lobby_view_item item)
{
const auto v{get_all_lobby_view_items()};
auto there{std::find(std::begin(v), std::end(v), item)};
assert(there != std::end(v));
if (there == std::end(v) - 1)
{
assert(!v.empty());
const auto t{v.front()};
return t;
}
return *(++there);
}
lobby_view_item get_previous(const lobby_view_item& item)
{
const auto v{get_all_lobby_view_items()};
auto there{std::find(std::begin(v), std::end(v), item)};
assert(there != std::end(v));
if (there == std::begin(v))
{
assert(!v.empty());
const auto t{v.back()};
return t;
}
return *(--there);
}
void test_lobby_view_item()
{
#ifndef NDEBUG
// Get next
{
assert(get_next(lobby_view_item::color) == lobby_view_item::race);
assert(get_next(lobby_view_item::race) == lobby_view_item::start);
assert(get_next(lobby_view_item::start) == lobby_view_item::color);
}
// Get previous
{
for (const auto i: get_all_lobby_view_items())
{
assert(get_previous(get_next(i)) == i);
}
}
#endif
}