Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / filter / generate_gr_fir_sysconfig_generic.py
1 #!/bin/env python
2 # -*- python -*-
3 #
4 # Copyright 2003,2009 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 3, 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     if not out:
32         return
33     out.write (copyright)
34
35     out.write (
36 '''
37 /*
38  * WARNING: This file is automatically generated by
39  * generate_gr_fir_sysconfig_generic.py.
40  *
41  * Any changes made to this file will be overwritten.
42  */
43
44 #ifndef _GR_FIR_SYSCONFIG_GENERIC_H_
45 #define _GR_FIR_SYSCONFIG_GENERIC_H_
46
47 #include <gr_fir_sysconfig.h>
48
49 ''')
50
51     out.write (
52 '''
53 class gr_fir_sysconfig_generic : public gr_fir_sysconfig {
54 public:
55 ''')
56     
57     for sig in fir_signatures:
58       out.write (('  virtual gr_fir_%s *create_gr_fir_%s (const std::vector<%s> &taps);\n' %
59         (sig, sig, tap_type (sig))))
60
61     out.write ('\n')
62
63     for sig in fir_signatures:
64       out.write (('  virtual void get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info);\n' %
65         (sig, sig)))
66
67     out.write (
68 '''
69 };
70
71
72 #endif /* _GR_FIR_SYSCONFIG_GENERIC_H_ */
73 ''')
74     out.close ()
75     
76
77 # ----------------------------------------------------------------
78
79 def make_constructor (sig, out):
80     out.write ('''
81 static gr_fir_%s *
82 make_gr_fir_%s (const std::vector<%s> &taps)
83 {
84   return new gr_fir_%s_generic (taps);
85 }
86 ''' % (sig, sig, tap_type (sig), sig))
87   
88
89 def make_creator (sig, out):
90     out.write ('''
91 gr_fir_%s *
92 gr_fir_sysconfig_generic::create_gr_fir_%s (const std::vector<%s> &taps)
93 {
94   return make_gr_fir_%s (taps);
95 }
96 ''' % (sig, sig, tap_type (sig), sig))
97     
98
99 def make_info (sig, out):
100     out.write ('''
101 void
102 gr_fir_sysconfig_generic::get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info)
103 {
104   info->resize (1);
105   (*info)[0].name = "generic";
106   (*info)[0].create = make_gr_fir_%s;
107 }
108 ''' % (sig, sig, sig))
109
110     
111 # ----------------------------------------------------------------
112
113 def make_gr_fir_sysconfig_generic_cc ():
114     out = open_and_log_name ('gr_fir_sysconfig_generic.cc', 'w')
115     if not out:
116         return
117     out.write (copyright)
118
119     out.write (
120 '''
121 /*
122  * WARNING: This file is automatically generated by
123  * generate_gr_fir_sysconfig_generic.py.
124  *
125  * Any changes made to this file will be overwritten.
126  */
127
128 #ifdef HAVE_CONFIG_H
129 #include <config.h>
130 #endif
131 #include <gr_fir_sysconfig_generic.h>
132
133 ''')
134     
135     for sig in fir_signatures:
136         out.write ('#include <gr_fir_%s_generic.h>\n' % (sig))
137
138     out.write (
139 '''
140 /*
141  * ----------------------------------------------------------------
142  * static functions that serve as constructors returned by info
143  * ----------------------------------------------------------------
144  */
145 ''')
146
147     for sig in fir_signatures:
148         make_constructor (sig, out)
149
150     out.write (
151 '''
152 /*
153  * ----------------------------------------------------------------
154  * return instances of the generic C++ versions of these classes.
155  * ----------------------------------------------------------------
156  */
157 ''')
158
159     for sig in fir_signatures:
160         make_creator (sig, out)
161
162     out.write (
163 '''
164 /*
165  * Return info about available implementations.
166  *
167  * This is the bottom of the concrete hierarchy, so we set the
168  * size of the vector to 1, and install our info.  Classes derived
169  * from us invoke us first, then append their own info.
170  */
171 ''')
172
173     for sig in fir_signatures:
174         make_info (sig, out)
175
176
177     out.close ()
178
179 # ----------------------------------------------------------------
180
181 def generate ():
182     make_gr_fir_sysconfig_generic_h ()
183     make_gr_fir_sysconfig_generic_cc ()
184
185 if __name__ == '__main__':
186     generate ()