Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / filter / generate_gr_fir_sysconfig_generic.py
1 #!/bin/env python
2 # -*- python -*-
3 #
4 # Copyright 2003 Free Software Foundation, Inc.
5
6 # This file is part of GNU Radio
7
8 # GNU Radio is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # GNU Radio is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Radio; see the file COPYING.  If not, write to
20 # the Free Software Foundation, Inc., 51 Franklin Street,
21 # Boston, MA 02110-1301, USA.
22
23
24 from generate_utils import *
25
26
27 # ----------------------------------------------------------------
28
29 def make_gr_fir_sysconfig_generic_h ():
30     out = open_and_log_name ('gr_fir_sysconfig_generic.h', 'w')
31     out.write (copyright)
32
33     out.write (
34 '''
35 /*
36  * WARNING: This file is automatically generated by
37  * generate_gr_fir_sysconfig_generic.py.
38  *
39  * Any changes made to this file will be overwritten.
40  */
41
42 #ifndef _GR_FIR_SYSCONFIG_GENERIC_H_
43 #define _GR_FIR_SYSCONFIG_GENERIC_H_
44
45 #include <gr_fir_sysconfig.h>
46
47 ''')
48
49     out.write (
50 '''
51 class gr_fir_sysconfig_generic : public gr_fir_sysconfig {
52 public:
53 ''')
54     
55     for sig in fir_signatures:
56       out.write (('  virtual gr_fir_%s *create_gr_fir_%s (const std::vector<%s> &taps);\n' %
57         (sig, sig, tap_type (sig))))
58
59     out.write ('\n')
60
61     for sig in fir_signatures:
62       out.write (('  virtual void get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info);\n' %
63         (sig, sig)))
64
65     out.write (
66 '''
67 };
68
69
70 #endif /* _GR_FIR_SYSCONFIG_GENERIC_H_ */
71 ''')
72     out.close ()
73     
74
75 # ----------------------------------------------------------------
76
77 def make_constructor (sig, out):
78     out.write ('''
79 static gr_fir_%s *
80 make_gr_fir_%s (const std::vector<%s> &taps)
81 {
82   return new gr_fir_%s_generic (taps);
83 }
84 ''' % (sig, sig, tap_type (sig), sig))
85   
86
87 def make_creator (sig, out):
88     out.write ('''
89 gr_fir_%s *
90 gr_fir_sysconfig_generic::create_gr_fir_%s (const std::vector<%s> &taps)
91 {
92   return make_gr_fir_%s (taps);
93 }
94 ''' % (sig, sig, tap_type (sig), sig))
95     
96
97 def make_info (sig, out):
98     out.write ('''
99 void
100 gr_fir_sysconfig_generic::get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info)
101 {
102   info->resize (1);
103   (*info)[0].name = "generic";
104   (*info)[0].create = make_gr_fir_%s;
105 }
106 ''' % (sig, sig, sig))
107
108     
109 # ----------------------------------------------------------------
110
111 def make_gr_fir_sysconfig_generic_cc ():
112     out = open_and_log_name ('gr_fir_sysconfig_generic.cc', 'w')
113     out.write (copyright)
114
115     out.write (
116 '''
117 /*
118  * WARNING: This file is automatically generated by
119  * generate_gr_fir_sysconfig_generic.py.
120  *
121  * Any changes made to this file will be overwritten.
122  */
123
124 #ifdef HAVE_CONFIG_H
125 #include <config.h>
126 #endif
127 #include <gr_fir_sysconfig_generic.h>
128
129 ''')
130     
131     for sig in fir_signatures:
132         out.write ('#include <gr_fir_%s_generic.h>\n' % (sig))
133
134     out.write (
135 '''
136 /*
137  * ----------------------------------------------------------------
138  * static functions that serve as constructors returned by info
139  * ----------------------------------------------------------------
140  */
141 ''')
142
143     for sig in fir_signatures:
144         make_constructor (sig, out)
145
146     out.write (
147 '''
148 /*
149  * ----------------------------------------------------------------
150  * return instances of the generic C++ versions of these classes.
151  * ----------------------------------------------------------------
152  */
153 ''')
154
155     for sig in fir_signatures:
156         make_creator (sig, out)
157
158     out.write (
159 '''
160 /*
161  * Return info about available implementations.
162  *
163  * This is the bottom of the concrete hierarchy, so we set the
164  * size of the vector to 1, and install our info.  Classes derived
165  * from us invoke us first, then append their own info.
166  */
167 ''')
168
169     for sig in fir_signatures:
170         make_info (sig, out)
171
172
173     out.close ()
174
175 # ----------------------------------------------------------------
176
177 def generate ():
178     make_gr_fir_sysconfig_generic_h ()
179     make_gr_fir_sysconfig_generic_cc ()
180
181 if __name__ == '__main__':
182     generate ()