202 static_assert(std::is_trivially_copyable_v<T>,
"T must be trivially copyable");
203 static_assert(!std::is_class_v<T> || std::is_trivially_destructible_v<T>,
"T must be trivially destructible");
211 static const constexpr size_t minimumLength =
sizeof(
T);
220 : sharedMemory(path, minimumLength, mode) {}
284 static_assert(std::is_trivially_copyable_v<T>,
"T must be trivially copyable");
285 static_assert(std::is_trivially_destructible_v<T>,
"T must be trivially destructible");
293 static const constexpr size_t minimumLength =
sizeof(
T) * N;
302 : sharedMemory(path, minimumLength, mode) {}
321 T*
data() noexcept {
return reinterpret_cast<T*
>(sharedMemory.
data()); }
324 const T*
data() const noexcept {
return reinterpret_cast<const T*
>(sharedMemory.
data()); }
327 T&
front() noexcept {
return data()[0]; }
330 const T&
front() const noexcept {
return data()[0]; }
333 T&
back() noexcept {
return data()[size()]; }
336 const T&
back() const noexcept {
return data()[size()]; }
339 [[nodiscard]]
constexpr size_t size() const noexcept {
return N; }
342 [[nodiscard]]
constexpr size_t capacity() const noexcept {
return size(); }
345 [[nodiscard]]
constexpr bool empty() const noexcept {
return false; }
349 [[nodiscard]]
bool valid() const noexcept {
return sharedMemory.
valid(); }
359 T*
begin() noexcept {
return &data()[0]; }
362 const T*
begin() const noexcept {
return &data()[0]; }
365 const T*
cbegin() const noexcept {
return &data()[0]; }
368 T*
end() noexcept {
return &data()[size()]; }
371 const T*
end() const noexcept {
return &data()[size()]; }
374 const T*
cend() const noexcept {
return &data()[size()]; }
377 std::reverse_iterator<T*>
rbegin() noexcept {
return end(); }
380 [[nodiscard]] std::reverse_iterator<const T*>
rbegin() const noexcept {
return end(); }
383 [[nodiscard]] std::reverse_iterator<const T*>
crbegin() const noexcept {
return end(); }
386 std::reverse_iterator<T*>
rend() noexcept {
return begin(); }
389 [[nodiscard]] std::reverse_iterator<const T*>
rend() const noexcept {
return begin(); }
392 [[nodiscard]] std::reverse_iterator<const T*>
crend() const noexcept {
return begin(); }
397 explicit operator bool() const noexcept {
return valid(); }
413 static_assert(std::is_trivially_copyable_v<T>,
"T must be trivially copyable");
414 static_assert(std::is_trivially_destructible_v<T>,
"T must be trivially destructible");
422 static const constexpr size_t minimumLength = 0;
431 : sharedMemory(path, minimumLength, mode) {}
450 T*
data() noexcept {
return reinterpret_cast<T*
>(sharedMemory.
data()); }
453 const T*
data() const noexcept {
return reinterpret_cast<const T*
>(sharedMemory.
data()); }
456 T&
front() noexcept {
return data()[0]; }
459 const T&
front() const noexcept {
return data()[0]; }
462 T&
back() noexcept {
return data()[size()]; }
465 const T&
back() const noexcept {
return data()[size()]; }
468 [[nodiscard]]
size_t size() const noexcept {
return size_t(sharedMemory.
size() /
sizeof(
T)); }
471 [[nodiscard]]
size_t capacity() const noexcept {
return size(); }
474 [[nodiscard]]
bool empty() const noexcept {
return size() == 0; }
478 [[nodiscard]]
bool valid() const noexcept {
return sharedMemory.
valid(); }
485 void resize(
const size_t newSize) { sharedMemory.
resize(newSize *
sizeof(
T)); }
488 void clear() noexcept { resize(0); }
495 T*
begin() noexcept {
return &data()[0]; }
498 const T*
begin() const noexcept {
return &data()[0]; }
501 const T*
cbegin() const noexcept {
return &data()[0]; }
504 T*
end() noexcept {
return &data()[size()]; }
507 const T*
end() const noexcept {
return &data()[size()]; }
510 const T*
cend() const noexcept {
return &data()[size()]; }
513 std::reverse_iterator<T*>
rbegin() noexcept {
return std::reverse_iterator<T*>{end()}; }
516 [[nodiscard]] std::reverse_iterator<const T*>
rbegin() const noexcept {
return std::reverse_iterator<const T*>{cend()}; }
519 [[nodiscard]] std::reverse_iterator<const T*>
crbegin() const noexcept {
return std::reverse_iterator<const T*>{cend()}; }
522 std::reverse_iterator<T*>
rend() noexcept {
return std::reverse_iterator<T*>{begin()}; }
525 [[nodiscard]] std::reverse_iterator<const T*>
rend() const noexcept {
return std::reverse_iterator<T*>{cbegin()}; }
528 [[nodiscard]] std::reverse_iterator<const T*>
crend() const noexcept {
return std::reverse_iterator<const T*>{cbegin()}; }
533 explicit operator bool() const noexcept {
return valid(); }
Path to file or directory.
Definition FilePath.hpp:37
Definition SharedMemory.hpp:17
ConstPointer end() const noexcept
Definition SharedMemory.hpp:169
NativeHandle mHandle
The native handle used to manage the shared memory.
Definition SharedMemory.hpp:55
SizeType mLength
Definition SharedMemory.hpp:69
std::uintmax_t SizeType
A type that represents the mapping length and offsets.
Definition SharedMemory.hpp:48
int NativeHandle
A type that represents the native shared memory handle.
Definition SharedMemory.hpp:32
Pointer end() noexcept
Definition SharedMemory.hpp:166
Pointer mAddress
The base address to the mapped memory.
Definition SharedMemory.hpp:63
void unmap()
Unmaps the file into memory.
~SharedMemory() noexcept
Unloads the mapped file (if loaded) and destroy the SharedMemory object.
ConstPointer cend() const noexcept
Definition SharedMemory.hpp:172
size_t capacity() const noexcept
ConstReference at(const SizeType index) const noexcept
Definition SharedMemory.hpp:118
Reference back() noexcept
Definition SharedMemory.hpp:127
void resize(SizeType newSize)
Resizes the array to fit at least newSize elements.
void reset()
Closes any handle and unmaps all memory.
Byte const * ConstPointer
A type that represents a pointer in the memory mapped file.
Definition SharedMemory.hpp:45
size_t size() const noexcept
void map(SizeType size)
Maps the file into memory.
Reference front() noexcept
Definition SharedMemory.hpp:121
AccessMode mMode
The mode the file was mapped with.
Definition SharedMemory.hpp:66
SharedMemory(const FilePath &path, AccessMode mode=AccessMode::Read)
Creates a new SharedMemory by mapping the file given path.
AccessMode
This is used to determine whether to create a read-only or a read-write memory mapping.
Definition SharedMemory.hpp:21
void sync()
Synchronizes any dirty data not synchronized with the file.
bool valid() const noexcept
SharedMemory(SharedMemory &&other) noexcept
Creates a new SharedMemory by moving the contents of another.
SharedMemory & operator=(SharedMemory &&other) noexcept
Assigns the SharedMemory by moving the contents of another.
ConstPointer begin() const noexcept
Definition SharedMemory.hpp:160
FilePath mPath
The path of the memory mapped file.
Definition SharedMemory.hpp:52
Pointer begin() noexcept
Definition SharedMemory.hpp:157
Reference at(const SizeType index) noexcept
Definition SharedMemory.hpp:114
ConstReference front() const noexcept
Definition SharedMemory.hpp:124
SharedMemory()
Creates a new unmapped SharedMemory object.
SharedMemory & operator=(const SharedMemory &)=delete
Copy assignment of a SharedMemory is not allowed.
ConstPointer cbegin() const noexcept
Definition SharedMemory.hpp:163
SharedMemory(const FilePath &path, SizeType size, AccessMode mode=AccessMode::Read)
Creates a new SharedMemory by mapping the file given path.
SharedMemory(const SharedMemory &)=delete
Copy of a SharedMemory is not allowed.
bool empty() const noexcept
ConstReference back() const noexcept
Definition SharedMemory.hpp:130
TSharedMemory & operator=(const TSharedMemory &)=delete
Copy assignment of a TSharedMemory is not allowed.
T & back() noexcept
Definition SharedMemory.hpp:462
const T * cend() const noexcept
Definition SharedMemory.hpp:510
const T * cbegin() const noexcept
Definition SharedMemory.hpp:501
void sync()
Synchronizes any dirty data not synchronized with the file.
Definition SharedMemory.hpp:481
T * data() noexcept
Definition SharedMemory.hpp:450
T * end() noexcept
Definition SharedMemory.hpp:504
void reset()
Closes any handle and unmaps all memory.
Definition SharedMemory.hpp:491
const T * end() const noexcept
Definition SharedMemory.hpp:507
const T & back() const noexcept
Definition SharedMemory.hpp:465
const T & front() const noexcept
Definition SharedMemory.hpp:459
const T * begin() const noexcept
Definition SharedMemory.hpp:498
std::reverse_iterator< const T * > crbegin() const noexcept
Definition SharedMemory.hpp:519
std::reverse_iterator< T * > rbegin() noexcept
Definition SharedMemory.hpp:513
size_t size() const noexcept
Definition SharedMemory.hpp:468
const T & operator[](size_t i) const
Definition SharedMemory.hpp:541
std::reverse_iterator< const T * > rend() const noexcept
Definition SharedMemory.hpp:525
TSharedMemory(const FilePath &path, const SharedMemory::AccessMode mode=SharedMemory::AccessMode::Read)
Creates a new TSharedMemory by mapping the file given path.
Definition SharedMemory.hpp:430
void resize(const size_t newSize)
Resizes the array to fit at least newSize elements.
Definition SharedMemory.hpp:485
void clear() noexcept
Clears the shared memory object.
Definition SharedMemory.hpp:488
TSharedMemory(TSharedMemory &&other) noexcept=default
Creates a new TSharedMemory by moving the contents of another.
bool valid() const noexcept
Definition SharedMemory.hpp:478
T & operator[](size_t i)
Definition SharedMemory.hpp:537
TSharedMemory(const SharedMemory &)=delete
Copy of a TSharedMemory is not allowed.
std::reverse_iterator< T * > rend() noexcept
Definition SharedMemory.hpp:522
size_t capacity() const noexcept
Definition SharedMemory.hpp:471
TSharedMemory()
Creates a new unmapped TSharedMemory object.
Definition SharedMemory.hpp:425
SharedMemory sharedMemory
The underlying shared memory object.
Definition SharedMemory.hpp:418
T & front() noexcept
Definition SharedMemory.hpp:456
T * begin() noexcept
Definition SharedMemory.hpp:495
std::reverse_iterator< const T * > crend() const noexcept
Definition SharedMemory.hpp:528
const T * data() const noexcept
Definition SharedMemory.hpp:453
std::reverse_iterator< const T * > rbegin() const noexcept
Definition SharedMemory.hpp:516
bool empty() const noexcept
Definition SharedMemory.hpp:474
TSharedMemory & operator=(TSharedMemory &&other) noexcept=default
Assigns the TSharedMemory by moving the contents of another.
std::reverse_iterator< T * > rbegin() noexcept
Definition SharedMemory.hpp:377
const T * cbegin() const noexcept
Definition SharedMemory.hpp:365
constexpr size_t size() const noexcept
Definition SharedMemory.hpp:339
std::reverse_iterator< const T * > rbegin() const noexcept
Definition SharedMemory.hpp:380
T & front() noexcept
Definition SharedMemory.hpp:327
TSharedMemory(TSharedMemory &&other) noexcept=default
Creates a new TSharedMemory by moving the contents of another.
SharedMemory sharedMemory
The underlying shared memory object.
Definition SharedMemory.hpp:289
const T & front() const noexcept
Definition SharedMemory.hpp:330
const T * begin() const noexcept
Definition SharedMemory.hpp:362
const T & operator[](size_t i) const
Definition SharedMemory.hpp:405
T & operator[](size_t i)
Definition SharedMemory.hpp:401
T * begin() noexcept
Definition SharedMemory.hpp:359
constexpr size_t capacity() const noexcept
Definition SharedMemory.hpp:342
TSharedMemory & operator=(TSharedMemory &&other) noexcept=default
Assigns the TSharedMemory by moving the contents of another.
std::reverse_iterator< const T * > rend() const noexcept
Definition SharedMemory.hpp:389
T * data() noexcept
Definition SharedMemory.hpp:321
std::reverse_iterator< T * > rend() noexcept
Definition SharedMemory.hpp:386
const T * end() const noexcept
Definition SharedMemory.hpp:371
const T & back() const noexcept
Definition SharedMemory.hpp:336
TSharedMemory(const SharedMemory &)=delete
Copy of a TSharedMemory is not allowed.
const T * cend() const noexcept
Definition SharedMemory.hpp:374
TSharedMemory(const FilePath &path, const SharedMemory::AccessMode mode=SharedMemory::AccessMode::Read)
Creates a new TSharedMemory by mapping the file given path.
Definition SharedMemory.hpp:301
bool valid() const noexcept
Definition SharedMemory.hpp:349
std::reverse_iterator< const T * > crend() const noexcept
Definition SharedMemory.hpp:392
void reset()
Closes any handle and unmaps all memory.
Definition SharedMemory.hpp:355
const T * data() const noexcept
Definition SharedMemory.hpp:324
std::reverse_iterator< const T * > crbegin() const noexcept
Definition SharedMemory.hpp:383
T & back() noexcept
Definition SharedMemory.hpp:333
TSharedMemory()
Creates a new unmapped TSharedMemory object.
Definition SharedMemory.hpp:296
constexpr bool empty() const noexcept
Definition SharedMemory.hpp:345
TSharedMemory & operator=(const TSharedMemory &)=delete
Copy assignment of a TSharedMemory is not allowed.
T * end() noexcept
Definition SharedMemory.hpp:368
void sync()
Synchronizes any dirty data not synchronized with the file.
Definition SharedMemory.hpp:352
A helper class that maps a file into memory and allows accessing it as a regular C++ struct.
Definition SharedMemory.hpp:201
TSharedMemory()
Creates a new unmapped TSharedMemory object.
Definition SharedMemory.hpp:214
const T * get() const noexcept
Definition SharedMemory.hpp:242
T * operator->()
Definition SharedMemory.hpp:266
T * data() noexcept
Definition SharedMemory.hpp:245
TSharedMemory & operator=(const TSharedMemory &)=delete
Copy assignment of a TSharedMemory is not allowed.
const T * data() const noexcept
Definition SharedMemory.hpp:248
const T & operator*() const
Definition SharedMemory.hpp:275
TSharedMemory(const FilePath &path, const SharedMemory::AccessMode mode=SharedMemory::AccessMode::Read)
Creates a new TSharedMemory by mapping the file given path.
Definition SharedMemory.hpp:219
void reset()
Closes any handle and unmaps all memory.
Definition SharedMemory.hpp:258
SharedMemory sharedMemory
The underlying shared memory object.
Definition SharedMemory.hpp:207
bool valid() const noexcept
Definition SharedMemory.hpp:252
TSharedMemory(const SharedMemory &)=delete
Copy of a TSharedMemory is not allowed.
T & operator*()
Definition SharedMemory.hpp:272
TSharedMemory(TSharedMemory &&other) noexcept=default
Creates a new TSharedMemory by moving the contents of another.
T * get() noexcept
Definition SharedMemory.hpp:239
void sync()
Synchronizes any dirty data not synchronized with the file.
Definition SharedMemory.hpp:255
TSharedMemory & operator=(TSharedMemory &&other) noexcept=default
Assigns the TSharedMemory by moving the contents of another.
const T * operator->() const
Definition SharedMemory.hpp:269
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
decltype(auto) get(BezierPath::Element &element) noexcept
Decomposes a bezier path element.
Definition BezierPath.hpp:723
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25