Skip to content
CPP_RAW_API_void.cpp 39.9 KiB
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.
Luker's avatar
Luker committed
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);
        return;
    case RaptorQ_type::RQ_ENC_16:
        _encoder = new Encoder<uint16_t*, uint16_t*> (
                            static_cast<Block_Size> (symbols), symbol_size);
        return;
    case RaptorQ_type::RQ_ENC_32:
        _encoder = new Encoder<uint32_t*, uint32_t*> (
                            static_cast<Block_Size> (symbols), symbol_size);
        return;
    case RaptorQ_type::RQ_ENC_64:
        _encoder = new Encoder<uint64_t*, uint64_t*> (
                            static_cast<Block_Size> (symbols), symbol_size);
        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...