Newer
Older
/*
* Copyright (c) 2016, Luca Fulchir<luca@fulchir.it>, All rights reserved.
*
* This file is part of "libRaptorQ".
*
* libRaptorQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* libRaptorQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and a copy of the GNU Lesser General Public License
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RaptorQ/v1/wrapper/CPP_RAW_API_void.hpp"
#include "RaptorQ/v1/RaptorQ.hpp"
namespace RaptorQ__v1 {
namespace Impl {
// check that we have the right type, else keep error.
static RaptorQ_type init_t (const RaptorQ_type type, const bool is_encoder)
{
switch (type) {
case RaptorQ_type::RQ_ENC_8:
return (is_encoder ? RaptorQ_type::RQ_ENC_8 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_16:
return (is_encoder ? RaptorQ_type::RQ_ENC_16 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_32:
return (is_encoder ? RaptorQ_type::RQ_ENC_32 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_64:
return (is_encoder ? RaptorQ_type::RQ_ENC_64 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_DEC_8:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_8);
case RaptorQ_type::RQ_DEC_16:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_16);
case RaptorQ_type::RQ_DEC_32:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_32);
case RaptorQ_type::RQ_DEC_64:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_64);
case RaptorQ_type::RQ_NONE:
break;
}
return RaptorQ_type::RQ_NONE;
}
////////////////
//// Encoder
/////////////////
Encoder_void::Encoder_void (const RaptorQ_type type,
const RaptorQ_Block_Size symbols,
const size_t symbol_size)
: _type (init_t (type, true))
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
_encoder = new Encoder<uint8_t*, uint8_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint16_t*, uint16_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint32_t*, uint32_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint64_t*, uint64_t*> (
static_cast<Block_Size> (symbols), symbol_size);
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
return;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
_encoder = nullptr;
}
Encoder_void::~Encoder_void()
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
delete reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_16:
delete reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_32:
delete reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_64:
delete reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
_type = RaptorQ_type::RQ_NONE;
_encoder = nullptr;
}
Encoder_void::operator bool() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder);
case RaptorQ_type::RQ_ENC_16:
return reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder);
case RaptorQ_type::RQ_ENC_32:
return reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder);
case RaptorQ_type::RQ_ENC_64:
return reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder);
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return false;
}
uint16_t Encoder_void::symbols() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder)->
symbols();
case RaptorQ_type::RQ_ENC_16:
return reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder)->
symbols();
case RaptorQ_type::RQ_ENC_32:
return reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder)->
symbols();
case RaptorQ_type::RQ_ENC_64:
return reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder)->
symbols();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
size_t Encoder_void::symbol_size() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder)->
symbol_size();
case RaptorQ_type::RQ_ENC_16:
return reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder)->
symbol_size();
case RaptorQ_type::RQ_ENC_32:
return reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder)->
symbol_size();
case RaptorQ_type::RQ_ENC_64:
return reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder)->
symbol_size();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
uint32_t Encoder_void::max_repair() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder)->
max_repair();
case RaptorQ_type::RQ_ENC_16:
return reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder)->
max_repair();
case RaptorQ_type::RQ_ENC_32:
return reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder)->
max_repair();
case RaptorQ_type::RQ_ENC_64:
return reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder)->
Loading full blame...