diff --git a/include/Athena/IStreamReader.hpp b/include/Athena/IStreamReader.hpp index 33b88d8..8a79354 100644 --- a/include/Athena/IStreamReader.hpp +++ b/include/Athena/IStreamReader.hpp @@ -10,7 +10,7 @@ namespace io class IStreamReader : public IStream { public: - virtual ~IStreamReader(); + virtual ~IStreamReader() {} virtual void setEndian(Endian) = 0; virtual Endian endian() const= 0; virtual bool isBigEndian() const= 0; diff --git a/include/Athena/IStreamWriter.hpp b/include/Athena/IStreamWriter.hpp index 7ec9a8b..0e24e0b 100644 --- a/include/Athena/IStreamWriter.hpp +++ b/include/Athena/IStreamWriter.hpp @@ -10,7 +10,7 @@ namespace io class IStreamWriter : public IStream { public: - virtual ~IStreamWriter(); + virtual ~IStreamWriter() {} virtual void setEndian(Endian) = 0; virtual Endian endian() const= 0; virtual bool isBigEndian() const= 0; diff --git a/include/Athena/MemoryWriter.hpp b/include/Athena/MemoryWriter.hpp index d04e10c..e8001cb 100644 --- a/include/Athena/MemoryWriter.hpp +++ b/include/Athena/MemoryWriter.hpp @@ -16,7 +16,7 @@ #ifndef MEMORYWRITER_HPP #define MEMORYWRITER_HPP -#include "Athena/IStream.hpp" +#include "Athena/IStreamWriter.hpp" #include #include @@ -33,7 +33,7 @@ namespace io * this allows for fast, flexible code as well as the ability to quickly modify data * \sa Stream */ -class MemoryWriter : public IStream +class MemoryWriter : public IStreamWriter { public: /*! \brief This constructor takes an existing buffer to write to. diff --git a/src/Athena/Compression.cpp b/src/Athena/Compression.cpp index e3af89f..2ed4ac5 100644 --- a/src/Athena/Compression.cpp +++ b/src/Athena/Compression.cpp @@ -109,7 +109,7 @@ atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8* { int srcSize = sourceSize; int size = dstSize; - int result = lzo1x_decompress(source, srcSize, dst, (lzo_uintp)&size, NULL); + int result = lzo1x_decompress_safe(source, srcSize, dst, (lzo_uintp)&size, NULL); dstSize -= size; return result; diff --git a/src/LZ77/LZLookupTable.cpp b/src/LZ77/LZLookupTable.cpp index 076033d..75878eb 100644 --- a/src/LZ77/LZLookupTable.cpp +++ b/src/LZ77/LZLookupTable.cpp @@ -13,15 +13,15 @@ LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt3 { if(minimumMatch > 0 ) m_minimumMatch = minimumMatch; - else + else m_minimumMatch = 3; if(slidingWindow > 0) m_slidingWindow = slidingWindow; - else + else m_slidingWindow = 4096; if(lookAheadWindow > 0) m_lookAheadWindow = lookAheadWindow; - else + else m_lookAheadWindow = 18; m_buffer.reserve(m_minimumMatch); } @@ -33,80 +33,80 @@ void LZLookupTable::setLookAheadWindow(atInt32 lookAheadWindow) { if(lookAheadWindow > 0) m_lookAheadWindow = lookAheadWindow; - else + else m_lookAheadWindow = 18; } LZLengthOffset LZLookupTable::search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd) { LZLengthOffset loPair = {0,0}; - //Returns negative 1 for search failures since the current position is passed the size to be compressed + //Returns negative 1 for search failures since the current position is passed the size to be compressed if(curPos >=dataEnd) - { + { loPair.length=-1; return loPair; - } + } std::copy(curPos, curPos + m_minimumMatch, m_buffer.begin()); int32_t currentOffset = static_cast(curPos - dataBegin); - //Find code + //Find code if(currentOffset > 0 && (dataEnd - curPos) >= m_minimumMatch) - { + { auto elements = table.equal_range(m_buffer); - elements.second--; - elements.first--; - //Iterate over keys in reverse order. C++11 guarantees that the relative order of elements is maintained for the same key - for(auto iter = elements.second; iter != elements.first; iter--) - { + elements.second--; + elements.first--; + //Iterate over keys in reverse order. C++11 guarantees that the relative order of elements is maintained for the same key + for(auto iter = elements.second; iter != elements.first; iter--) + { int32_t matchLength = m_minimumMatch; int32_t lookAheadBufferLength = ((dataEnd - curPos) < m_lookAheadWindow) ? static_cast(dataEnd - curPos) : m_lookAheadWindow; - for(; matchLength < lookAheadBufferLength; ++matchLength) - { + for(; matchLength < lookAheadBufferLength; ++matchLength) + { if(*(dataBegin + iter->second + matchLength) != *(curPos + matchLength)) - break; - } - //Store the longest match found so far into length_offset struct. - //When lengths are the same the closer offset to the lookahead buffer wins + break; + } + //Store the longest match found so far into length_offset struct. + //When lengths are the same the closer offset to the lookahead buffer wins if(loPair.length < (atUint32)matchLength) - { + { loPair.length = matchLength; loPair.offset = currentOffset - iter->second; - } - //Found the longest match so break out of loop + } + //Found the longest match so break out of loop if(loPair.length == (atUint32)m_lookAheadWindow) - break; - } - } - //end find code - //Insert code + break; + } + } + //end find code + //Insert code table.insert(std::make_pair(m_buffer, currentOffset)); for(atUint32 i = 1; i < loPair.length; i++) - { + { if(dataEnd - (curPos + i) < m_minimumMatch) - break; + break; std::copy(curPos + i, curPos + m_minimumMatch + i, m_buffer.begin()); table.insert(std::make_pair(m_buffer, currentOffset + i)); - - } - //end insert code - //Delete code + + } + //end insert code + //Delete code int32_t slidingWindowOffset = std::max(0, currentOffset - m_slidingWindow);//Absolute offset - int32_t tablesize=static_cast(table.size()); + int32_t tablesize=static_cast(table.size()); for(int32_t i = 0; i < tablesize - m_slidingWindow; ++i) - { + { std::copy(dataBegin + slidingWindowOffset + i, dataBegin + slidingWindowOffset + m_minimumMatch + i, m_buffer.begin()); auto elements = table.equal_range(m_buffer); - for(auto iter = elements.first; iter != elements.second; iter++) - { - if(slidingWindowOffset + i == iter->second) - { - table.erase(iter); - //There should no occurance of the map with the same value - break; - } - } - } - //end delete code + for(auto iter = elements.first; iter != elements.second; iter++) + { + if(slidingWindowOffset + i == iter->second) + { + table.erase(iter); + //There should no occurance of the map with the same value + break; + } + } + } + //end delete code return loPair; - //break lookupTable.cpp:109 if table.size()> 4096 + //break lookupTable.cpp:109 if table.size()> 4096 }