Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-error-correcting-codes / src / lib / libecc / encoder.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_ENCODER_H
24 #define INCLUDED_ENCODER_H
25
26 #include "code_io.h"
27
28 class encoder
29 {
30   /*
31    * class encoder
32    * A virtual class upon which all encoder types can be built.
33    * This class provides the basic methods and variables
34    * generic for all encoders.
35    */
36 public:
37   encoder () {};
38   virtual ~encoder () {};
39
40   /*
41    * compute_n_...: to be defined by inheriting classes, in order to
42    * allow for user-functions to figure out how many inputs are
43    * required to generate a given number of outputs, and vice versa.
44    * Can't define them without knowing the encoder type.
45    *
46    * Compute the number of input bits needed to produce 'n_output' bits,
47    * and the number of output bits which will be produced by 'n_input'
48    * bits ... for a single stream only.
49    */
50
51   virtual size_t compute_n_input_bits (size_t n_output_bits) = 0;
52   virtual size_t compute_n_output_bits (size_t n_input_bits) = 0;
53
54   /*
55    * encode: given the input and output buffers, either encode up to
56    * the number of output bits or encode the number of input bits
57    * ... if the buffers support either encoding amounts.
58    */
59
60   virtual size_t encode (const code_input_ptr in_buf,
61                          code_output_ptr out_buf,
62                          size_t n_bits_to_output);
63   virtual size_t encode (const code_input_ptr in_buf,
64                          size_t n_bits_to_input,
65                          code_output_ptr out_buf);
66
67 /* for remote access to internal info */
68
69   inline const size_t block_size_bits () {return (d_block_size_bits);};
70   inline const size_t n_code_inputs () {return (d_n_code_inputs);};
71   inline const size_t n_code_outputs () {return (d_n_code_outputs);};
72   inline const size_t total_n_enc_bits () {return (d_total_n_enc_bits);};
73
74 protected:
75   /*
76    * encode_private: encode the given in_buf and write the output bits
77    * to the out_buf, using internal class variables.  This function is
78    * called from the publically available "encode()" methods, which
79    * first set the internal class variables before executing.
80    */
81
82   virtual void encode_private () = 0;
83
84   size_t d_block_size_bits, d_n_code_inputs, d_n_code_outputs;
85   size_t d_total_n_enc_bits, d_n_bits_to_input, d_n_bits_to_output;
86   code_input_ptr d_in_buf;
87   code_output_ptr d_out_buf;
88 };
89
90 #endif /* INCLUDED_ENCODER_H */