Add support for reading excel packed booleans
This commit is contained in:
parent
8b6842c0e0
commit
fbe386c958
2 changed files with 34 additions and 2 deletions
|
@ -9,6 +9,7 @@ struct ExcelDataPagination;
|
||||||
|
|
||||||
struct Column {
|
struct Column {
|
||||||
std::string data;
|
std::string data;
|
||||||
|
std::string type; // for debug
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Row {
|
struct Row {
|
||||||
|
|
|
@ -27,13 +27,18 @@ struct ExcelDataRowHeader {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string readData(FILE* file, int offset) {
|
T readDataRaw(FILE* file, int offset) {
|
||||||
fseek(file, offset, SEEK_SET);
|
fseek(file, offset, SEEK_SET);
|
||||||
|
|
||||||
T value;
|
T value;
|
||||||
fread(&value, sizeof value, 1, file);
|
fread(&value, sizeof value, 1, file);
|
||||||
endianSwap(&value);
|
endianSwap(&value);
|
||||||
return std::to_string(value);
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::string readData(FILE* file, int offset) {
|
||||||
|
return std::to_string(readDataRaw<T>(file, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getEXDFilename(EXH& exh, std::string_view name, std::string_view lang, ExcelDataPagination& page) {
|
std::string getEXDFilename(EXH& exh, std::string_view name, std::string_view lang, ExcelDataPagination& page) {
|
||||||
|
@ -103,37 +108,63 @@ EXD readEXD(EXH& exh, std::string_view path, ExcelDataPagination& page) {
|
||||||
fmt::print("{}\n", string.data());
|
fmt::print("{}\n", string.data());
|
||||||
|
|
||||||
c.data = string;
|
c.data = string;
|
||||||
|
c.type = "String";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Int8:
|
case Int8:
|
||||||
c.data = readData<int8_t>(file, rowOffset + column.offset);
|
c.data = readData<int8_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Int";
|
||||||
break;
|
break;
|
||||||
case UInt8:
|
case UInt8:
|
||||||
c.data = readData<uint8_t>(file, rowOffset + column.offset);
|
c.data = readData<uint8_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Unsigned Int";
|
||||||
break;
|
break;
|
||||||
case Int16:
|
case Int16:
|
||||||
c.data = readData<int16_t>(file, rowOffset + column.offset);
|
c.data = readData<int16_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Int";
|
||||||
break;
|
break;
|
||||||
case UInt16:
|
case UInt16:
|
||||||
c.data = readData<uint16_t>(file, rowOffset + column.offset);
|
c.data = readData<uint16_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Unsigned Int";
|
||||||
break;
|
break;
|
||||||
case Int32:
|
case Int32:
|
||||||
c.data = readData<int32_t>(file, rowOffset + column.offset);
|
c.data = readData<int32_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Int";
|
||||||
break;
|
break;
|
||||||
case UInt32:
|
case UInt32:
|
||||||
c.data = readData<uint32_t>(file, rowOffset + column.offset);
|
c.data = readData<uint32_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Unsigned Int";
|
||||||
break;
|
break;
|
||||||
case Float32:
|
case Float32:
|
||||||
c.data = readData<float>(file, rowOffset + column.offset);
|
c.data = readData<float>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Float";
|
||||||
break;
|
break;
|
||||||
case Int64:
|
case Int64:
|
||||||
c.data = readData<int64_t>(file, rowOffset + column.offset);
|
c.data = readData<int64_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Int";
|
||||||
break;
|
break;
|
||||||
case UInt64:
|
case UInt64:
|
||||||
c.data = readData<uint64_t>(file, rowOffset + column.offset);
|
c.data = readData<uint64_t>(file, rowOffset + column.offset);
|
||||||
|
c.type = "Unsigned Int";
|
||||||
|
break;
|
||||||
|
case PackedBool0:
|
||||||
|
case PackedBool1:
|
||||||
|
case PackedBool2:
|
||||||
|
case PackedBool3:
|
||||||
|
case PackedBool4:
|
||||||
|
case PackedBool5:
|
||||||
|
case PackedBool6:
|
||||||
|
case PackedBool7: {
|
||||||
|
int shift = (int)column.type - (int)PackedBool0;
|
||||||
|
int bit = 1 << shift;
|
||||||
|
int32_t data = readDataRaw<int32_t>(file, rowOffset + column.offset);
|
||||||
|
c.data = std::to_string((data & bit) == bit);
|
||||||
|
c.type = "Boolean";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
c.data = "undefined";
|
c.data = "undefined";
|
||||||
|
c.type = "Unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue