MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_array_2d.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_ARRAY_2D_H_1746562234
12#define INCGUARD_MGL_ARRAY_2D_H_1746562234
13
14#include <memory>
15#include <type_traits>
16#include <utility>
17
22
23namespace MGL
24{
25/* ------------------------------------------------------------------------- */
30/* ------------------------------------------------------------------------- */
31template <class ValueType, class IndexType = size_t>
33{
34public:
35 // 配列の要素はデフォルト構築可能でなければならない
36 static_assert(std::is_default_constructible_v<ValueType>, "Array2D element must be constructible by default.");
37
38 // インデックスは整数型である必要がある
39 static_assert(std::is_integral_v<IndexType>, "IndexType must be integral value.");
40
41 // コピーは禁止
42 Array2D(Array2D &) = delete;
43 Array2D &operator=(Array2D &) = delete;
44
45 /* ------------------------------------------------------------------------- */
50 /* ------------------------------------------------------------------------- */
51 Array2D(Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
52 : Array2D(0, 0, clearMode)
53 {
54 }
55
56 /* ------------------------------------------------------------------------- */
63 /* ------------------------------------------------------------------------- */
64 Array2D(IndexType width, IndexType height, Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
65 {
66 Allocate(width, height, clearMode);
67 }
68
69 /* ------------------------------------------------------------------------- */
77 /* ------------------------------------------------------------------------- */
78 Array2D(IndexType width, IndexType height, const ValueType &invalidValue, Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
79 {
80 Allocate(width, height, clearMode);
81 SetInvalidValue(invalidValue);
82 }
83
84 /* ------------------------------------------------------------------------- */
92 /* ------------------------------------------------------------------------- */
93 Array2D(IndexType width, IndexType height, ValueType &&invalidValue, Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
94 {
95 Allocate(width, height, clearMode);
96 SetInvalidValue(std::move(invalidValue));
97 }
98
99 /* ------------------------------------------------------------------------- */
104 /* ------------------------------------------------------------------------- */
105 Array2D(Array2D &&rhs) noexcept
106 {
107 *this = std::move(rhs);
108 }
109
110 /* ------------------------------------------------------------------------- */
115 /* ------------------------------------------------------------------------- */
116 Array2D &operator=(Array2D &&rhs) noexcept
117 {
118 Deallocate();
119
120 // NOLINTBEGIN(cppcoreguidelines-prefer-member-initializer) : 上のDeallocate()が呼べなくなるので無理
121 _width = rhs._width;
122 _height = rhs._height;
123 _arraySize = rhs._arraySize;
124 _top = rhs._top;
125 _tail = rhs._tail;
126 // NOLINTEND(cppcoreguidelines-prefer-member-initializer)
127
128 rhs._width = 0;
129 rhs._height = 0;
130 rhs._arraySize = 0;
131 rhs._top = nullptr;
132 rhs._tail = nullptr;
133
134 return *this;
135 }
136
137 /* ------------------------------------------------------------------------- */
141 /* ------------------------------------------------------------------------- */
142 ~Array2D() noexcept
143 {
144 Deallocate();
145 }
146
147 /* ------------------------------------------------------------------------- */
156 /* ------------------------------------------------------------------------- */
157 bool New(IndexType width, IndexType height, Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
158 {
159 // 末尾(無効値)が存在している場合はそれを保つように生成
160 if (_tail != nullptr)
161 {
162 auto invalidValue = std::move(*_tail); // アロケート中に消えるので別のメモリ空間に移動しておく
163 if (Allocate(width, height, clearMode))
164 {
165 SetInvalidValue(std::move(invalidValue));
166 return true;
167 }
168 return false;
169 }
170 // 末尾が存在していない場合は普通に生成
171 else
172 {
173 // Note: 実はここには到達しない(コンストラクタがアロケートして無効値も生成されるため)
174 return Allocate(width, height, clearMode);
175 }
176 }
177
178 /* ------------------------------------------------------------------------- */
185 /* ------------------------------------------------------------------------- */
186 bool Renew(Memory::ClearMode clearMode = Memory::ClearMode::Auto) noexcept
187 {
188 return New(_width, _height, clearMode);
189 }
190
191 /* ------------------------------------------------------------------------- */
196 /* ------------------------------------------------------------------------- */
197 constexpr void Fill(const ValueType &value) noexcept
198 {
199 for (auto *e = begin(); e != end(); ++e)
200 {
201 *e = value;
202 }
203 }
204
205 /* ------------------------------------------------------------------------- */
212 /* ------------------------------------------------------------------------- */
213 [[nodiscard]] static constexpr std::pair<IndexType, IndexType> MakePair(IndexType x, IndexType y) noexcept
214 {
215 return {x, y};
216 }
217
218 /* ------------------------------------------------------------------------- */
225 /* ------------------------------------------------------------------------- */
226 [[nodiscard]] constexpr const ValueType &Get(IndexType x, IndexType y) const noexcept
227 {
228 return _top[GetIndex(x, y)];
229 }
230
231 /* ------------------------------------------------------------------------- */
237 /* ------------------------------------------------------------------------- */
238 [[nodiscard]] const ValueType &Get(const std::pair<IndexType, IndexType> &pair) const noexcept
239 {
240 return Get(pair.first, pair.second);
241 }
242
243#if __cplusplus >= 202211L // 添字演算子の多次元サポートはC++23以降で利用可能
244 /* ------------------------------------------------------------------------- */
251 /* ------------------------------------------------------------------------- */
252 [[nodiscard]] const ValueType &operator[](IndexType x, IndexType y) const noexcept
253 {
254 return Get(x, y);
255 }
256#endif
257
258 /* ------------------------------------------------------------------------- */
264 /* ------------------------------------------------------------------------- */
265 [[nodiscard]] const ValueType &operator[](const std::pair<IndexType, IndexType> &pair) const noexcept
266 {
267 return Get(pair.first, pair.second);
268 }
269
270 /* ------------------------------------------------------------------------- */
277 /* ------------------------------------------------------------------------- */
278 [[nodiscard]] constexpr ValueType *GetPtr(IndexType x, IndexType y) noexcept
279 {
280 auto index = GetIndex(x, y);
281 if (index >= _arraySize)
282 {
283 return nullptr;
284 }
285
286 return &_top[index];
287 }
288
289 /* ------------------------------------------------------------------------- */
295 /* ------------------------------------------------------------------------- */
296 [[nodiscard]] constexpr ValueType *GetPtr(const std::pair<IndexType, IndexType> &pair) noexcept
297 {
298 return GetPtr(pair.first, pair.second);
299 }
300
301 /* ------------------------------------------------------------------------- */
310 /* ------------------------------------------------------------------------- */
311 constexpr bool Set(IndexType x, IndexType y, const ValueType &value) noexcept
312 {
313 if (auto *e = GetPtr(x, y); e != nullptr)
314 {
315 *e = value;
316 return true;
317 }
318
319 return false;
320 }
321
322 /* ------------------------------------------------------------------------- */
330 /* ------------------------------------------------------------------------- */
331 constexpr bool Set(const std::pair<IndexType, IndexType> &pair, const ValueType &value) noexcept
332 {
333 return Set(pair.first, pair.second, value);
334 }
335
336 /* ------------------------------------------------------------------------- */
345 /* ------------------------------------------------------------------------- */
346 constexpr bool Set(IndexType x, IndexType y, const ValueType &&value) noexcept
347 {
348 if (auto *e = GetPtr(x, y); e != nullptr)
349 {
350 *e = std::move(value);
351 return true;
352 }
353
354 return false;
355 }
356
357 /* ------------------------------------------------------------------------- */
365 /* ------------------------------------------------------------------------- */
366 constexpr bool Set(const std::pair<IndexType, IndexType> &pair, const ValueType &&value) noexcept
367 {
368 return Set(pair.first, pair.second, std::forward<ValueType>(value));
369 }
370
371 /* ------------------------------------------------------------------------- */
380 /* ------------------------------------------------------------------------- */
381 template <class Body>
382 constexpr bool Write(IndexType x, IndexType y, Body body) noexcept
383 {
384 if (auto *e = GetPtr(x, y); e != nullptr)
385 {
386 if constexpr (std::is_invocable_r_v<void, decltype(body), ValueType &>)
387 {
388 body(*e);
389 return true;
390 }
391 else
392 {
393 static_assert(std::false_type::value, "Write function is not matching arguments.");
394 return false;
395 }
396 }
397
398 return false;
399 }
400
401 /* ------------------------------------------------------------------------- */
409 /* ------------------------------------------------------------------------- */
410 template <class Body>
411 constexpr bool Write(const std::pair<IndexType, IndexType> &pair, Body body) noexcept
412 {
413 return Write(pair.first, pair.second, body);
414 }
415
416 /* ------------------------------------------------------------------------- */
422 /* ------------------------------------------------------------------------- */
423 template <class LoopBody>
424 constexpr void ForEach(LoopBody body) noexcept
425 {
426 for (IndexType y = 0; y < _height; ++y)
427 {
428 for (IndexType x = 0; x < _width; ++x)
429 {
430 if (!InvokeLoopBody(body, x, y))
431 {
432 return;
433 }
434 }
435 }
436 }
437
438 /* ------------------------------------------------------------------------- */
444 /* ------------------------------------------------------------------------- */
445 template <class LoopBody>
446 constexpr void ForEach(LoopBody body) const noexcept
447 {
448 for (IndexType y = 0; y < _height; ++y)
449 {
450 for (IndexType x = 0; x < _width; ++x)
451 {
452 if (!InvokeLoopBody(body, x, y))
453 {
454 return;
455 }
456 }
457 }
458 }
459
460 /* ------------------------------------------------------------------------- */
470 /* ------------------------------------------------------------------------- */
471 template <class LoopBody>
472 constexpr void ForRange(IndexType beginX, IndexType beginY, IndexType endX, IndexType endY, LoopBody body) noexcept
473 {
474 if (_arraySize == 0)
475 {
476 return;
477 }
478
479 Range<IndexType> rangeX(
480 std::clamp(beginX, static_cast<IndexType>(0), GetWidth() - 1),
481 std::clamp(endX, static_cast<IndexType>(0), GetWidth() - 1));
482
483 Range<IndexType> rangeY(
484 std::clamp(beginY, static_cast<IndexType>(0), GetHeight() - 1),
485 std::clamp(endY, static_cast<IndexType>(0), GetHeight() - 1));
486
487 for (auto y = rangeY.Begin(); rangeY.Contains(y); y = rangeY.Next(y))
488 {
489 for (auto x = rangeX.Begin(); rangeX.Contains(x); x = rangeX.Next(x))
490 {
491 if (!InvokeLoopBody(body, x, y))
492 {
493 return;
494 }
495 }
496 }
497 }
498
499 /* ------------------------------------------------------------------------- */
507 /* ------------------------------------------------------------------------- */
508 template <class LoopBody>
509 constexpr void ForRange(
510 const std::pair<IndexType, IndexType> &begin,
511 const std::pair<IndexType, IndexType> &end,
512 LoopBody body) noexcept
513 {
514 ForRange(begin.first, begin.second, end.first, end.second, body);
515 }
516
517 /* ------------------------------------------------------------------------- */
527 /* ------------------------------------------------------------------------- */
528 template <class LoopBody>
529 constexpr void ForRange(IndexType beginX, IndexType beginY, IndexType endX, IndexType endY, LoopBody body) const noexcept
530 {
531 if (_arraySize == 0)
532 {
533 return;
534 }
535
536 Range<IndexType> rangeX(
537 std::clamp(beginX, 0, GetWidth() - 1),
538 std::clamp(endX, 0, GetWidth() - 1));
539
540 Range<IndexType> rangeY(
541 std::clamp(beginY, 0, GetHeight() - 1),
542 std::clamp(endY, 0, GetHeight() - 1));
543
544 for (auto y = rangeY.Begin(); rangeY.Contains(y); y = rangeY.Next(y))
545 {
546 for (auto x = rangeX.Begin(); rangeX.Contains(x); x = rangeX.Next(x))
547 {
548 if (!InvokeLoopBody(body, x, y))
549 {
550 return;
551 }
552 }
553 }
554 }
555
556 /* ------------------------------------------------------------------------- */
564 /* ------------------------------------------------------------------------- */
565 template <class LoopBody>
566 constexpr void ForRange(
567 const std::pair<IndexType, IndexType> &begin,
568 const std::pair<IndexType, IndexType> &end,
569 LoopBody body) const noexcept
570 {
571 ForRange(begin.first, begin.second, end.first, end.second, body);
572 }
573
574 /* ------------------------------------------------------------------------- */
581 /* ------------------------------------------------------------------------- */
582 [[nodiscard]] constexpr bool Contains(const ValueType &element) const noexcept
583 {
584 return Contains(std::addressof(element));
585 }
586
587 /* ------------------------------------------------------------------------- */
594 /* ------------------------------------------------------------------------- */
595 [[nodiscard]] constexpr bool Contains(const ValueType *element) const noexcept
596 {
597 // Note:
598 // ValueType型の実体をを内包するValueType型は作れないはずなので、
599 // 各要素のアドレスと一致するかのチェックは不要なはず。
600
601 auto topAddress = reinterpret_cast<uintptr_t>(_top);
602 auto elemAddress = reinterpret_cast<uintptr_t>(element);
603 auto tailAddress = reinterpret_cast<uintptr_t>(_tail);
604
605 return (topAddress <= elemAddress) && (elemAddress < tailAddress);
606 }
607
608 /* ------------------------------------------------------------------------- */
613 /* ------------------------------------------------------------------------- */
614 constexpr void SetInvalidValue(const ValueType &value) noexcept
615 {
616 if (_tail != nullptr)
617 {
618 *_tail = value;
619 }
620 }
621
622 /* ------------------------------------------------------------------------- */
627 /* ------------------------------------------------------------------------- */
628 constexpr void SetInvalidValue(ValueType &&value) noexcept
629 {
630 if (_tail != nullptr)
631 {
632 *_tail = std::move(value);
633 }
634 }
635
636 /* ------------------------------------------------------------------------- */
641 /* ------------------------------------------------------------------------- */
642 [[nodiscard]] constexpr IndexType GetWidth() const noexcept
643 {
644 return _width;
645 }
646
647 /* ------------------------------------------------------------------------- */
652 /* ------------------------------------------------------------------------- */
653 [[nodiscard]] constexpr IndexType GetHeight() const noexcept
654 {
655 return _height;
656 }
657
658 /* ------------------------------------------------------------------------- */
663 /* ------------------------------------------------------------------------- */
664 [[nodiscard]] constexpr size_t GetArraySize() const noexcept
665 {
666 return _arraySize;
667 }
668
669 /* ------------------------------------------------------------------------- */
674 /* ------------------------------------------------------------------------- */
675 [[nodiscard]] constexpr ValueType *begin() const noexcept
676 {
677 return _top;
678 }
679
680 /* ------------------------------------------------------------------------- */
685 /* ------------------------------------------------------------------------- */
686 [[nodiscard]] constexpr ValueType *end() const noexcept
687 {
688 return _tail;
689 }
690
691 /* ------------------------------------------------------------------------- */
696 /* ------------------------------------------------------------------------- */
697 [[nodiscard]] constexpr const ValueType *cbegin() const noexcept
698 {
699 return _top;
700 }
701
702 /* ------------------------------------------------------------------------- */
707 /* ------------------------------------------------------------------------- */
708 [[nodiscard]] constexpr const ValueType *cend() const noexcept
709 {
710 return _tail;
711 }
712
713private:
714 /* ------------------------------------------------------------------------- */
723 /* ------------------------------------------------------------------------- */
724 bool Allocate(IndexType width, IndexType height, Memory::ClearMode clearMode) noexcept
725 {
726 // IndexTypeが符号付きの場合、負の値を0に補正する
727 if constexpr (std::is_signed_v<IndexType>)
728 {
729 width = std::max(0, width);
730 height = std::max(0, height);
731 }
732
733 // 行または列のサイズに0が指定されている場合はサイズ0の配列とみなす
734 if ((width == 0) || (height == 0))
735 {
736 width = height = 0;
737 }
738 auto arraySize = static_cast<size_t>(width) * static_cast<size_t>(height);
739
740 // 生成済みかつ同サイズであればアロケートを省略
741 if ((_top != nullptr) && (_arraySize == arraySize))
742 {
743 // 全てのデストラクタを呼び出す
744 std::destroy_n(_top, _arraySize + 1);
745
746 // メモリ領域をクリア
747 _top = Memory::Utility::InitializeArrayBuffer<ValueType>(_top, _arraySize + 1, clearMode);
748 }
749 // 未生成、またはサイズが異なる場合は一旦削除して際生成
750 else
751 {
752 // 一旦削除
753 Deallocate();
754
755 // アロケータからメモリを確保
756 const auto size = sizeof(ValueType) * (arraySize + 1);
757 auto *ptr = Memory::Allocate(size);
758 MGL_ASSERT(ptr, "Memory allocation failed.");
759 if (ptr == nullptr)
760 {
761 return false;
762 }
763
764 // メモリ領域をクリア
765 _top = Memory::Utility::InitializeArrayBuffer<ValueType>(ptr, arraySize + 1, clearMode);
766
767 // 確保したメモリリソースをもとに各メンバを初期化
768 _tail = std::addressof(_top[arraySize]);
769 _width = width;
770 _height = height;
771 _arraySize = arraySize;
772 }
773
774 return true;
775 }
776
777 /* ------------------------------------------------------------------------- */
781 /* ------------------------------------------------------------------------- */
782 void Deallocate() noexcept
783 {
784 if (_top != nullptr)
785 {
786 std::destroy_n(_top, _arraySize + 1);
787 Memory::Deallocate(_top);
788 _top = _tail = nullptr;
789 _arraySize = 0;
790 }
791 }
792
793 /* ------------------------------------------------------------------------- */
800 /* ------------------------------------------------------------------------- */
801 [[nodiscard]] constexpr size_t GetIndex(IndexType x, IndexType y) const noexcept
802 {
803 // 符号付きの場合、どちらか一方が負の値だったら失敗
804 if constexpr (std::is_signed_v<IndexType>)
805 {
806 if (x < 0 || y < 0)
807 {
808 return _arraySize;
809 }
810 }
811
812 // どちらか一方が指定サイズより大きければ失敗
813 if (x >= _width)
814 {
815 return _arraySize;
816 }
817 if (y >= _height)
818 {
819 return _arraySize;
820 }
821
822 return static_cast<size_t>(y * _width + x);
823 }
824
825 /* ------------------------------------------------------------------------- */
835 /* ------------------------------------------------------------------------- */
836 template <class LoopBody>
837 constexpr bool InvokeLoopBody(LoopBody body, IndexType x, IndexType y) noexcept
838 {
839 // 座標付き、中断あり
840 if constexpr (std::is_invocable_r_v<bool, decltype(body), IndexType, IndexType, ValueType &>)
841 {
842 return body(x, y, _top[GetIndex(x, y)]);
843 }
844 // 座標付き、中断なし
845 else if constexpr (std::is_invocable_r_v<void, decltype(body), IndexType, IndexType, ValueType &>)
846 {
847 body(x, y, _top[GetIndex(x, y)]);
848 return true;
849 }
850 // 座標なし、中断あり
851 else if constexpr (std::is_invocable_r_v<bool, decltype(body), ValueType &>)
852 {
853 return body(_top[GetIndex(x, y)]);
854 }
855 // 座標なし、中断なし
856 else if constexpr (std::is_invocable_r_v<void, decltype(body), ValueType &>)
857 {
858 body(_top[GetIndex(x, y)]);
859 return true;
860 }
861 // それ以外は不適格
862 else
863 {
864 static_assert(std::false_type::value, "Loop body is not matching arguments.");
865 return false;
866 }
867 }
868
869 /* ------------------------------------------------------------------------- */
879 /* ------------------------------------------------------------------------- */
880 template <class LoopBody>
881 constexpr bool InvokeLoopBody(LoopBody body, IndexType x, IndexType y) const noexcept
882 {
883 // 座標付き、中断あり
884 if constexpr (std::is_invocable_r_v<bool, decltype(body), IndexType, IndexType, const ValueType &>)
885 {
886 return body(x, y, _top[GetIndex(x, y)]);
887 }
888 // 座標付き、中断なし
889 else if constexpr (std::is_invocable_r_v<void, decltype(body), IndexType, IndexType, const ValueType &>)
890 {
891 body(x, y, _top[GetIndex(x, y)]);
892 return true;
893 }
894 // 座標なし、中断あり
895 else if constexpr (std::is_invocable_r_v<bool, decltype(body), const ValueType &>)
896 {
897 return body(_top[GetIndex(x, y)]);
898 }
899 // 座標なし、中断なし
900 else if constexpr (std::is_invocable_r_v<void, decltype(body), const ValueType &>)
901 {
902 body(_top[GetIndex(x, y)]);
903 return true;
904 }
905 // それ以外は不適格
906 else
907 {
908 static_assert(std::false_type::value, "Loop body is not matching arguments.");
909 return false;
910 }
911 }
912
913 IndexType _width{0};
914 IndexType _height{0};
915 size_t _arraySize{0};
916 ValueType *_top{nullptr};
917 ValueType *_tail{nullptr};
918};
919} // namespace MGL
920
921#endif // INCGUARD_MGL_ARRAY_2D_H_1746562234
922
923// vim: et ts=4 sw=4 sts=4
動的2次元配列クラス
Definition mgl_array_2d.h:33
Array2D & operator=(Array2D &&rhs) noexcept
ムーブ代入
Definition mgl_array_2d.h:116
bool Renew(Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
配列を同じサイズで構築し直す
Definition mgl_array_2d.h:186
constexpr ValueType * begin() const noexcept
先頭の要素を取得
Definition mgl_array_2d.h:675
constexpr IndexType GetHeight() const noexcept
配列のY方向の最大値を取得
Definition mgl_array_2d.h:653
static constexpr std::pair< IndexType, IndexType > MakePair(IndexType x, IndexType y) noexcept
ペアの生成
Definition mgl_array_2d.h:213
constexpr const ValueType * cbegin() const noexcept
先頭の要素をconstで取得
Definition mgl_array_2d.h:697
bool New(IndexType width, IndexType height, Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
配列の生成
Definition mgl_array_2d.h:157
constexpr void ForRange(IndexType beginX, IndexType beginY, IndexType endX, IndexType endY, LoopBody body) noexcept
範囲を指定して要素にアクセス
Definition mgl_array_2d.h:472
constexpr IndexType GetWidth() const noexcept
配列のX方向の最大値を取得
Definition mgl_array_2d.h:642
constexpr ValueType * GetPtr(IndexType x, IndexType y) noexcept
書き込み可能な要素へのポインタを取得
Definition mgl_array_2d.h:278
constexpr size_t GetArraySize() const noexcept
配列全体のサイズを取得
Definition mgl_array_2d.h:664
constexpr bool Set(const std::pair< IndexType, IndexType > &pair, const ValueType &&value) noexcept
要素に値を設定
Definition mgl_array_2d.h:366
constexpr bool Set(IndexType x, IndexType y, const ValueType &&value) noexcept
要素に値を設定
Definition mgl_array_2d.h:346
Array2D(IndexType width, IndexType height, ValueType &&invalidValue, Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
コンストラクタ
Definition mgl_array_2d.h:93
constexpr void ForEach(LoopBody body) const noexcept
全ての要素へ読み取り専用でアクセス
Definition mgl_array_2d.h:446
constexpr void ForRange(const std::pair< IndexType, IndexType > &begin, const std::pair< IndexType, IndexType > &end, LoopBody body) noexcept
範囲を指定して要素にアクセス
Definition mgl_array_2d.h:509
constexpr void Fill(const ValueType &value) noexcept
全ての要素を指定値で書き込む
Definition mgl_array_2d.h:197
constexpr bool Contains(const ValueType *element) const noexcept
指定した要素が範囲内に含まれているかを取得
Definition mgl_array_2d.h:595
constexpr void ForRange(IndexType beginX, IndexType beginY, IndexType endX, IndexType endY, LoopBody body) const noexcept
範囲を指定して読み取り専用で要素にアクセス
Definition mgl_array_2d.h:529
constexpr bool Set(IndexType x, IndexType y, const ValueType &value) noexcept
要素に値を設定
Definition mgl_array_2d.h:311
const ValueType & operator[](const std::pair< IndexType, IndexType > &pair) const noexcept
添字演算子による要素の取得
Definition mgl_array_2d.h:265
constexpr bool Set(const std::pair< IndexType, IndexType > &pair, const ValueType &value) noexcept
要素に値を設定
Definition mgl_array_2d.h:331
constexpr void ForRange(const std::pair< IndexType, IndexType > &begin, const std::pair< IndexType, IndexType > &end, LoopBody body) const noexcept
範囲を指定して読み取り専用で要素にアクセス
Definition mgl_array_2d.h:566
constexpr void SetInvalidValue(ValueType &&value) noexcept
無効値の設定
Definition mgl_array_2d.h:628
constexpr ValueType * end() const noexcept
末尾の要素を取得
Definition mgl_array_2d.h:686
constexpr bool Write(IndexType x, IndexType y, Body body) noexcept
値の書き込み
Definition mgl_array_2d.h:382
constexpr const ValueType * cend() const noexcept
末尾の要素をconstで取得
Definition mgl_array_2d.h:708
constexpr bool Write(const std::pair< IndexType, IndexType > &pair, Body body) noexcept
値の書き込み
Definition mgl_array_2d.h:411
~Array2D() noexcept
デストラクタ
Definition mgl_array_2d.h:142
Array2D(Array2D &&rhs) noexcept
ムーブコンストラクタ
Definition mgl_array_2d.h:105
constexpr void SetInvalidValue(const ValueType &value) noexcept
無効値の設定
Definition mgl_array_2d.h:614
constexpr void ForEach(LoopBody body) noexcept
全ての要素へのアクセス
Definition mgl_array_2d.h:424
constexpr bool Contains(const ValueType &element) const noexcept
指定した要素が範囲内に含まれているかを取得
Definition mgl_array_2d.h:582
const ValueType & Get(const std::pair< IndexType, IndexType > &pair) const noexcept
要素の取得
Definition mgl_array_2d.h:238
constexpr ValueType * GetPtr(const std::pair< IndexType, IndexType > &pair) noexcept
書き込み可能な要素へのポインタを取得
Definition mgl_array_2d.h:296
Array2D(IndexType width, IndexType height, const ValueType &invalidValue, Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
コンストラクタ
Definition mgl_array_2d.h:78
Array2D(Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
コンストラクタ
Definition mgl_array_2d.h:51
Array2D(IndexType width, IndexType height, Memory::ClearMode clearMode=Memory::ClearMode::Auto) noexcept
コンストラクタ
Definition mgl_array_2d.h:64
constexpr const ValueType & Get(IndexType x, IndexType y) const noexcept
要素の取得
Definition mgl_array_2d.h:226
値の範囲を表現するクラス
Definition mgl_range.h:28
constexpr bool Contains(T value) const noexcept
指定された値が範囲内に含まれているかを取得
Definition mgl_range.h:181
constexpr T Next(T value) const noexcept
指定された値の次の値を取得
Definition mgl_range.h:142
constexpr T Begin() const noexcept
開始値を取得
Definition mgl_range.h:56
ValueType
値のタイプ
Definition mgl_achievement_defs.h:33
MGL メモリ関連
MGL メモリユーティリティ
ClearMode
クリアモード
Definition mgl_memory_utility.h:23
MGL 値の範囲を表現するクラス
MGL デバッグ用マクロ
#define MGL_ASSERT(...)
アサート用マクロ
Definition mgl_system_debug_macro.h:88