diff --git a/CMakeLists.txt b/CMakeLists.txt index c361fc6..8180778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,52 @@ endif() set(ESFA_PUBLIC_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include") set(ESFA_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src") +# == Compiler Warnings == + +if(MSVC) + set(ESFA_WARNING_FLAGS + /W4 + /permissive- + /w14242 + /w14254 + /w14263 + /w14265 + /w14287 + /we4289 + /w14296 + /w14311 + /w14545 + /w14546 + /w14547 + /w14549 + /w14555 + /w14619 + /w14640 + /w14826 + /w14905 + /w14906 + /w14928 + ) +else() + set(ESFA_WARNING_FLAGS + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wconversion + -Wsign-conversion + -Wnull-dereference + -Wdouble-promotion + -Wformat=2 + -Wimplicit-fallthrough + ) +endif() + # Processing add_library(processing ${ESFA_LIB_TYPE} @@ -34,6 +80,7 @@ add_library(processing ${ESFA_LIB_TYPE} ) target_include_directories(processing PUBLIC ${ESFA_PUBLIC_INCLUDES} PRIVATE ${ESFA_SRC}/processing) +target_compile_options(processing PRIVATE ${ESFA_WARNING_FLAGS}) # Interface @@ -42,16 +89,19 @@ add_library(interface ${ESFA_LIB_TYPE} ) target_include_directories(interface PUBLIC ${ESFA_PUBLIC_INCLUDES} PRIVATE ${ESFA_SRC}/interface) +target_compile_options(interface PRIVATE ${ESFA_WARNING_FLAGS}) # esfa lib add_library(esfa ${ESFA_SRC}/esfa.cpp) target_include_directories(esfa PUBLIC ${ESFA_PUBLIC_INCLUDES}) target_link_libraries(esfa PUBLIC processing interface) +target_compile_options(esfa PRIVATE ${ESFA_WARNING_FLAGS}) set_target_properties(esfa PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) + # binary / tests if(ESFA_BUILD_TESTS) diff --git a/include/esfa/esfa.hpp b/include/esfa/esfa.hpp index fbde7f3..ebd1c77 100644 --- a/include/esfa/esfa.hpp +++ b/include/esfa/esfa.hpp @@ -18,6 +18,13 @@ class Processor { std::any& ctx, esfa::bit::Endianness sourceEndianness); + std::shared_ptr ParseAsset( + const std::string& typeKey, + std::shared_ptr inStream, + const interface::AssetMeta& meta, + std::any& ctx, + bit::Endianness sourceEndianness); + void ExportAsset( const std::string& typeKey, std::shared_ptr asset, @@ -27,6 +34,13 @@ class Processor { uint64_t maxSize = std::numeric_limits::max()); + void ExportAsset( + const std::string& typeKey, + std::shared_ptr asset, + std::shared_ptr outStream, + std::any& ctx, + bit::Endianness targetEndianness, + uint64_t maxSize); private: const interface::Registry& mRegistry; }; diff --git a/include/esfa/interface/asset.hpp b/include/esfa/interface/asset.hpp index 4382892..7fe4a7b 100644 --- a/include/esfa/interface/asset.hpp +++ b/include/esfa/interface/asset.hpp @@ -17,13 +17,18 @@ class ParsedAsset { // Minimal per-asset info the registry needs to pass through. struct AssetMeta { std::string name; - uint32_t offset; - uint32_t size; + uint32_t offset = 0; + uint32_t size = 0; std::filesystem::path sourceFile; // Allow asset to grow during swap (e.g., uncompressed formats) // If not set, defaults to input size - std::optional maxOutputSize; + std::optional maxOutputSize = std::nullopt; + + AssetMeta() = default; + AssetMeta(std::string n, uint32_t off, uint32_t sz, std::filesystem::path src, + std::optional maxOut = std::nullopt) + : name(std::move(n)), offset(off), size(sz), sourceFile(std::move(src)), maxOutputSize(maxOut) {} }; } diff --git a/include/esfa/processing/binary/writer.hpp b/include/esfa/processing/binary/writer.hpp index 4419d30..10a7ec2 100644 --- a/include/esfa/processing/binary/writer.hpp +++ b/include/esfa/processing/binary/writer.hpp @@ -18,6 +18,7 @@ class Writer Writer(std::shared_ptr nStream); void SetEndianness(esfa::bit::Endianness endianness); + esfa::bit::Endianness GetEndianness() const; std::shared_ptr GetStream(); uint64_t GetBaseAddress(); diff --git a/include/esfa/processing/bit/converter.hpp b/include/esfa/processing/bit/converter.hpp index 5145382..0694e58 100644 --- a/include/esfa/processing/bit/converter.hpp +++ b/include/esfa/processing/bit/converter.hpp @@ -32,158 +32,191 @@ enum class Endianness class BitConverter { public: - static inline int8_t ToInt8BE(const uint8_t* data, int32_t offset) + static inline int8_t ToInt8BE(const uint8_t* data, size_t offset) { - return (uint8_t)data[offset + 0]; + return static_cast(data[offset]); } - static inline int8_t ToInt8BE(const std::vector& data, int32_t offset) + static inline int8_t ToInt8BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + return static_cast(data[offset]); } - static inline uint8_t ToUInt8BE(const uint8_t* data, int32_t offset) + static inline uint8_t ToUInt8BE(const uint8_t* data, size_t offset) { - return (uint8_t)data[offset + 0]; + return data[offset]; } - static inline uint8_t ToUInt8BE(const std::vector& data, int32_t offset) + static inline uint8_t ToUInt8BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + return data[offset]; } - static inline int16_t ToInt16BE(const uint8_t* data, int32_t offset) + static inline int16_t ToInt16BE(const uint8_t* data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + return static_cast((static_cast(data[offset]) << 8) | + static_cast(data[offset + 1])); } - static inline int16_t ToInt16BE(const std::vector& data, int32_t offset) + static inline int16_t ToInt16BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + return static_cast((static_cast(data[offset]) << 8) | + static_cast(data[offset + 1])); } - static inline uint16_t ToUInt16BE(const uint8_t* data, int32_t offset) + static inline uint16_t ToUInt16BE(const uint8_t* data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + return static_cast((static_cast(data[offset]) << 8) | + static_cast(data[offset + 1])); } - static inline uint16_t ToUInt16BE(const std::vector& data, int32_t offset) + static inline uint16_t ToUInt16BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + return static_cast((static_cast(data[offset]) << 8) | + static_cast(data[offset + 1])); } - static inline int32_t ToInt32BE(const uint8_t* data, int32_t offset) + static inline int32_t ToInt32BE(const uint8_t* data, size_t offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return static_cast((static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3])); } - static inline int32_t ToInt32BE(const std::vector& data, int32_t offset) + static inline int32_t ToInt32BE(const std::vector& data, size_t offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return static_cast((static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3])); } - static inline uint32_t ToUInt32BE(const uint8_t* data, int32_t offset) + static inline uint32_t ToUInt32BE(const uint8_t* data, size_t offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return (static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3]); } - static inline uint32_t ToUInt32BE(const std::vector& data, int32_t offset) + static inline uint32_t ToUInt32BE(const std::vector& data, size_t offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return (static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3]); } - static inline int64_t ToInt64BE(const uint8_t* data, int32_t offset) + static inline int64_t ToInt64BE(const uint8_t* data, size_t offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return static_cast((static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7])); } - static inline int64_t ToInt64BE(const std::vector& data, int32_t offset) + static inline int64_t ToInt64BE(const std::vector& data, size_t offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return static_cast((static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7])); } - static inline uint64_t ToUInt64BE(const uint8_t* data, int32_t offset) + static inline uint64_t ToUInt64BE(const uint8_t* data, size_t offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return (static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7]); } - static inline uint64_t ToUInt64BE(const std::vector& data, int32_t offset) + static inline uint64_t ToUInt64BE(const std::vector& data, size_t offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return (static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7]); } - static inline float ToFloatBE(const uint8_t* data, int32_t offset) + static inline float ToFloatBE(const uint8_t* data, size_t offset) { - float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + - ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + float value = 0.0f; + uint32_t floatData = (static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3]); static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float"); std::memcpy(&value, &floatData, sizeof(value)); return value; } - static inline float ToFloatBE(const std::vector& data, int32_t offset) + static inline float ToFloatBE(const std::vector& data, size_t offset) { - float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + - ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + float value = 0.0f; + uint32_t floatData = (static_cast(data[offset]) << 24) | + (static_cast(data[offset + 1]) << 16) | + (static_cast(data[offset + 2]) << 8) | + static_cast(data[offset + 3]); static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float"); std::memcpy(&value, &floatData, sizeof(value)); return value; } - static inline double ToDoubleBE(const uint8_t* data, int32_t offset) + static inline double ToDoubleBE(const uint8_t* data, size_t offset) { - double value; + double value = 0.0; uint64_t floatData = - ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + (static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7]); static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double"); - // Checks if the float format on the platform the ZAPD binary is running on supports the - // same float format as the object file. - static_assert(std::numeric_limits::is_iec559, - "expected IEC559 floats on host machine"); + static_assert(std::numeric_limits::is_iec559, + "expected IEC559 doubles on host machine"); std::memcpy(&value, &floatData, sizeof(value)); return value; } - static inline double ToDoubleBE(const std::vector& data, int32_t offset) + static inline double ToDoubleBE(const std::vector& data, size_t offset) { - double value; + double value = 0.0; uint64_t floatData = - ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + (static_cast(data[offset]) << 56) | + (static_cast(data[offset + 1]) << 48) | + (static_cast(data[offset + 2]) << 40) | + (static_cast(data[offset + 3]) << 32) | + (static_cast(data[offset + 4]) << 24) | + (static_cast(data[offset + 5]) << 16) | + (static_cast(data[offset + 6]) << 8) | + static_cast(data[offset + 7]); static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double"); - // Checks if the float format on the platform the ZAPD binary is running on supports the - // same float format as the object file. static_assert(std::numeric_limits::is_iec559, "expected IEC559 doubles on host machine"); std::memcpy(&value, &floatData, sizeof(value)); return value; } - }; } diff --git a/include/esfa/processing/stream/file_stream.hpp b/include/esfa/processing/stream/file_stream.hpp index 532e6a9..337e7c4 100644 --- a/include/esfa/processing/stream/file_stream.hpp +++ b/include/esfa/processing/stream/file_stream.hpp @@ -33,7 +33,6 @@ class FileStream : public Stream { private: std::filesystem::path mPath; std::fstream mFile; - FileMode mMode; bool mClosed = false; void EnsureOpen() const; diff --git a/src/esfa.cpp b/src/esfa.cpp index fbff5b3..47f654f 100644 --- a/src/esfa.cpp +++ b/src/esfa.cpp @@ -21,6 +21,21 @@ std::shared_ptr Processor::ParseAsset( return mRegistry.Parse(typeKey, reader, meta, ctx); } +std::shared_ptr Processor::ParseAsset( + const std::string& typeKey, + std::shared_ptr inStream, + const interface::AssetMeta& meta, + std::any& ctx, + bit::Endianness sourceEndianness) +{ + auto bounded = std::make_shared( + inStream, meta.offset, meta.size); + + binary::Reader reader(bounded); + reader.SetEndianness(sourceEndianness); + return mRegistry.Parse(typeKey, reader, meta, ctx); +} + void Processor::ExportAsset( const std::string& typeKey, std::shared_ptr asset, @@ -60,4 +75,19 @@ void Processor::ExportAsset( } } +void Processor::ExportAsset( + const std::string& typeKey, + std::shared_ptr asset, + std::shared_ptr outStream, + std::any& ctx, + bit::Endianness targetEndianness, + uint64_t maxSize) +{ + auto bounded = std::make_shared(outStream, 0, maxSize); + binary::Writer writer(bounded); + writer.SetEndianness(targetEndianness); + mRegistry.Export(typeKey, writer, std::move(asset), ctx); + writer.Close(); +} + } diff --git a/src/processing/binary/reader.cpp b/src/processing/binary/reader.cpp index 677d59d..68a530e 100644 --- a/src/processing/binary/reader.cpp +++ b/src/processing/binary/reader.cpp @@ -20,9 +20,9 @@ void Reader::Close() stream->Close(); } -void Reader::SetEndianness(esfa::bit::Endianness endianness) +void Reader::SetEndianness(esfa::bit::Endianness nEndianness) { - this->endianness = endianness; + this->endianness = nEndianness; } esfa::bit::Endianness Reader::GetEndianness() const @@ -42,17 +42,17 @@ uint64_t Reader::GetBaseAddress() void Reader::Read(int32_t length) { - stream->Read(length); + stream->Read(static_cast(length)); } void Reader::Read(char* buffer, int32_t length) { - stream->Read(buffer, length); + stream->Read(buffer, static_cast(length)); } char Reader::ReadChar() { - return (char)stream->ReadByte(); + return static_cast(stream->ReadByte()); } int8_t Reader::ReadByte() @@ -62,17 +62,17 @@ int8_t Reader::ReadByte() uint8_t Reader::ReadUByte() { - return (uint8_t)stream->ReadByte(); + return static_cast(stream->ReadByte()); } int16_t Reader::ReadInt16() { int16_t result = 0; - stream->Read((char*)&result, sizeof(int16_t)); + stream->Read(reinterpret_cast(&result), sizeof(int16_t)); if (endianness != esfa::bit::Endianness::Native) - result = BSWAP16(result); + result = static_cast(BSWAP16(static_cast(result))); return result; } @@ -81,10 +81,10 @@ int32_t Reader::ReadInt32() { int32_t result = 0; - stream->Read((char*)&result, sizeof(int32_t)); + stream->Read(reinterpret_cast(&result), sizeof(int32_t)); if (endianness != esfa::bit::Endianness::Native) - result = BSWAP32(result); + result = static_cast(BSWAP32(static_cast(result))); return result; } @@ -93,7 +93,7 @@ uint16_t Reader::ReadUInt16() { uint16_t result = 0; - stream->Read((char*)&result, sizeof(uint16_t)); + stream->Read(reinterpret_cast(&result), sizeof(uint16_t)); if (endianness != esfa::bit::Endianness::Native) result = BSWAP16(result); @@ -105,7 +105,7 @@ uint32_t Reader::ReadUInt32() { uint32_t result = 0; - stream->Read((char*)&result, sizeof(uint32_t)); + stream->Read(reinterpret_cast(&result), sizeof(uint32_t)); if (endianness != esfa::bit::Endianness::Native) result = BSWAP32(result); @@ -117,7 +117,7 @@ uint64_t Reader::ReadUInt64() { uint64_t result = 0; - stream->Read((char*)&result, sizeof(uint64_t)); + stream->Read(reinterpret_cast(&result), sizeof(uint64_t)); if (endianness != esfa::bit::Endianness::Native) result = BSWAP64(result); @@ -129,13 +129,13 @@ float Reader::ReadSingle() { float result = 0.f; - stream->Read((char*)&result, sizeof(float)); + stream->Read(reinterpret_cast(&result), sizeof(float)); if (endianness != esfa::bit::Endianness::Native) { - float tmp; - char* dst = (char*)&tmp; - char* src = (char*)&result; + float tmp = 0.0f; + char* dst = reinterpret_cast(&tmp); + char* src = reinterpret_cast(&result); dst[3] = src[0]; dst[2] = src[1]; dst[1] = src[2]; dst[0] = src[3]; result = tmp; } @@ -147,13 +147,13 @@ double Reader::ReadDouble() { double result = 0.0; - stream->Read((char*)&result, sizeof(double)); + stream->Read(reinterpret_cast(&result), sizeof(double)); if (endianness != esfa::bit::Endianness::Native) { - double tmp; - char* dst = (char*)&tmp; - char* src = (char*)&result; + double tmp = 0.0; + char* dst = reinterpret_cast(&tmp); + char* src = reinterpret_cast(&result); dst[7] = src[0]; dst[6] = src[1]; dst[5] = src[2]; dst[4] = src[3]; dst[3] = src[4]; dst[2] = src[5]; dst[1] = src[6]; dst[0] = src[7]; result = tmp; @@ -165,9 +165,9 @@ double Reader::ReadDouble() std::string Reader::ReadString() { std::string res; - int numChars = ReadInt32(); + int32_t numChars = ReadInt32(); - for (int i = 0; i < numChars; i++) + for (int32_t i = 0; i < numChars; i++) res += ReadChar(); return res; diff --git a/src/processing/binary/writer.cpp b/src/processing/binary/writer.cpp index 6993658..e7fb1e1 100644 --- a/src/processing/binary/writer.cpp +++ b/src/processing/binary/writer.cpp @@ -12,11 +12,17 @@ Writer::Writer(std::shared_ptr nStream) stream = nStream; } -void Writer::SetEndianness(esfa::bit::Endianness endianness) +void Writer::SetEndianness(esfa::bit::Endianness nEndianness) { - this->endianness = endianness; + this->endianness = nEndianness; } +esfa::bit::Endianness Writer::GetEndianness() const +{ + return this->endianness; +} + + void Writer::Close() { stream->Close(); @@ -44,20 +50,20 @@ void Writer::Seek(int64_t offset, esfa::stream::SeekOffsetType seekType) void Writer::Write(int8_t value) { - stream->Write((char*)&value, sizeof(int8_t)); + stream->Write(reinterpret_cast(&value), sizeof(int8_t)); } void Writer::Write(uint8_t value) { - stream->Write((char*)&value, sizeof(uint8_t)); + stream->Write(reinterpret_cast(&value), sizeof(uint8_t)); } void Writer::Write(int16_t value) { if (endianness != esfa::bit::Endianness::Native) - value = BSWAP16(value); + value = static_cast(BSWAP16(static_cast(value))); - stream->Write((char*)&value, sizeof(int16_t)); + stream->Write(reinterpret_cast(&value), sizeof(int16_t)); } void Writer::Write(uint16_t value) @@ -65,15 +71,15 @@ void Writer::Write(uint16_t value) if (endianness != esfa::bit::Endianness::Native) value = BSWAP16(value); - stream->Write((char*)&value, sizeof(uint16_t)); + stream->Write(reinterpret_cast(&value), sizeof(uint16_t)); } void Writer::Write(int32_t value) { if (endianness != esfa::bit::Endianness::Native) - value = BSWAP32(value); + value = static_cast(BSWAP32(static_cast(value))); - stream->Write((char*)&value, sizeof(int32_t)); + stream->Write(reinterpret_cast(&value), sizeof(int32_t)); } void Writer::Write(int32_t valueA, int32_t valueB) @@ -87,15 +93,15 @@ void Writer::Write(uint32_t value) if (endianness != esfa::bit::Endianness::Native) value = BSWAP32(value); - stream->Write((char*)&value, sizeof(uint32_t)); + stream->Write(reinterpret_cast(&value), sizeof(uint32_t)); } void Writer::Write(int64_t value) { if (endianness != esfa::bit::Endianness::Native) - value = BSWAP64(value); + value = static_cast(BSWAP64(static_cast(value))); - stream->Write((char*)&value, sizeof(int64_t)); + stream->Write(reinterpret_cast(&value), sizeof(int64_t)); } void Writer::Write(uint64_t value) @@ -103,45 +109,45 @@ void Writer::Write(uint64_t value) if (endianness != esfa::bit::Endianness::Native) value = BSWAP64(value); - stream->Write((char*)&value, sizeof(uint64_t)); + stream->Write(reinterpret_cast(&value), sizeof(uint64_t)); } void Writer::Write(float value) { if (endianness != esfa::bit::Endianness::Native) { - float tmp; - char* dst = (char*)&tmp; - char* src = (char*)&value; + float tmp = 0.0f; + char* dst = reinterpret_cast(&tmp); + char* src = reinterpret_cast(&value); dst[3] = src[0]; dst[2] = src[1]; dst[1] = src[2]; dst[0] = src[3]; value = tmp; } - stream->Write((char*)&value, sizeof(float)); + stream->Write(reinterpret_cast(&value), sizeof(float)); } void Writer::Write(double value) { if (endianness != esfa::bit::Endianness::Native) { - double tmp; - char* dst = (char*)&tmp; - char* src = (char*)&value; + double tmp = 0.0; + char* dst = reinterpret_cast(&tmp); + char* src = reinterpret_cast(&value); dst[7] = src[0]; dst[6] = src[1]; dst[5] = src[2]; dst[4] = src[3]; dst[3] = src[4]; dst[2] = src[5]; dst[1] = src[6]; dst[0] = src[7]; value = tmp; } - stream->Write((char*)&value, sizeof(double)); + stream->Write(reinterpret_cast(&value), sizeof(double)); } void Writer::Write(const std::string& str) { - int strLen = str.size(); + auto strLen = static_cast(str.size()); Write(strLen); for (char c : str) - stream->WriteByte(c); + stream->WriteByte(static_cast(c)); } void Writer::Write(char* srcBuffer, size_t length) diff --git a/src/processing/stream/file_stream.cpp b/src/processing/stream/file_stream.cpp index ba8e377..5c99ce4 100644 --- a/src/processing/stream/file_stream.cpp +++ b/src/processing/stream/file_stream.cpp @@ -21,7 +21,7 @@ std::ios::openmode ToOpenMode(FileMode mode) } // anonymous namespace FileStream::FileStream(const std::filesystem::path& path, FileMode mode) - : mPath(path), mMode(mode) + : mPath(path) { if (mode == FileMode::ReadWrite && !std::filesystem::exists(mPath)) {