Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
Types.hh
1
#pragma once
2
3
#include <Logger.hh>
4
5
#include <egg/core/Heap.hh>
6
7
#include <cstdint>
8
#include <span>
9
#include <type_traits>
10
11
namespace
Kinoko {
12
13
typedef
int8_t s8;
14
typedef
int16_t s16;
15
typedef
int32_t s32;
16
typedef
int64_t s64;
17
18
typedef
uint8_t u8;
19
typedef
uint16_t u16;
20
typedef
uint32_t u32;
21
typedef
uint64_t u64;
22
23
typedef
float
f32;
24
typedef
double
f64;
25
30
template
<
typename
T>
31
class
owning_span
{
32
public
:
34
owning_span
() :
m_data
(nullptr),
m_size
(0) {}
35
37
owning_span
(
size_t
count) :
m_data
(
EGG
::egg_new_array<T>(count)),
m_size
(count) {}
38
41
owning_span
(
const
std::span<const T> &span)
42
:
m_data
(
EGG
::egg_new_array<T>(span.
size
())),
m_size
(span.
size
()) {
43
std::copy(span.begin(), span.end(),
m_data
);
44
}
45
48
owning_span
(
const
owning_span
&rhs) :
m_size
(rhs.
m_size
) {
49
m_data
= EGG::egg_new_array<T>(
m_size
);
50
std::copy(rhs.begin(), rhs.end(),
m_data
);
51
}
52
55
owning_span
(
owning_span
&&rhs) {
56
m_data
= rhs.m_data;
57
rhs.m_data =
nullptr
;
58
59
m_size
= rhs.m_size;
60
rhs.m_size = 0;
61
}
62
65
owning_span
&
operator=
(
const
owning_span
&rhs) {
66
if
(
this
!= &rhs) {
67
EGG::egg_delete_array(
m_data
,
m_size
);
68
m_size
= rhs.
m_size
;
69
m_data
= EGG::egg_new_array<T>(
m_size
);
70
std::copy(rhs.begin(), rhs.end(),
m_data
);
71
}
72
73
return
*
this
;
74
}
75
78
owning_span
&
operator=
(
owning_span
&&rhs) {
79
if
(
this
!= &rhs) {
80
EGG::egg_delete_array(
m_data
,
m_size
);
81
m_data
= rhs.m_data;
82
rhs.m_data =
nullptr
;
83
m_size
= rhs.m_size;
84
rhs.m_size = 0;
85
}
86
87
return
*
this
;
88
}
89
91
~owning_span
() {
92
EGG::egg_delete_array(
m_data
,
m_size
);
93
}
94
97
[[nodiscard]] T &
operator[]
(
size_t
idx) {
98
ASSERT(idx <
m_size
);
99
return
m_data
[idx];
100
}
101
104
[[nodiscard]]
const
T &
operator[]
(
size_t
idx)
const
{
105
ASSERT(idx <
m_size
);
106
return
m_data
[idx];
107
}
108
110
[[nodiscard]] T &
front
() {
111
ASSERT(
m_size
> 0);
112
return
m_data
[0];
113
}
114
116
[[nodiscard]]
const
T &
front
()
const
{
117
ASSERT(
m_size
> 0);
118
return
m_data
[0];
119
}
120
122
[[nodiscard]] T &
back
() {
123
ASSERT(
m_size
> 0);
124
return
m_data
[
m_size
- 1];
125
}
126
128
[[nodiscard]]
const
T &
back
()
const
{
129
ASSERT(
m_size
> 0);
130
return
m_data
[
m_size
- 1];
131
}
132
133
[[nodiscard]] T *begin() {
134
return
m_data
;
135
}
136
137
[[nodiscard]] T *end() {
138
return
m_data
+
m_size
;
139
}
140
141
[[nodiscard]]
const
T *begin()
const
{
142
return
m_data
;
143
}
144
145
[[nodiscard]]
const
T *end()
const
{
146
return
m_data
+
m_size
;
147
}
148
150
[[nodiscard]]
bool
empty
()
const
{
151
return
m_size
== 0;
152
}
153
155
[[nodiscard]]
size_t
size
()
const
{
156
return
m_size
;
157
}
158
160
[[nodiscard]] std::span<const T>
view
()
const
{
161
return
{
m_data
,
m_size
};
162
}
163
164
private
:
165
T *
m_data
;
166
size_t
m_size
;
167
};
168
169
}
// namespace Kinoko
Kinoko::owning_span::owning_span
owning_span()
Uninitialized buffer.
Definition
Types.hh:34
Kinoko::owning_span::back
const T & back() const
Retrieves the last element in the buffer.
Definition
Types.hh:128
Kinoko::owning_span::operator=
owning_span & operator=(const owning_span &rhs)
Copy assignment operator.
Definition
Types.hh:65
Kinoko::owning_span::front
const T & front() const
Retrieves the first element in the buffer.
Definition
Types.hh:116
Kinoko::owning_span::back
T & back()
Retrieves the last element in the buffer.
Definition
Types.hh:122
Kinoko::owning_span::owning_span
owning_span(const owning_span &rhs)
Copy constructor.
Definition
Types.hh:48
Kinoko::owning_span::empty
bool empty() const
Returns true if the buffer is uninitialized.
Definition
Types.hh:150
Kinoko::owning_span::front
T & front()
Retrieves the first element in the buffer.
Definition
Types.hh:110
Kinoko::owning_span::size
size_t size() const
Returns the number of elements that fit in the buffer.
Definition
Types.hh:155
Kinoko::owning_span::m_data
T * m_data
Pointer to the underlying buffer.
Definition
Types.hh:165
Kinoko::owning_span::~owning_span
~owning_span()
Destroys the underlying buffer on teardown.
Definition
Types.hh:91
Kinoko::owning_span::owning_span
owning_span(size_t count)
Allocates a buffer of T elements. Does not initialize any elements.
Definition
Types.hh:37
Kinoko::owning_span::operator=
owning_span & operator=(owning_span &&rhs)
Move assignment operator.
Definition
Types.hh:78
Kinoko::owning_span::m_size
size_t m_size
The number of T elements that fit in the buffer.
Definition
Types.hh:166
Kinoko::owning_span::operator[]
const T & operator[](size_t idx) const
Indexes into the underlying buffer.
Definition
Types.hh:104
Kinoko::owning_span::operator[]
T & operator[](size_t idx)
Indexes into the underlying buffer.
Definition
Types.hh:97
Kinoko::owning_span::owning_span
owning_span(owning_span &&rhs)
Move constructor.
Definition
Types.hh:55
Kinoko::owning_span::owning_span
owning_span(const std::span< const T > &span)
Performs a deep copy from a std::span of const T.
Definition
Types.hh:41
Kinoko::owning_span::view
std::span< const T > view() const
Returns a read-only view of the entire buffer.
Definition
Types.hh:160
Kinoko::EGG
EGG core library.
Definition
Allocator.hh:5
include
Types.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0