Houston, we have a trunk.
[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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef INCLUDED_ENCODER_H
24 #define INCLUDED_ENCODER_H
25
26 #include "code_types.h"
27
28 // the 'encoder' class is a virtual class upon which all encoder types
29 // can be built.
30
31 class encoder
32 {
33 public:
34   encoder () {};
35   virtual ~encoder () {};
36
37   virtual size_t compute_n_input_bits (size_t n_output_bits) = 0;
38   virtual size_t compute_n_output_bits (size_t n_input_bits) = 0;
39   virtual size_t encode (const char** in_buf,
40                          char** out_buf,
41                          size_t n_bits_to_output);
42   virtual size_t encode (const char** in_buf,
43                          size_t n_bits_to_input,
44                          char** out_buf);
45
46 /* for remote access to internal info */
47
48   inline size_t block_size_bits () {return (d_block_size_bits);};
49   inline size_t n_code_inputs () {return (d_n_code_inputs);};
50   inline size_t n_code_outputs () {return (d_n_code_outputs);};
51
52 protected:
53   /* encode_private: encode the given in_buf and write the output bits
54    * to the out_buf, using internal class variables.  This function is
55    * called from the publically available "encode()" methods, which
56    * first set the internal class variables before executing.
57    */
58
59   virtual void encode_private (const char** in_buf, char** out_buf) = 0;
60
61   /* inheriting methods need to figure out what makes the most sense
62    * for them in terms of getting new inputs and writing outputs.
63    */
64
65   size_t d_block_size_bits, d_n_code_inputs, d_n_code_outputs;
66   size_t d_n_enc_bits, d_total_n_enc_bits;
67   size_t d_in_buf_ndx, d_out_buf_ndx;
68   size_t d_in_bit_shift, d_out_bit_shift;
69   size_t d_n_input_bits_left, d_n_output_bits_left;
70 };
71
72 #endif /* INCLUDED_ENCODER_H */