diff --git a/src/bitpack.cc b/src/bitpack.cc index ac965b8..6eb5c9d 100644 --- a/src/bitpack.cc +++ b/src/bitpack.cc @@ -10,9 +10,9 @@ using vuint16 = vector; using vuchar = vector; using ustring = std::basic_string; -int max(const int t_n) { return ipow(2, t_n) - 1; } +[[nodiscard]] int max(const int t_n) { return ipow(2, t_n) - 1; } -constexpr uint16_t mask_n(int t_nb_bits) { +[[nodiscard]] constexpr uint16_t mask_n(int t_nb_bits) { if (t_nb_bits == 0) { return 0; } @@ -31,14 +31,14 @@ constexpr uint16_t masks[17] = { // packing // /////////////////////////////////////////////////////////////////////////////// -vuchar pack(const vuint16 &t_input) { +[[nodiscard]] vuchar pack(const vuint16 &t_input) { vuchar vec{}; return pack_n(t_input.begin(), t_input.end(), vec, 9); } -vuchar pack_n(const vuint16::const_iterator t_input_begin, - const vuint16::const_iterator t_input_end, vuchar &t_res, - int t_n) { +[[nodiscard]] vuchar pack_n(const vuint16::const_iterator t_input_begin, + const vuint16::const_iterator t_input_end, + vuchar &t_res, int t_n) { if (t_n == 16) { return pack_16(t_input_begin, t_input_end, t_res); } @@ -107,8 +107,9 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin, return t_res; } -vuchar pack_16(const vuint16::const_iterator t_input_begin, - const vuint16::const_iterator t_input_end, vuchar &t_res) { +[[nodiscard]] vuchar pack_16(const vuint16::const_iterator t_input_begin, + const vuint16::const_iterator t_input_end, + vuchar &t_res) { std::for_each(t_input_begin, t_input_end, [&t_res](const auto value) { t_res.push_back(static_cast(value >> 8 & 0xFFU)); t_res.push_back(static_cast(value & 0xFFU)); @@ -120,13 +121,14 @@ vuchar pack_16(const vuint16::const_iterator t_input_begin, // unpacking // /////////////////////////////////////////////////////////////////////////////// -vuint16 unpack(ustring &&t_input) { +[[nodiscard]] vuint16 unpack(ustring &&t_input) { vuint16 vec{}; return unpack_n(t_input.begin(), t_input.end(), vec, 9); } -vuint16 unpack_n(const ustring::const_iterator t_begin, - const ustring::const_iterator t_end, vuint16 &t_res, int t_n) { +[[nodiscard]] vuint16 unpack_n(const ustring::const_iterator t_begin, + const ustring::const_iterator t_end, + vuint16 &t_res, int t_n) { if (t_n == 16) { return unpack_16(t_begin, t_end, t_res); } @@ -165,8 +167,9 @@ vuint16 unpack_n(const ustring::const_iterator t_begin, return t_res; } -vuint16 unpack_16(const ustring::const_iterator t_begin, - const ustring::const_iterator t_end, vuint16 &t_res) { +[[nodiscard]] vuint16 unpack_16(const ustring::const_iterator t_begin, + const ustring::const_iterator t_end, + vuint16 &t_res) { for (auto it = t_begin; it < t_end; ++it) { t_res.push_back(static_cast(*it << 8 | *++it)); } diff --git a/src/bitpack.hh b/src/bitpack.hh index d8ac1f2..b9aa613 100644 --- a/src/bitpack.hh +++ b/src/bitpack.hh @@ -5,24 +5,28 @@ #include #include -std::vector pack(const std::vector &); +[[nodiscard]] std::vector +pack(const std::vector &); -std::vector pack_n(std::vector::const_iterator, - std::vector::const_iterator, - std::vector &, int); +[[nodiscard]] std::vector +pack_n(std::vector::const_iterator, + std::vector::const_iterator, std::vector &, + int); -std::vector pack_16(std::vector::const_iterator, - std::vector::const_iterator, - std::vector &); +[[nodiscard]] std::vector +pack_16(std::vector::const_iterator, + std::vector::const_iterator, + std::vector &); -std::vector unpack(std::basic_string &&); +[[nodiscard]] std::vector +unpack(std::basic_string &&); -std::vector +[[nodiscard]] std::vector unpack_n(std::basic_string::const_iterator t_begin, std::basic_string::const_iterator t_end, std::vector &, int t_n); -std::vector +[[nodiscard]] std::vector unpack_16(std::basic_string::const_iterator, std::basic_string::const_iterator, std::vector &); diff --git a/src/common.cc b/src/common.cc index ea1c0ba..6909434 100644 --- a/src/common.cc +++ b/src/common.cc @@ -6,7 +6,7 @@ using dic_comp_t = std::map, uint16_t>; using ustring = std::basic_string; using p_ustring = std::shared_ptr; -int ipow(int base, int exp) { +[[nodiscard]] int ipow(int base, int exp) { int result = 1; for (;;) { if (exp & 1) { @@ -21,20 +21,21 @@ int ipow(int base, int exp) { return result; } -std::pair dico(dic_comp_t &t_dictionary, - const uint16_t t_nr_chaine, const uint8_t t_c) { +[[nodiscard]] std::pair +dico(dic_comp_t &t_dictionary, const uint16_t t_nr_chaine, const uint8_t t_c) { if (t_nr_chaine == 0xFFFF) { return std::make_pair(true, t_c); } auto &e = t_dictionary[std::make_pair(t_nr_chaine, t_c)]; - if(e != 0) + if (e != 0) return std::make_pair(true, e); e = static_cast(t_dictionary.size() + 255); return std::make_pair(false, e); } -ustring dico_uncompress(std::map &t_dict, - const uint16_t t_code, const uint16_t t_old) { +[[nodiscard]] ustring dico_uncompress(std::map &t_dict, + const uint16_t t_code, + const uint16_t t_old) { // le code existe dans le dictionnaire s’il est < 256 if (t_code < 256) { ustring e{static_cast(t_code)}; diff --git a/src/common.hh b/src/common.hh index 6b25d04..ff9a3f5 100644 --- a/src/common.hh +++ b/src/common.hh @@ -5,13 +5,13 @@ #include #include -int ipow(int, int); +[[nodiscard]] int ipow(int, int); -std::pair +[[nodiscard]] std::pair dico(std::map, std::uint16_t> &, const std::uint16_t, const std::uint8_t); -std::basic_string +[[nodiscard]] std::basic_string dico_uncompress(std::map> &, const std::uint16_t, const std::uint16_t); diff --git a/src/compress.cc b/src/compress.cc index 9928a55..a279123 100644 --- a/src/compress.cc +++ b/src/compress.cc @@ -17,7 +17,7 @@ using ustring = std::basic_string; using dict_t = std::map, uint16_t>; using std::printf; -ustring read_file(const string &filename) { +[[nodiscard]] ustring read_file(const string &filename) { std::ifstream file{filename, ios::binary}; assert(file); file.unsetf(ios::skipws); @@ -32,7 +32,7 @@ ustring read_file(const string &filename) { return res; } -vvuint16 lzw_compress(ustring &&t_text) { +[[nodiscard]] vvuint16 lzw_compress(ustring &&t_text) { vvuint16 res{}; const auto DICT_MAX = static_cast(ipow(2, 14) - 256); /* 16 bits */ uint16_t w = 0xFFFF; diff --git a/src/compress.hh b/src/compress.hh index 2047ac9..66be2f8 100644 --- a/src/compress.hh +++ b/src/compress.hh @@ -6,7 +6,7 @@ #include #include -std::vector> +[[nodiscard]] std::vector> lzw_compress(std::basic_string &&); void compress(const std::string &, const char *); diff --git a/src/main.cc b/src/main.cc index c04aeae..4b3747e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -37,7 +37,8 @@ Options available:\n\ \t\"_uncompresed\" will be added"); } -std::tuple process_args(int t_argc, char *t_argv[]) { +[[nodiscard]] std::tuple process_args(int t_argc, + char *t_argv[]) { auto ret = std::make_tuple(string{}, string{}, true); while (true) { int option_index = 0; @@ -82,7 +83,7 @@ std::tuple process_args(int t_argc, char *t_argv[]) { int main(int argc, char *argv[]) { const auto [input_path, output_path, compressing] = process_args(argc, argv); - if(input_path.empty()) { + if (input_path.empty()) { help(); return 0; } diff --git a/src/uncompress.cc b/src/uncompress.cc index f826296..60e17d2 100644 --- a/src/uncompress.cc +++ b/src/uncompress.cc @@ -16,7 +16,7 @@ using std::vector; using ustring = std::basic_string; using vuint16 = vector; -ustring lzw_uncompress(vuint16 &&t_compressed) { +[[nodiscard]] ustring lzw_uncompress(vuint16 &&t_compressed) { ustring ret{}; uint16_t old = 0; std::map dict{}; diff --git a/src/uncompress.hh b/src/uncompress.hh index 699c77a..e5b070b 100644 --- a/src/uncompress.hh +++ b/src/uncompress.hh @@ -6,10 +6,11 @@ #include #include -std::basic_string lzw_uncompress(std::vector &&); +[[nodiscard]] std::basic_string +lzw_uncompress(std::vector &&); void uncompress(const std::string &, const char *); -void uncompress_chunk(FILE *, std::ofstream&); +void uncompress_chunk(FILE *, std::ofstream &); #endif /* LZW_SRC_UNCOMPRESS_H_ */