Use tables to display pattern data

This commit is contained in:
WerWolv
2020-11-15 00:46:18 +01:00
parent 30c0ce8d2c
commit 5b2dc51c07
4 changed files with 129 additions and 11 deletions

View File

@@ -47,6 +47,7 @@ namespace hex {
[[nodiscard]] const std::string& getName() const { return this->m_name; }
virtual std::string format(prv::Provider* &provider) = 0;
virtual std::string getTypeName() = 0;
private:
u64 m_offset;
@@ -67,6 +68,17 @@ namespace hex {
return hex::format("%lu (0x%08lx)", data, data);
}
std::string getTypeName() override {
switch (this->getSize()) {
case 1: return "u8";
case 2: return "u16";
case 4: return "u32";
case 8: return "u64";
case 16: return "u128";
default: return "Unsigned data";
}
}
};
class PatternDataSigned : public PatternData {
@@ -81,6 +93,17 @@ namespace hex {
return hex::format("%ld (0x%08lx)", signedData, data);
}
std::string getTypeName() override {
switch (this->getSize()) {
case 1: return "s8";
case 2: return "s16";
case 4: return "s32";
case 8: return "s64";
case 16: return "s128";
default: return "Signed data";
}
}
};
class PatternDataFloat : public PatternData {
@@ -101,6 +124,14 @@ namespace hex {
return hex::format("%f (0x%08lx)", formatData, formatData);
}
std::string getTypeName() override {
switch (this->getSize()) {
case 4: return "float";
case 8: return "double";
default: return "Floating point data";
}
}
};
class PatternDataCharacter : public PatternData {
@@ -113,6 +144,10 @@ namespace hex {
return hex::format("'%c'", character);
}
std::string getTypeName() override {
return "Character";
}
};
class PatternDataString : public PatternData {
@@ -126,6 +161,10 @@ namespace hex {
return hex::format("\"%s\"", makeDisplayable(buffer.data(), this->getSize()).c_str());
}
std::string getTypeName() override {
return "String";
}
};
class PatternDataEnum : public PatternData {
@@ -145,6 +184,10 @@ namespace hex {
return hex::format("%lu (0x%08lx) : %s::???", value, value, this->m_enumName.c_str());
}
std::string getTypeName() override {
return "enum " + this->m_enumName;
}
private:
std::string m_enumName;
std::vector<std::pair<u64, std::string>> m_enumValues;

View File

@@ -25,6 +25,7 @@ namespace hex {
private:
prv::Provider* &m_dataProvider;
std::vector<hex::PatternData*> &m_patternData;
std::vector<hex::PatternData*> m_sortedPatternData;
bool m_windowOpen = true;
};