diff --git a/QRCodeLibrary/BitArray.hpp b/QRCodeLibrary/BitArray.hpp index 032a5af..84b5177 100644 --- a/QRCodeLibrary/BitArray.hpp +++ b/QRCodeLibrary/BitArray.hpp @@ -6,10 +6,8 @@ #include "utils.hpp" -using namespace std; - constexpr static unsigned ceil_div(unsigned a, unsigned b) { - if (b == 0) throw runtime_error("Dividion by zero not possible"); + if (b == 0) throw std::runtime_error("Dividion by zero not possible"); return a / b + (a % b > 0); } diff --git a/QRCodeLibrary/DataBlocks.cpp b/QRCodeLibrary/DataBlocks.cpp index b3d25d9..79b2abf 100644 --- a/QRCodeLibrary/DataBlocks.cpp +++ b/QRCodeLibrary/DataBlocks.cpp @@ -6,12 +6,12 @@ DataBlocks::DataBlocks(const byte_list& e_data_, CorrectionLevel corr_lvl_, char version_) : e_data{ e_data_ }, corr_lvl{ corr_lvl_ }, version{ version_ } { - vector>data_block_sizes; + std::vector>data_block_sizes; divide_to_blocks(data_block_sizes, to_U(e_data.size()), Tables::data_blocks_number.at(corr_lvl).at(version)); unsigned EC_bytes_number = Tables::correction_bytes_num.at(corr_lvl).at(version); - vector EC_blocks(data_block_sizes.size(), byte_list()); + std::vector EC_blocks(data_block_sizes.size(), byte_list()); for (unsigned i = 0; i < data_block_sizes.size(); i++) compose_EC_bytes(EC_blocks[i], e_data.cbegin() + data_block_sizes[i].second, EC_bytes_number, data_block_sizes[i].first); @@ -19,7 +19,7 @@ DataBlocks::DataBlocks(const byte_list& e_data_, CorrectionLevel corr_lvl_, char join_data_and_EC_blocks(data, e_data, data_block_sizes, EC_blocks, EC_bytes_number); } -void DataBlocks::divide_to_blocks(vector>& db_sizes, unsigned data_size, unsigned db_number) +void DataBlocks::divide_to_blocks(std::vector>& db_sizes, unsigned data_size, unsigned db_number) { db_sizes.reserve(db_number); @@ -34,7 +34,7 @@ void DataBlocks::divide_to_blocks(vector>& db_sizes, un void DataBlocks::compose_EC_bytes(byte_list& res, const byte_list::const_iterator& src, unsigned corr_bytes_num, unsigned db_size) { - res.reserve(max(db_size, corr_bytes_num)); + res.reserve(std::max(db_size, corr_bytes_num)); res.insert(res.end(), src, src + db_size); res.resize(res.capacity(), 0); @@ -57,11 +57,11 @@ void DataBlocks::compose_EC_bytes(byte_list& res, const byte_list::const_iterato } } -unsigned get_db_byte_index(unsigned block_index, unsigned byte_index, const vector>& db_sizes) { +unsigned get_db_byte_index(unsigned block_index, unsigned byte_index, const std::vector>& db_sizes) { return db_sizes[block_index].second + byte_index; } -void DataBlocks::join_data_and_EC_blocks(byte_list& res, const byte_list& e_data, const vector>& db_sizes, const vector& ec_codes, unsigned ec_bytes_number) +void DataBlocks::join_data_and_EC_blocks(byte_list& res, const byte_list& e_data, const std::vector>& db_sizes, const std::vector& ec_codes, unsigned ec_bytes_number) { res.reserve(e_data.size() + ec_codes.at(0).size() * ec_codes.size()); diff --git a/QRCodeLibrary/DataBlocks.hpp b/QRCodeLibrary/DataBlocks.hpp index 8cdde17..8f39f5b 100644 --- a/QRCodeLibrary/DataBlocks.hpp +++ b/QRCodeLibrary/DataBlocks.hpp @@ -5,8 +5,6 @@ #include "BitArray.hpp" #include "Method.hpp" -using namespace std; - class DataBlocks { public: @@ -14,9 +12,9 @@ public: byte_list& get_joined_data_and_EC_blocks() { return data; }; - static void divide_to_blocks(vector>& db_sizes, unsigned data_size, unsigned db_number); + static void divide_to_blocks(std::vector>& db_sizes, unsigned data_size, unsigned db_number); static void compose_EC_bytes(byte_list& res, const byte_list::const_iterator& src, unsigned corr_bytes_num, unsigned db_size); - static void join_data_and_EC_blocks(byte_list&res, const byte_list& e_data, const vector>& db_sizes, const vector& ec_codes, unsigned ec_bytes_number); + static void join_data_and_EC_blocks(byte_list&res, const byte_list& e_data, const std::vector>& db_sizes, const std::vector& ec_codes, unsigned ec_bytes_number); private: const byte_list& e_data; diff --git a/QRCodeLibrary/Encoder.cpp b/QRCodeLibrary/Encoder.cpp index 118dbf1..f733132 100644 --- a/QRCodeLibrary/Encoder.cpp +++ b/QRCodeLibrary/Encoder.cpp @@ -61,7 +61,7 @@ void Encoder::write_metadata(unsigned input_size, unsigned input_bits_amount_siz out.set(4, input_size, input_bits_amount_size); } -void Encoder::encode_numeric(const string& input, BitArray& out, unsigned offset) +void Encoder::encode_numeric(const std::string& input, BitArray& out, unsigned offset) { int bin; for (unsigned i = 0; i < input.size() / 3; i++) { @@ -79,7 +79,7 @@ void Encoder::encode_numeric(const string& input, BitArray& out, unsigned offset } } -void Encoder::encode_alphabetic(const string& input, BitArray& out, unsigned offset) +void Encoder::encode_alphabetic(const std::string& input, BitArray& out, unsigned offset) { for (unsigned i = 0; i < input.size() / 2; i++) { int bin = encode_char(input[i * 2]) * 45 + encode_char(input[i * 2 + 1]); diff --git a/QRCodeLibrary/Encoder.hpp b/QRCodeLibrary/Encoder.hpp index 3b06562..66ba4f4 100644 --- a/QRCodeLibrary/Encoder.hpp +++ b/QRCodeLibrary/Encoder.hpp @@ -8,8 +8,6 @@ #include "BitArray.hpp" #include "utils.hpp" -using namespace std; - class Encoder { public: @@ -36,8 +34,8 @@ public: } }; - static void encode_numeric(const string& input, BitArray& out, unsigned offset); - static void encode_alphabetic(const string& input, BitArray& out, unsigned offset); + static void encode_numeric(const std::string& input, BitArray& out, unsigned offset); + static void encode_alphabetic(const std::string& input, BitArray& out, unsigned offset); static void encode_byte(const byte_list& input, BitArray& out, unsigned offset); static void pad_data(BitArray& arr, unsigned bits_written); @@ -84,7 +82,7 @@ constexpr unsigned Encoder::calculate_encoded_input_size(unsigned input_size, QR } template -constexpr unsigned upper_index(const array& arr, T val) { +constexpr unsigned upper_index(const std::array& arr, T val) { unsigned count = N, s = 0, e = 0, step = 0; while (count > 0) { diff --git a/QRCodeLibrary/Method.hpp b/QRCodeLibrary/Method.hpp index 6d9351e..bec5cdb 100644 --- a/QRCodeLibrary/Method.hpp +++ b/QRCodeLibrary/Method.hpp @@ -2,8 +2,6 @@ #include "utils.hpp" -using namespace std; - enum class QRCodeMethod { Dynamic, Numeric, diff --git a/QRCodeLibrary/QRCode.hpp b/QRCodeLibrary/QRCode.hpp index 5be5373..ba26b74 100644 --- a/QRCodeLibrary/QRCode.hpp +++ b/QRCodeLibrary/QRCode.hpp @@ -6,17 +6,15 @@ #include "QRMatrix.hpp" #include "utils.hpp" -using namespace std; - class QRCode { public: QRCode(const byte_list& input_, CorrectionLevel corr_lvl_ = CorrectionLevel::M, QRCodeMethod method_ = QRCodeMethod::Dynamic, char version_ = -1, unsigned char mask_n = 0); - QRCode(const string& input_, CorrectionLevel corr_lvl_ = CorrectionLevel::M, QRCodeMethod method_ = QRCodeMethod::Dynamic, char version_ = -1, unsigned char mask_n = 0) : QRCode(str_to_bytes(input_), corr_lvl_, method_, version_, mask_n) {}; + QRCode(const std::string& input_, CorrectionLevel corr_lvl_ = CorrectionLevel::M, QRCodeMethod method_ = QRCodeMethod::Dynamic, char version_ = -1, unsigned char mask_n = 0) : QRCode(str_to_bytes(input_), corr_lvl_, method_, version_, mask_n) {}; - string to_string() const { return matrix.to_string(); }; - string to_ascii(char black = '#', char white = ' ', char empty = 'E') const { return matrix.to_ascii(black, white, empty); } - vector> to_vector() const { return matrix.to_vector(); }; + std::string to_string() const { return matrix.to_string(); }; + std::string to_ascii(char black = '#', char white = ' ', char empty = 'E') const { return matrix.to_ascii(black, white, empty); } + std::vector> to_vector() const { return matrix.to_vector(); }; protected: byte_list input; diff --git a/QRCodeLibrary/Tables.hpp b/QRCodeLibrary/Tables.hpp index d1333b8..5acd261 100644 --- a/QRCodeLibrary/Tables.hpp +++ b/QRCodeLibrary/Tables.hpp @@ -112,8 +112,8 @@ namespace Tables { 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175 }; - static const array, 40>alignment_patterns_coordinates{ - vector(), {18,}, {22,}, {26,}, {30,}, + static const std::array, 40>alignment_patterns_coordinates{ + std::vector(), {18,}, {22,}, {26,}, {30,}, {34,}, {6, 22, 38}, {6, 24, 42}, {6, 26, 46}, {6, 28, 50}, {6, 30, 54}, {6, 32, 58}, {6, 34, 62}, {6, 26, 46, 66}, {6, 26, 48, 70}, {6, 26, 50, 74}, {6, 30, 54, 78}, {6, 30, 56, 82}, {6, 30, 58, 86}, {6, 34, 62, 90}, @@ -124,7 +124,7 @@ namespace Tables { {6, 28, 54, 80, 106, 132, 158}, {6, 32, 58, 84, 110, 136, 162}, {6, 26, 54, 82, 110, 138, 166}, {6, 30, 58, 86, 114, 142, 170} }; - static constexpr array, 34>version_codes{ { + static constexpr std::array, 34>version_codes{ { { 0b000010, 0b011110, 0b100110 }, { 0b010001, 0b011100, 0b111000 }, { 0b110111, 0b011000, 0b000100 }, @@ -161,7 +161,7 @@ namespace Tables { { 0b111001, 0b000100, 0b010101 } } }; - static const map>corr_lvl_and_mask_codes{ + static const std::map>corr_lvl_and_mask_codes{ { CorrectionLevel::L, { 0b111011111000100, 0b111001011110011, 0b111110110101010, 0b111100010011101, 0b110011000101111, 0b110001100011000, 0b110110001000001, 0b110100101110110 } }, @@ -176,7 +176,7 @@ namespace Tables { } }; - static const array, 8>mask_functions{ { + static const std::array, 8>mask_functions{ { [](unsigned y, unsigned x) { return (x + y) % 2; }, [](unsigned y, unsigned x) { return y % 2; }, [](unsigned y, unsigned x) { return x % 3; }, diff --git a/QRCodeLibrary/TritMatrix.cpp b/QRCodeLibrary/TritMatrix.cpp index 252d73f..e3a6db8 100644 --- a/QRCodeLibrary/TritMatrix.cpp +++ b/QRCodeLibrary/TritMatrix.cpp @@ -25,9 +25,9 @@ void TritMatrix::set(unsigned y, unsigned x, bool val) set(y, x, val ? Trit::T : Trit::F); } -string TritMatrix::to_ascii(char black, char white, char empty) const +std::string TritMatrix::to_ascii(char black, char white, char empty) const { - string res; + std::string res; for (unsigned i = 0; i < c.size(); i++) { for (unsigned j = 0; j < c.at(0).size(); j++) diff --git a/QRCodeLibrary/TritMatrix.hpp b/QRCodeLibrary/TritMatrix.hpp index 0569faf..6c8e90b 100644 --- a/QRCodeLibrary/TritMatrix.hpp +++ b/QRCodeLibrary/TritMatrix.hpp @@ -3,8 +3,6 @@ #include #include -using namespace std; - enum Trit { EMPTY = -1, F, @@ -14,8 +12,8 @@ enum Trit { class TritMatrix { public: - TritMatrix(unsigned width, unsigned height) : c{ height, vector(width, Trit::EMPTY) } {}; - TritMatrix(unsigned size) : c{ size, vector(size, Trit::EMPTY) } {}; + TritMatrix(unsigned width, unsigned height) : c{ height, std::vector(width, Trit::EMPTY) } {}; + TritMatrix(unsigned size) : c{ size, std::vector(size, Trit::EMPTY) } {}; Trit get(unsigned y, unsigned x) const; @@ -25,11 +23,11 @@ public: void resize(unsigned width, unsigned height); - string to_ascii(char black = '#', char white = ' ', char empty = 'E') const; - string to_string() const { return to_ascii('1', '0', 'E'); }; - vector> to_vector() const { return c; }; + std::string to_ascii(char black = '#', char white = ' ', char empty = 'E') const; + std::string to_string() const { return to_ascii('1', '0', 'E'); }; + std::vector> to_vector() const { return c; }; protected: - vector> c; + std::vector> c; }; diff --git a/tests/DataBlocks_test.cpp b/tests/DataBlocks_test.cpp index 5993f5c..de7c5b1 100644 --- a/tests/DataBlocks_test.cpp +++ b/tests/DataBlocks_test.cpp @@ -5,6 +5,9 @@ #include "../QRCodeLibrary/DataBlocks.hpp" +using std::vector; +using std::pair; + TEST(DataBlocksTests, ComposesSizesOfDatablocks) { vector> db_s;