summaryrefslogtreecommitdiff
path: root/gr-error-correcting-codes/src/lib/libecc/decoder.h
blob: b8a2acf1205b3f7c6f3311b66b913db33eeca2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* -*- c++ -*- */
/*
 * Copyright 2006 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * GNU Radio 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
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef INCLUDED_DECODER_H
#define INCLUDED_DECODER_H

#include "code_io.h"

class decoder
{
  /*
   * class decoder
   * A virtual class upon which all decoder types can be built.
   * This class provides the basic methods and variables
   * generic for all decoders.
   */
public:
  decoder () {};
  virtual ~decoder () {};

  /*
   * compute_n_...: to be defined by inheriting classes, in order to
   * allow for user-functions to figure out how many inputs are
   * required to generate a given number of outputs, and vice versa.
   * Can't define them without knowing the decoder type.
   *
   * Compute the number of input items (metrics, floats, whatevers)
   * needed to produce 'n_output' bits, and the number of output bits
   * which will be produced by 'n_input' items ... for a single stream
   * only.
   */

  virtual size_t compute_n_input_items (size_t n_output_bits) = 0;
  virtual size_t compute_n_output_bits (size_t n_input_items) = 0;

  /*
   * decode: given the input and output buffers, either decode up to
   * the number of output bits or decode the number of input items
   * ... if the buffers support either decoding amounts.
   */

  virtual size_t decode (const code_input_ptr in_buf,
			 code_output_ptr out_buf,
			 size_t n_bits_to_output);
  virtual size_t decode (const code_input_ptr in_buf,
			 size_t n_items_to_input,
			 code_output_ptr out_buf);

/* for remote access to internal info */

  inline const size_t block_size_bits () {return (d_block_size_bits);};
  inline const size_t n_code_inputs () {return (d_n_code_inputs);};
  inline const size_t n_code_outputs () {return (d_n_code_outputs);};
  inline const size_t total_n_dec_bits () {return (d_total_n_dec_bits);};

protected:
  /*
   * decode_private: decode the given in_buf and write the output bits
   * to the out_buf, using internal class variables.  This function is
   * called from the publically available "encode()" methods, which
   * first set the internal class variables before executing.
   */

  virtual void decode_private () = 0;

  size_t d_block_size_bits, d_n_code_inputs, d_n_code_outputs;
  size_t d_total_n_dec_bits, d_n_items_to_input, d_n_bits_to_output;
  code_input_ptr d_in_buf;
  code_output_ptr d_out_buf;
};

#endif /* INCLUDED_DECODER_H */