Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TStackSentinel.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common/debug.h"
4
5#include <cstddef>
6#include <cstdint>
7#include <memory>
8
9namespace ph
10{
11
16template<std::size_t BUFFER_BYTES = 16 * 1024>
17class TStackSentinel final
18{
19public:
20 static auto makeUnique()
21 -> std::unique_ptr<TStackSentinel>;
22
25
26private:
27 static std::uint8_t genValue(std::size_t byteIdx);
28
29 std::uint8_t m_stackBuffer[BUFFER_BYTES];
30};
31
32template<std::size_t BUFFER_BYTES>
34-> std::unique_ptr<TStackSentinel>
35{
36 return std::make_unique<TStackSentinel>();
37}
38
39template<std::size_t BUFFER_BYTES>
41{
42 for(std::size_t i = 0; i < BUFFER_BYTES; ++i)
43 {
44 m_stackBuffer[i] = genValue(i);
45 }
46}
47
48template<std::size_t BUFFER_BYTES>
50{
51 for(std::size_t i = 0; i < BUFFER_BYTES; ++i)
52 {
53 if(m_stackBuffer[i] != genValue(i))
54 {
55 PH_DEBUG_BREAK();
56 }
57 }
58}
59
60template<std::size_t BUFFER_BYTES>
61inline std::uint8_t TStackSentinel<BUFFER_BYTES>::genValue(const std::size_t byteIdx)
62{
63 // Generates the pattern `BAADF00D` (bad food)
64 switch(byteIdx % 4)
65 {
66 case 0: return 0xBA;
67 case 1: return 0xAD;
68 case 2: return 0xF0;
69 case 3: return 0x0D;
70 }
71}
72
73}// end namespace ph
Definition TStackSentinel.h:18
TStackSentinel()
Definition TStackSentinel.h:40
static auto makeUnique() -> std::unique_ptr< TStackSentinel >
Definition TStackSentinel.h:33
~TStackSentinel()
Definition TStackSentinel.h:49
The root for all renderer implementations.
Definition EEngineProject.h:6