Removed using namespace std
This commit is contained in:
parent
63f20afae0
commit
880a3e9908
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<pair<unsigned, unsigned>>data_block_sizes;
|
||||
std::vector<std::pair<unsigned, unsigned>>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<byte_list> EC_blocks(data_block_sizes.size(), byte_list());
|
||||
std::vector<byte_list> 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<pair<unsigned, unsigned>>& db_sizes, unsigned data_size, unsigned db_number)
|
||||
void DataBlocks::divide_to_blocks(std::vector<std::pair<unsigned, unsigned>>& db_sizes, unsigned data_size, unsigned db_number)
|
||||
{
|
||||
db_sizes.reserve(db_number);
|
||||
|
||||
@ -34,7 +34,7 @@ void DataBlocks::divide_to_blocks(vector<pair<unsigned, unsigned>>& 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<pair<unsigned, unsigned>>& db_sizes) {
|
||||
unsigned get_db_byte_index(unsigned block_index, unsigned byte_index, const std::vector<std::pair<unsigned, unsigned>>& 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<pair<unsigned, unsigned>>& db_sizes, const vector<byte_list>& ec_codes, unsigned ec_bytes_number)
|
||||
void DataBlocks::join_data_and_EC_blocks(byte_list& res, const byte_list& e_data, const std::vector<std::pair<unsigned, unsigned>>& db_sizes, const std::vector<byte_list>& ec_codes, unsigned ec_bytes_number)
|
||||
{
|
||||
res.reserve(e_data.size() + ec_codes.at(0).size() * ec_codes.size());
|
||||
|
||||
|
@ -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<pair<unsigned, unsigned>>& db_sizes, unsigned data_size, unsigned db_number);
|
||||
static void divide_to_blocks(std::vector<std::pair<unsigned, unsigned>>& 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<pair<unsigned, unsigned>>& db_sizes, const vector<byte_list>& ec_codes, unsigned ec_bytes_number);
|
||||
static void join_data_and_EC_blocks(byte_list&res, const byte_list& e_data, const std::vector<std::pair<unsigned, unsigned>>& db_sizes, const std::vector<byte_list>& ec_codes, unsigned ec_bytes_number);
|
||||
|
||||
private:
|
||||
const byte_list& e_data;
|
||||
|
@ -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]);
|
||||
|
@ -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 <typename T, size_t N>
|
||||
constexpr unsigned upper_index(const array<T, N>& arr, T val) {
|
||||
constexpr unsigned upper_index(const std::array<T, N>& arr, T val) {
|
||||
unsigned count = N, s = 0, e = 0, step = 0;
|
||||
|
||||
while (count > 0) {
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum class QRCodeMethod {
|
||||
Dynamic,
|
||||
Numeric,
|
||||
|
@ -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<vector<Trit>> 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<std::vector<Trit>> to_vector() const { return matrix.to_vector(); };
|
||||
|
||||
protected:
|
||||
byte_list input;
|
||||
|
@ -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<const vector<unsigned>, 40>alignment_patterns_coordinates{
|
||||
vector<unsigned>(), {18,}, {22,}, {26,}, {30,},
|
||||
static const std::array<const std::vector<unsigned>, 40>alignment_patterns_coordinates{
|
||||
std::vector<unsigned>(), {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<const array<unsigned char, 3>, 34>version_codes{ {
|
||||
static constexpr std::array<const std::array<unsigned char, 3>, 34>version_codes{ {
|
||||
{ 0b000010, 0b011110, 0b100110 },
|
||||
{ 0b010001, 0b011100, 0b111000 },
|
||||
{ 0b110111, 0b011000, 0b000100 },
|
||||
@ -161,7 +161,7 @@ namespace Tables {
|
||||
{ 0b111001, 0b000100, 0b010101 }
|
||||
} };
|
||||
|
||||
static const map<CorrectionLevel, array<unsigned short, 8>>corr_lvl_and_mask_codes{
|
||||
static const std::map<CorrectionLevel, std::array<unsigned short, 8>>corr_lvl_and_mask_codes{
|
||||
{ CorrectionLevel::L,
|
||||
{ 0b111011111000100, 0b111001011110011, 0b111110110101010, 0b111100010011101, 0b110011000101111, 0b110001100011000, 0b110110001000001, 0b110100101110110 }
|
||||
},
|
||||
@ -176,7 +176,7 @@ namespace Tables {
|
||||
}
|
||||
};
|
||||
|
||||
static const array<std::function<bool(unsigned, unsigned)>, 8>mask_functions{ {
|
||||
static const std::array<std::function<bool(unsigned, unsigned)>, 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; },
|
||||
|
@ -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++)
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
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<Trit>(width, Trit::EMPTY) } {};
|
||||
TritMatrix(unsigned size) : c{ size, vector<Trit>(size, Trit::EMPTY) } {};
|
||||
TritMatrix(unsigned width, unsigned height) : c{ height, std::vector<Trit>(width, Trit::EMPTY) } {};
|
||||
TritMatrix(unsigned size) : c{ size, std::vector<Trit>(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<vector<Trit>> 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<std::vector<Trit>> to_vector() const { return c; };
|
||||
|
||||
protected:
|
||||
vector<vector<Trit>> c;
|
||||
std::vector<std::vector<Trit>> c;
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
#include "../QRCodeLibrary/DataBlocks.hpp"
|
||||
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
|
||||
TEST(DataBlocksTests, ComposesSizesOfDatablocks) {
|
||||
vector<pair<unsigned, unsigned>> db_s;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user