#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_COMPRESSION_ZLIB_ZLIBCOMPRESSIONALGORITHM_H #define NUCLEX_STORAGE_COMPRESSION_ZLIB_ZLIBCOMPRESSIONALGORITHM_H #include "Nuclex/Storage/Config.h" #if defined(NUCLEX_STORAGE_HAVE_ZLIB) #include "Nuclex/Storage/Compression/CompressionAlgorithm.h" namespace Nuclex { namespace Storage { namespace Compression { namespace ZLib { // ------------------------------------------------------------------------------------------- // /// Provides compressors and decompressors using the ZLib algorithm class DeflateCompressionAlgorithm : public CompressionAlgorithm { /// Level parameter that results in the fastest compression public: static const int FastestLevel; /// Level parameter that results in the highest ratio compression public: static const int StrongestLevel; /// Level parameter that results in reasonable compression /// /// There's usually a point where a compression algorithm's time requirement /// rises exponentially while the gains on terms of compression ratio are just /// minimal. This level tries to reflect a point before. /// public: static const int DefaultLevel; /// Initializes the ZLib compressor and decompressor factory /// ZLib compression level that will be used public: DeflateCompressionAlgorithm(int level = DefaultLevel); /// Frees all resources owned by the instance public: virtual ~DeflateCompressionAlgorithm() override = default; /// Returns the human-readable name of the compression algorithm /// The name of the compression algorithm the factory provides public: const std::string &GetName() const override { return this->name; } /// Returns a unique id for the compression algorithm /// The compression algorithm's unique id public: std::array GetId() const override { return std::array { 'D', 'F', 'L', 'T', '0', '0', '0', '1' }; } /// /// Returns the average number of CPU cycles this algorithm runs for to /// compress one kilobyte of data /// /// The average number of CPU cycles to comrpess one kilobyte public: std::size_t GetCompressionCyclesPerKilobyte() const override { return 10000; }; /// /// Returns the average size of data compressed with this algorithm as compared /// to its uncompressed size /// /// The average ratio of compressed size to uncompressed size public: float GetAverageCompressionRatio() const override { return 0.8f; } /// Creates a new data compressor /// A new data compressor of the algorithm's type public: std::unique_ptr CreateCompressor() const override; /// Creates a new data decompressor /// A new data decompressor of the algorithm's type public: std::unique_ptr CreateDecompressor() const override; /// The name of the compression algorithm private: std::string name; /// Compression level that will be used when compressing things private: int level; }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::Compression::ZLib #endif // defined(NUCLEX_STORAGE_HAVE_ZLIB) #endif // NUCLEX_STORAGE_COMPRESSION_ZLIB_ZLIBCOMPRESSOR_H