ImHex/tests/pattern_language/include/test_patterns/test_pattern_unions.hpp

36 lines
1.0 KiB
C++
Raw Normal View History

2021-09-11 21:13:49 +00:00
#pragma once
#include "test_pattern.hpp"
namespace hex::test {
class TestPatternUnions : public TestPattern {
public:
TestPatternUnions() : TestPattern("Unions") {
2021-10-03 10:32:58 +00:00
auto testUnion = create<PatternDataUnion>("TestUnion", "testUnion", 0x200, sizeof(u128), nullptr);
2021-09-11 21:13:49 +00:00
2021-10-03 10:32:58 +00:00
auto array = create<PatternDataStaticArray>("s32", "array", 0x200, sizeof(s32[2]), nullptr);
array->setEntries(create<PatternDataSigned>("s32", "", 0x200, sizeof(s32), nullptr), 2);
auto variable = create<PatternDataUnsigned>("u128", "variable", 0x200, sizeof(u128), nullptr);
2021-09-11 21:13:49 +00:00
testUnion->setMembers({ array, variable });
addPattern(testUnion);
}
~TestPatternUnions() override = default;
[[nodiscard]]
std::string getSourceCode() const override {
return R"(
union TestUnion {
s32 array[2];
u128 variable;
};
TestUnion testUnion @ 0x200;
)";
}
};
}