removed [[nodiscard]] and changed chunk binary format

This commit is contained in:
Phuntsok Drak-pa 2018-06-11 21:26:05 +02:00
parent 67a88aaf91
commit 6c3fb8b6a7
5 changed files with 22 additions and 26 deletions

View File

@ -14,7 +14,7 @@ using ustring = std::basic_string<unsigned char>;
// packing //
///////////////////////////////////////////////////////////////////////////////
[[nodiscard]] vuchar pack(const vuint16 &t_input) {
vuchar pack(const vuint16 &t_input) {
return pack_n(t_input.begin(), t_input.end(), 9);
}
@ -27,8 +27,7 @@ using ustring = std::basic_string<unsigned char>;
* \param t_n maximum size of an input value in bits \return Returns a
* vector of unsigned char containing the packed values from t_input
*/
[[nodiscard]] vuchar
pack_n(const vuint16::const_iterator t_input_begin,
vuchar pack_n(const vuint16::const_iterator t_input_begin,
const vuint16::const_iterator t_input_end, const int t_n) {
#ifdef Debug
std::printf("%d bits!\n", t_n);
@ -87,7 +86,7 @@ pack_n(const vuint16::const_iterator t_input_begin,
return ret;
}
[[nodiscard]] vuchar pack_16(const vuint16::const_iterator t_input_begin,
vuchar pack_16(const vuint16::const_iterator t_input_begin,
const vuint16::const_iterator t_input_end) {
vuchar ret{};
std::for_each(t_input_begin, t_input_end, [&](const auto value) {
@ -102,7 +101,7 @@ pack_n(const vuint16::const_iterator t_input_begin,
///////////////////////////////////////////////////////////////////////////////
uint16_t mask_n(int t_nb_bits) {
if(t_nb_bits == 0) {
if (t_nb_bits == 0) {
return 0;
}
uint16_t mask = mask_n(t_nb_bits - 1);
@ -111,13 +110,12 @@ uint16_t mask_n(int t_nb_bits) {
return mask;
}
[[nodiscard]] vuint16 unpack(ustring &&t_input) {
vuint16 unpack(ustring &&t_input) {
return unpack_n(t_input.begin(), t_input.end(), 9);
}
[[nodiscard]] vuint16 unpack_n(const ustring::const_iterator t_begin,
const ustring::const_iterator t_end,
const int t_n) {
vuint16 unpack_n(const ustring::const_iterator t_begin,
const ustring::const_iterator t_end, const int t_n) {
int step = t_n / 8;
int left_shift = 0;
int right_shift = 0;
@ -143,7 +141,7 @@ uint16_t mask_n(int t_nb_bits) {
current_char |= *(++it) >> right_shift;
// char made!
ret.push_back(current_char &= mask);
if(right_shift == 0) {
if (right_shift == 0) {
++it;
}
if (current_char >= max_value) {
@ -155,7 +153,7 @@ uint16_t mask_n(int t_nb_bits) {
return ret;
}
[[nodiscard]] vuint16 unpack_16(const ustring::const_iterator t_begin,
vuint16 unpack_16(const ustring::const_iterator t_begin,
const ustring::const_iterator t_end) {
vuint16 ret{};
for (auto it = t_begin; it < t_end; ++it) {

View File

@ -11,27 +11,25 @@
#include <vector>
/// \brief Bat-packs the input dynamically
[[nodiscard]] std::vector<unsigned char>
pack(const std::vector<std::uint16_t> &);
std::vector<unsigned char> pack(const std::vector<std::uint16_t> &);
/// \brief Packs std::uint16_t of n bits into unsigned char
[[nodiscard]] std::vector<unsigned char>
std::vector<unsigned char>
pack_n(const std::vector<std::uint16_t>::const_iterator,
const std::vector<std::uint16_t>::const_iterator, const int);
/// \brief Specialization of \ref pack_n for 16bits
[[nodiscard]] std::vector<unsigned char>
std::vector<unsigned char>
pack_16(const std::vector<std::uint16_t>::const_iterator,
const std::vector<std::uint16_t>::const_iterator);
[[nodiscard]] std::vector<std::uint16_t>
unpack(std::basic_string<unsigned char> &&);
std::vector<std::uint16_t> unpack(std::basic_string<unsigned char> &&);
[[nodiscard]] std::vector<std::uint16_t>
std::vector<std::uint16_t>
unpack_n(const std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator, const int t_n);
[[nodiscard]] std::vector<std::uint16_t>
std::vector<std::uint16_t>
unpack_16(const std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator);

View File

@ -29,7 +29,7 @@ using vvuint16 = vector<vuint16>;
* taille des chunks\n
* \n
* Un chunk est composé de la manière qui suit :\n
* - Sur deux octets sont écrit un `uint16_t` déterminant le nombre doctets
* - Sur deux octets sont écrit un `uint32_t` déterminant le nombre doctets
* composant le chunk\n
* - Sur le nombre doctets précisés par le header du chunk se trouvent les
* données compressées par lalgorithme lzw puis via bit-packing.\n
@ -59,7 +59,7 @@ void write_file(FILE *const t_out, const vvuint16 &t_text) {
*/
void write_chunk(FILE *const t_out, const vuint16 &t_chunk) {
const auto output = pack(t_chunk);
const auto chunk_size = static_cast<uint16_t>(output.size());
const auto chunk_size = static_cast<uint32_t>(output.size());
fwrite(&chunk_size, sizeof(chunk_size), 1, t_out);
fwrite(output.data(), sizeof(output[0]), output.size(), t_out);
}

View File

@ -14,7 +14,7 @@ using std::vector;
using ustring = std::basic_string<unsigned char>;
using vuint16 = vector<uint16_t>;
[[nodiscard]] ustring lzw_uncompress(vuint16 &&t_compressed) {
ustring lzw_uncompress(vuint16 &&t_compressed) {
ustring ret{};
uint16_t old = 0;

View File

@ -5,7 +5,7 @@
#include <string>
#include <vector>
[[nodiscard]] std::basic_string<unsigned char>
std::basic_string<unsigned char>
lzw_uncompress(std::vector<std::uint16_t> &&);
void uncompress(const std::string &, const char*);