diff options
-rw-r--r-- | src/common/DataStores/DB2FileLoader.cpp | 121 | ||||
-rw-r--r-- | src/common/DataStores/DB2FileLoader.h | 16 | ||||
-rw-r--r-- | src/common/DataStores/DB2FileSystemSource.h | 4 | ||||
-rw-r--r-- | src/tools/extractor_common/DB2CascFileSource.cpp | 2 | ||||
-rw-r--r-- | src/tools/extractor_common/DB2CascFileSource.h | 6 |
5 files changed, 105 insertions, 44 deletions
diff --git a/src/common/DataStores/DB2FileLoader.cpp b/src/common/DataStores/DB2FileLoader.cpp index 1254b98992b..2c472e66dd6 100644 --- a/src/common/DataStores/DB2FileLoader.cpp +++ b/src/common/DataStores/DB2FileLoader.cpp @@ -23,6 +23,7 @@ #include <limits> #include <sstream> #include <system_error> +#include <utility> #include <cstring> enum class DB2ColumnCompression : uint32 @@ -146,14 +147,18 @@ int32 DB2FileLoadInfo::GetFieldIndexByMetaIndex(uint32 metaIndex) const return ourIndex; } -DB2FileSource::~DB2FileSource() -{ -} +DB2FileSource::DB2FileSource() = default; +DB2FileSource::~DB2FileSource() = default; class DB2FileLoaderImpl { public: - virtual ~DB2FileLoaderImpl() { } + DB2FileLoaderImpl() = default; + DB2FileLoaderImpl(DB2FileLoaderImpl const& other) = delete; + DB2FileLoaderImpl(DB2FileLoaderImpl&& other) noexcept = delete; + DB2FileLoaderImpl& operator=(DB2FileLoaderImpl const& other) = delete; + DB2FileLoaderImpl& operator=(DB2FileLoaderImpl&& other) noexcept = delete; + virtual ~DB2FileLoaderImpl() = default; virtual void LoadColumnData(std::unique_ptr<DB2SectionHeader[]> sections, std::unique_ptr<DB2FieldEntry[]> fields, std::unique_ptr<DB2ColumnMeta[]> columnMeta, std::unique_ptr<std::unique_ptr<DB2PalletValue[]>[]> palletValues, std::unique_ptr<std::unique_ptr<DB2PalletValue[]>[]> palletArrayValues, std::unique_ptr<std::unordered_map<uint32, uint32>[]> commonValues) = 0; @@ -186,6 +191,7 @@ private: virtual float RecordGetFloat(uint8 const* record, uint32 field, uint32 arrayIndex) const = 0; virtual char const* RecordGetString(uint8 const* record, uint32 field, uint32 arrayIndex) const = 0; virtual std::size_t* RecordCreateDetachedFieldOffsets(std::size_t* oldOffsets) const = 0; + virtual std::size_t* RecordCopyDetachedFieldOffsets(std::size_t* oldOffsets) const = 0; virtual void RecordDestroyFieldOffsets(std::size_t*& fieldOffsets) const = 0; }; @@ -193,6 +199,10 @@ class DB2FileLoaderRegularImpl final : public DB2FileLoaderImpl { public: DB2FileLoaderRegularImpl(char const* fileName, DB2FileLoadInfo const* loadInfo, DB2Header const* header); + DB2FileLoaderRegularImpl(DB2FileLoaderRegularImpl const& other) = delete; + DB2FileLoaderRegularImpl(DB2FileLoaderRegularImpl&& other) noexcept = delete; + DB2FileLoaderRegularImpl& operator=(DB2FileLoaderRegularImpl const& other) = delete; + DB2FileLoaderRegularImpl& operator=(DB2FileLoaderRegularImpl&& other) noexcept = delete; ~DB2FileLoaderRegularImpl(); void LoadColumnData(std::unique_ptr<DB2SectionHeader[]> sections, std::unique_ptr<DB2FieldEntry[]> fields, std::unique_ptr<DB2ColumnMeta[]> columnMeta, @@ -232,6 +242,7 @@ private: uint64 RecordGetPackedValue(uint8 const* packedRecordData, uint32 bitWidth, uint32 bitOffset) const; uint16 GetFieldOffset(uint32 field) const; std::size_t* RecordCreateDetachedFieldOffsets(std::size_t* oldOffsets) const override; + std::size_t* RecordCopyDetachedFieldOffsets(std::size_t* oldOffsets) const override; void RecordDestroyFieldOffsets(std::size_t*& fieldOffsets) const override; char const* _fileName; @@ -253,6 +264,10 @@ class DB2FileLoaderSparseImpl final : public DB2FileLoaderImpl { public: DB2FileLoaderSparseImpl(char const* fileName, DB2FileLoadInfo const* loadInfo, DB2Header const* header, DB2FileSource* source); + DB2FileLoaderSparseImpl(DB2FileLoaderSparseImpl const& other) = delete; + DB2FileLoaderSparseImpl(DB2FileLoaderSparseImpl&& other) noexcept = delete; + DB2FileLoaderSparseImpl& operator=(DB2FileLoaderSparseImpl const& other) = delete; + DB2FileLoaderSparseImpl& operator=(DB2FileLoaderSparseImpl&& other) noexcept = delete; ~DB2FileLoaderSparseImpl(); void LoadColumnData(std::unique_ptr<DB2SectionHeader[]> sections, std::unique_ptr<DB2FieldEntry[]> fields, std::unique_ptr<DB2ColumnMeta[]> columnMeta, @@ -291,12 +306,10 @@ private: uint16 GetFieldOffset(uint32 field, uint32 arrayIndex) const; uint16 GetFieldSize(uint32 field) const; std::size_t* RecordCreateDetachedFieldOffsets(std::size_t* oldOffsets) const override; + std::size_t* RecordCopyDetachedFieldOffsets(std::size_t* oldOffsets) const override; void RecordDestroyFieldOffsets(std::size_t*& fieldOffsets) const override; void CalculateAndStoreFieldOffsets(uint8 const* rawRecord) const; -#pragma pack(push, 1) -#pragma pack(pop) - char const* _fileName; DB2FileLoadInfo const* _loadInfo; DB2Header const* _header; @@ -364,11 +377,9 @@ void DB2FileLoaderRegularImpl::SetAdditionalData(std::vector<uint32> idTable, st _parentIndexes = std::move(parentIndexes); } -DB2FileLoaderRegularImpl::~DB2FileLoaderRegularImpl() -{ -} +DB2FileLoaderRegularImpl::~DB2FileLoaderRegularImpl() = default; -static char const* const nullStr = ""; +static char const* const EmptyDb2String = ""; char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**& indexTable) { @@ -411,7 +422,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**& uint32 fieldIndex = 0; if (!_loadInfo->Meta->HasIndexFieldInData()) { - *((uint32*)(&dataTable[offset])) = indexVal; + *reinterpret_cast<uint32*>(&dataTable[offset]) = indexVal; offset += 4; ++fieldIndex; } @@ -423,33 +434,33 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**& switch (_loadInfo->Fields[fieldIndex].Type) { case FT_FLOAT: - *((float*)(&dataTable[offset])) = RecordGetFloat(rawRecord, x, z); + *reinterpret_cast<float*>(&dataTable[offset]) = RecordGetFloat(rawRecord, x, z); offset += 4; break; case FT_INT: - *((uint32*)(&dataTable[offset])) = RecordGetVarInt<uint32>(rawRecord, x, z); + *reinterpret_cast<uint32*>(&dataTable[offset]) = RecordGetVarInt<uint32>(rawRecord, x, z); offset += 4; break; case FT_BYTE: - *((uint8*)(&dataTable[offset])) = RecordGetUInt8(rawRecord, x, z); + *reinterpret_cast<uint8*>(&dataTable[offset]) = RecordGetUInt8(rawRecord, x, z); offset += 1; break; case FT_SHORT: - *((uint16*)(&dataTable[offset])) = RecordGetUInt16(rawRecord, x, z); + *reinterpret_cast<uint16*>(&dataTable[offset]) = RecordGetUInt16(rawRecord, x, z); offset += 2; break; case FT_LONG: - *((uint64*)(&dataTable[offset])) = RecordGetUInt64(rawRecord, x, z); + *reinterpret_cast<uint64*>(&dataTable[offset]) = RecordGetUInt64(rawRecord, x, z); offset += 8; break; case FT_STRING: - for (char const*& localeStr : ((LocalizedString*)(&dataTable[offset]))->Str) - localeStr = nullStr; + for (char const*& localeStr : reinterpret_cast<LocalizedString*>(&dataTable[offset])->Str) + localeStr = EmptyDb2String; offset += sizeof(LocalizedString); break; case FT_STRING_NOT_LOCALIZED: - *(char const**)(&dataTable[offset]) = nullStr; + *reinterpret_cast<char const**>(&dataTable[offset]) = EmptyDb2String; offset += sizeof(char*); break; default: @@ -468,15 +479,15 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**& switch (_loadInfo->Fields[fieldIndex].Type) { case FT_INT: - *((uint32*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint32*>(&dataTable[offset]) = 0; offset += 4; break; case FT_BYTE: - *((uint8*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint8*>(&dataTable[offset]) = 0; offset += 1; break; case FT_SHORT: - *((uint16*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint16*>(&dataTable[offset]) = 0; offset += 2; break; default: @@ -621,7 +632,7 @@ void DB2FileLoaderRegularImpl::AutoProduceRecordCopies(uint32 records, char** in { indexTable[copy.NewRowId] = &dataTable[offset]; memcpy(indexTable[copy.NewRowId], indexTable[copy.SourceRowId], recordsize); - *((uint32*)(&dataTable[offset + idFieldOffset])) = copy.NewRowId; + *reinterpret_cast<uint32*>(&dataTable[offset + idFieldOffset]) = copy.NewRowId; offset += recordsize; } } @@ -896,6 +907,11 @@ std::size_t* DB2FileLoaderRegularImpl::RecordCreateDetachedFieldOffsets(std::siz return nullptr; } +std::size_t* DB2FileLoaderRegularImpl::RecordCopyDetachedFieldOffsets(std::size_t* /*oldOffsets*/) const +{ + return nullptr; +} + void DB2FileLoaderRegularImpl::RecordDestroyFieldOffsets(std::size_t*& /*fieldOffsets*/) const { } @@ -1008,9 +1024,7 @@ DB2FileLoaderSparseImpl::DB2FileLoaderSparseImpl(char const* fileName, DB2FileLo { } -DB2FileLoaderSparseImpl::~DB2FileLoaderSparseImpl() -{ -} +DB2FileLoaderSparseImpl::~DB2FileLoaderSparseImpl() = default; void DB2FileLoaderSparseImpl::LoadColumnData(std::unique_ptr<DB2SectionHeader[]> sections, std::unique_ptr<DB2FieldEntry[]> fields, std::unique_ptr<DB2ColumnMeta[]> /*columnMeta*/, std::unique_ptr<std::unique_ptr<DB2PalletValue[]>[]> /*palletValues*/, std::unique_ptr<std::unique_ptr<DB2PalletValue[]>[]> /*palletArrayValues*/, @@ -1105,7 +1119,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i uint32 fieldIndex = 0; if (!_loadInfo->Meta->HasIndexFieldInData()) { - *((uint32*)(&dataTable[offset])) = indexVal; + *reinterpret_cast<uint32*>(&dataTable[offset]) = indexVal; offset += 4; ++fieldIndex; } @@ -1117,33 +1131,33 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i switch (_loadInfo->Fields[fieldIndex].Type) { case FT_FLOAT: - *((float*)(&dataTable[offset])) = RecordGetFloat(rawRecord, x, z); + *reinterpret_cast<float*>(&dataTable[offset]) = RecordGetFloat(rawRecord, x, z); offset += 4; break; case FT_INT: - *((uint32*)(&dataTable[offset])) = RecordGetVarInt(rawRecord, x, z, _loadInfo->Fields[fieldIndex].IsSigned); + *reinterpret_cast<uint32*>(&dataTable[offset]) = RecordGetVarInt(rawRecord, x, z, _loadInfo->Fields[fieldIndex].IsSigned); offset += 4; break; case FT_BYTE: - *((uint8*)(&dataTable[offset])) = RecordGetUInt8(rawRecord, x, z); + *reinterpret_cast<uint8*>(&dataTable[offset]) = RecordGetUInt8(rawRecord, x, z); offset += 1; break; case FT_SHORT: - *((uint16*)(&dataTable[offset])) = RecordGetUInt16(rawRecord, x, z); + *reinterpret_cast<uint16*>(&dataTable[offset]) = RecordGetUInt16(rawRecord, x, z); offset += 2; break; case FT_LONG: - *((uint64*)(&dataTable[offset])) = RecordGetUInt64(rawRecord, x, z); + *reinterpret_cast<uint64*>(&dataTable[offset]) = RecordGetUInt64(rawRecord, x, z); offset += 8; break; case FT_STRING: - for (char const*& localeStr : ((LocalizedString*)(&dataTable[offset]))->Str) - localeStr = nullStr; + for (char const*& localeStr : reinterpret_cast<LocalizedString*>(&dataTable[offset])->Str) + localeStr = EmptyDb2String; offset += sizeof(LocalizedString); break; case FT_STRING_NOT_LOCALIZED: - *(char const**)(&dataTable[offset]) = nullStr; + *reinterpret_cast<char const**>(&dataTable[offset]) = EmptyDb2String; offset += sizeof(char*); break; default: @@ -1162,15 +1176,15 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i switch (_loadInfo->Fields[fieldIndex].Type) { case FT_INT: - *((uint32*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint32*>(&dataTable[offset]) = 0; offset += 4; break; case FT_BYTE: - *((uint8*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint8*>(&dataTable[offset]) = 0; offset += 1; break; case FT_SHORT: - *((uint16*)(&dataTable[offset])) = 0; + *reinterpret_cast<uint16*>(&dataTable[offset]) = 0; offset += 2; break; default: @@ -1281,7 +1295,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceStrings(char** indexTable, uint32 inde break; case FT_STRING: { - LocalizedString* db2str = (LocalizedString*)(&recordData[offset]); + LocalizedString* db2str = reinterpret_cast<LocalizedString*>(&recordData[offset]); db2str->Str[locale] = stringPtr; strcpy(stringPtr, RecordGetString(rawRecord, x, z)); stringPtr += strlen(stringPtr) + 1; @@ -1290,7 +1304,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceStrings(char** indexTable, uint32 inde } case FT_STRING_NOT_LOCALIZED: { - char const** db2str = (char const**)(&recordData[offset]); + char const** db2str = reinterpret_cast<char const**>(&recordData[offset]); *db2str = stringPtr; strcpy(stringPtr, RecordGetString(rawRecord, x, z)); stringPtr += strlen(stringPtr) + 1; @@ -1327,7 +1341,7 @@ void DB2FileLoaderSparseImpl::AutoProduceRecordCopies(uint32 records, char** ind { indexTable[copy.NewRowId] = &dataTable[offset]; memcpy(indexTable[copy.NewRowId], indexTable[copy.SourceRowId], recordsize); - *((uint32*)(&dataTable[offset + idFieldOffset])) = copy.NewRowId; + *reinterpret_cast<uint32*>(&dataTable[offset + idFieldOffset]) = copy.NewRowId; offset += recordsize; } } @@ -1538,6 +1552,17 @@ std::size_t* DB2FileLoaderSparseImpl::RecordCreateDetachedFieldOffsets(std::size return newOffsets; } +std::size_t* DB2FileLoaderSparseImpl::RecordCopyDetachedFieldOffsets(std::size_t* oldOffsets) const +{ + if (oldOffsets == _fieldAndArrayOffsets.get()) + return oldOffsets; + + std::size_t size = _loadInfo->Meta->FieldCount + _loadInfo->FieldCount - (!_loadInfo->Meta->HasIndexFieldInData() ? 1 : 0); + std::size_t* newOffsets = new std::size_t[size]; + memcpy(newOffsets, _fieldAndArrayOffsets.get(), size * sizeof(std::size_t)); + return newOffsets; +} + void DB2FileLoaderSparseImpl::RecordDestroyFieldOffsets(std::size_t*& fieldOffsets) const { if (fieldOffsets == _fieldAndArrayOffsets.get()) @@ -1617,12 +1642,22 @@ DB2Record::DB2Record(DB2FileLoaderImpl const& db2, uint32 recordIndex, std::size { } +DB2Record::DB2Record(DB2Record const& other) + : _db2(other._db2), _recordIndex(other._recordIndex), _recordData(other._recordData), _fieldOffsets(_db2.RecordCopyDetachedFieldOffsets(other._fieldOffsets)) +{ +} + +DB2Record::DB2Record(DB2Record&& other) noexcept + : _db2(other._db2), _recordIndex(other._recordIndex), _recordData(other._recordData), _fieldOffsets(std::exchange(other._fieldOffsets, nullptr)) +{ +} + DB2Record::~DB2Record() { _db2.RecordDestroyFieldOffsets(_fieldOffsets); } -DB2Record::operator bool() +DB2Record::operator bool() const { return _recordData != nullptr; } diff --git a/src/common/DataStores/DB2FileLoader.h b/src/common/DataStores/DB2FileLoader.h index 9e3f7c465f3..46692708bdf 100644 --- a/src/common/DataStores/DB2FileLoader.h +++ b/src/common/DataStores/DB2FileLoader.h @@ -95,6 +95,12 @@ enum class DB2EncryptedSectionHandling struct TC_COMMON_API DB2FileSource { + DB2FileSource(); + DB2FileSource(DB2FileSource const& other) = delete; + DB2FileSource(DB2FileSource&& other) noexcept = delete; + DB2FileSource& operator=(DB2FileSource const& other) = delete; + DB2FileSource& operator=(DB2FileSource&& other) noexcept = delete; + virtual ~DB2FileSource(); // Returns true when the source is open for reading @@ -120,9 +126,13 @@ class TC_COMMON_API DB2Record { public: DB2Record(DB2FileLoaderImpl const& db2, uint32 recordIndex, std::size_t* fieldOffsets); + DB2Record(DB2Record const& other); + DB2Record(DB2Record&& other) noexcept; + DB2Record& operator=(DB2Record const& other) = delete; + DB2Record& operator=(DB2Record&& other) noexcept = delete; ~DB2Record(); - operator bool(); + explicit operator bool() const; uint32 GetId() const; @@ -176,6 +186,10 @@ class TC_COMMON_API DB2FileLoader { public: DB2FileLoader(); + DB2FileLoader(DB2FileLoader const& other) = delete; + DB2FileLoader(DB2FileLoader&& other) noexcept = delete; + DB2FileLoader& operator=(DB2FileLoader const& other) = delete; + DB2FileLoader& operator=(DB2FileLoader&& other) noexcept = delete; ~DB2FileLoader(); // loadInfo argument is required when trying to read data from the file diff --git a/src/common/DataStores/DB2FileSystemSource.h b/src/common/DataStores/DB2FileSystemSource.h index 993b8e64c3d..16c0e8d1848 100644 --- a/src/common/DataStores/DB2FileSystemSource.h +++ b/src/common/DataStores/DB2FileSystemSource.h @@ -24,6 +24,10 @@ struct TC_COMMON_API DB2FileSystemSource : public DB2FileSource { DB2FileSystemSource(std::string const& fileName); + DB2FileSystemSource(DB2FileSystemSource const& other) = delete; + DB2FileSystemSource(DB2FileSystemSource&& other) noexcept = delete; + DB2FileSystemSource& operator=(DB2FileSystemSource const& other) = delete; + DB2FileSystemSource& operator=(DB2FileSystemSource&& other) noexcept = delete; ~DB2FileSystemSource(); bool IsOpen() const override; bool Read(void* buffer, std::size_t numBytes) override; diff --git a/src/tools/extractor_common/DB2CascFileSource.cpp b/src/tools/extractor_common/DB2CascFileSource.cpp index 51ffa34c22c..658893728ac 100644 --- a/src/tools/extractor_common/DB2CascFileSource.cpp +++ b/src/tools/extractor_common/DB2CascFileSource.cpp @@ -26,6 +26,8 @@ DB2CascFileSource::DB2CascFileSource(std::shared_ptr<CASC::Storage const> storag _fileName = Trinity::StringFormat("FileDataId: {}", fileDataId); } +DB2CascFileSource::~DB2CascFileSource() = default; + bool DB2CascFileSource::IsOpen() const { return _fileHandle != nullptr; diff --git a/src/tools/extractor_common/DB2CascFileSource.h b/src/tools/extractor_common/DB2CascFileSource.h index b68a532584c..27e5b58011e 100644 --- a/src/tools/extractor_common/DB2CascFileSource.h +++ b/src/tools/extractor_common/DB2CascFileSource.h @@ -26,6 +26,12 @@ struct DB2CascFileSource : public DB2FileSource { DB2CascFileSource(std::shared_ptr<CASC::Storage const> storage, uint32 fileDataId, bool printErrors = true); + DB2CascFileSource(DB2CascFileSource const& other) = delete; + DB2CascFileSource(DB2CascFileSource&& other) noexcept = delete; + DB2CascFileSource& operator=(DB2CascFileSource const& other) = delete; + DB2CascFileSource& operator=(DB2CascFileSource&& other) noexcept = delete; + ~DB2CascFileSource(); + bool IsOpen() const override; bool Read(void* buffer, std::size_t numBytes) override; int64 GetPosition() const override; |