MCPcopy Create free account
hub / github.com/aff3ct/aff3ct / Encoder_user

Method Encoder_user

src/Module/Encoder/User/Encoder_user.cpp:66–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65template<typename B>
66Encoder_user<B>::Encoder_user(const int K, const int N, const std::string& filename, const int start_idx)
67 : Encoder<B>(K, N)
68 , codewords()
69 , cw_counter(start_idx)
70{
71 const std::string name = "Encoder_user";
72 this->set_name(name);
73 for (auto& t : this->tasks)
74 t->set_replicability(true);
75
76 if (filename.empty())
77 throw spu::tools::invalid_argument(__FILE__, __LINE__, __func__, "'filename' should not be empty.");
78
79 std::ifstream file(filename.c_str(), std::ios::in);
80
81 if (file.is_open())
82 {
83 int n_cw = 0, src_size = 0, cw_size = 0;
84
85 file >> n_cw;
86 file >> cw_size;
87 file >> src_size;
88
89 if (n_cw <= 0 || src_size <= 0 || cw_size <= 0)
90 {
91 std::stringstream message;
92 message << "'n_cw', 'src_size' and 'cw_size' have to be greater than 0 ('n_cw' = " << n_cw
93 << ", 'src_size' = " << src_size << ", 'cw_size' = " << cw_size << ").";
94 throw spu::tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
95 }
96
97 if (cw_size < src_size)
98 {
99 std::stringstream message;
100 message << "'cw_size' has to be equal or greater than 'src_size' ('cw_size' = " << cw_size
101 << ", 'src_size' = " << src_size << ").";
102 throw spu::tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
103 }
104
105 this->codewords.resize(n_cw);
106 for (auto i = 0; i < n_cw; i++)
107 this->codewords[i].resize(cw_size);
108
109 if ((src_size == this->K) && (cw_size == this->N))
110 {
111 for (auto i = 0; i < n_cw; i++)
112 for (auto j = 0; j < cw_size; j++)
113 {
114 int symbol;
115 file >> symbol;
116 this->codewords[i][j] = (B)symbol;
117 }
118 }
119 else
120 {
121 std::stringstream message;
122 message << "The number of information bits or the codeword size is wrong "
123 << "(read: {" << src_size << "," << cw_size << "}, "

Callers

nothing calls this directly

Calls 2

read_info_bits_posFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected