]> code.bitgloo.com Git - clyne/consteval-huffman.git/commitdiff
Figured out class organization
authorclyne <clyne@bitgloo.com>
Wed, 1 Jul 2020 21:21:59 +0000 (17:21 -0400)
committerGitHub <noreply@github.com>
Wed, 1 Jul 2020 21:21:59 +0000 (17:21 -0400)
consteval_huffman.hpp

index 9dde53a918f4cf7215c91526e6e57621ed3c0c34..b7ea81999d52de4551adce96d188d21aae20dd92 100644 (file)
@@ -9,25 +9,13 @@
  * @tparam data Expected to be a null-terminated `char` of data to be compressed.
  */
 template<auto data>
-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_