From c4a598007b33f9d6f678822633845bfe1de467ef Mon Sep 17 00:00:00 2001 From: clyne Date: Wed, 1 Jul 2020 17:21:59 -0400 Subject: [PATCH] Figured out class organization --- consteval_huffman.hpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/consteval_huffman.hpp b/consteval_huffman.hpp index 9dde53a..b7ea819 100644 --- a/consteval_huffman.hpp +++ b/consteval_huffman.hpp @@ -9,25 +9,13 @@ * @tparam data Expected to be a null-terminated `char` of data to be compressed. */ template -struct huffman_compress +class huffman_compress { using size_t = unsigned long int; - // Contains the compressed data. - unsigned char output[size()] = {}; - // Contains a 'tree' that can be used to decompress the data. - unsigned char decode_tree[3 * tree_count()] = {}; - - // Returns the size of the compressed data, in bytes. - consteval static auto size() { return output_size().first; } - // Returns how many of the bits in the last byte of `output` are actually part of the data. - consteval static auto lastbitscount() { return output_size().second; } - - consteval huffman_compress() { - build_decode_tree(); - compress(); - } - + // The internals for this class needed to be defined before they're used in + // the public interface. Scroll to the next `public` section for usable variables/functions. +private: // Node structure used for tree-building. struct node { int value = 0; @@ -160,6 +148,22 @@ struct huffman_compress } delete[] tree.data(); } + +public: + // Returns the size of the compressed data, in bytes. + consteval static auto size() { return output_size().first; } + // Returns how many of the bits in the last byte of `output` are actually part of the data. + consteval static auto lastbitscount() { return output_size().second; } + + // Contains the compressed data. + unsigned char output[size()] = {}; + // Contains a 'tree' that can be used to decompress the data. + unsigned char decode_tree[3 * tree_count()] = {}; + + consteval huffman_compress() { + build_decode_tree(); + compress(); + } }; #endif // TCSULLIVAN_CONSTEVAL_HUFFMAN_HPP_