My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
module.cpp
Go to the documentation of this file.
1
/*
2
* module.cpp - module class implementation
3
*
4
* Copyright (C) 2008, 2009, 2010 Stefan Jahn <stefan@lkcc.org>
5
*
6
* This is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* This software is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this package; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19
* Boston, MA 02110-1301, USA.
20
*
21
* $Id: module.cpp 1826 2011-03-12 01:00:56Z ela $
22
*
23
*/
24
25
#if HAVE_CONFIG_H
26
# include <config.h>
27
#endif
28
29
#include <stdio.h>
30
#include <stdlib.h>
31
32
#include "
netdefs.h
"
33
#include "components.h"
34
#include "
analyses.h
"
35
#include "
netdefs.h
"
36
#include "
module.h
"
37
38
// Global module hash.
39
qucs::hash<module>
module::modules
;
40
41
// Constructor creates an instance of the module class.
42
module::module
() {
43
definition
= NULL;
44
circreate
= NULL;
45
anacreate
= NULL;
46
}
47
48
// Destructor deletes an instance of the module class.
49
module::~module
() {
50
}
51
52
// Definitions which do not fit elsewhere.
53
static
struct
property_t
props1[] = {
54
PROP_NO_PROP
};
55
static
struct
property_t
props2[] = {
56
{
"Type"
,
PROP_STR
, {
PROP_NO_VAL
,
"DEF1"
},
PROP_NO_RANGE
},
57
PROP_NO_PROP
};
58
59
struct
define_t
miscdef1
=
60
{
"Def"
,
PROP_NODES
,
PROP_ACTION
,
PROP_NO_SUBSTRATE
,
PROP_LINEAR
,
61
props1, props1 };
62
63
struct
define_t
miscdef2
=
64
{
"Sub"
,
PROP_NODES
,
PROP_COMPONENT
,
PROP_NO_SUBSTRATE
,
PROP_LINEAR
,
65
props1, props2 };
66
67
// Registers an analysis object to the list of available modules.
68
void
module::registerModule
(
analysis_definer_t
define,
69
analysis_creator_t
create) {
70
module
* m =
new
module
();
71
m->
definition
= define ();
72
m->
anacreate
= create;
73
modules
.
put
((
char
*) define()->
type
, m);
74
}
75
76
// Registers a circuit object to the list of available modules.
77
void
module::registerModule
(
circuit_definer_t
define,
78
circuit_creator_t
create) {
79
module
* m =
new
module
();
80
m->
definition
= define ();
81
m->
circreate
= create;
82
registerModule
(define()->
type
, m);
83
}
84
85
// Registers a miscellaneous object to the list of available modules.
86
void
module::registerModule
(
misc_definer_t
define) {
87
module
* m =
new
module
();
88
m->
definition
= define ();
89
registerModule
(define()->
type
, m);
90
}
91
92
/* Registers a miscellaneous structure just defined by a somple
93
define_t structure to the list of available modules. */
94
void
module::registerModule
(
struct
define_t
* define) {
95
module
* m =
new
module
();
96
m->
definition
= define;
97
registerModule
(define->
type
, m);
98
}
99
100
// Puts a module into the available module hash.
101
void
module::registerModule
(
const
char
*
type
,
module
* m) {
102
if
(
modules
.
get
((
char
*) type) != NULL) {
103
logprint
(
LOG_ERROR
,
"module already registered: %s\n"
, type);
104
}
105
else
{
106
modules
.
put
((
char
*) type, m);
107
}
108
}
109
110
/* Returns the definition of a module specified by its type name if
111
such is existing and otherwise NULL. */
112
struct
define_t
*
module::getModule
(
char
* type) {
113
module
* m =
modules
.
get
(type);
114
if
(m != NULL) {
115
return
m->
definition
;
116
}
117
return
NULL;
118
}
119
120
// Helper macros.
121
#define REGISTER_CIRCUIT(val) \
122
registerModule (&val::definition, &val::create)
123
#define REGISTER_ANALYSIS(val) \
124
registerModule (&val::definition, &val::create)
125
#define REGISTER_MISC(val) \
126
registerModule (&val::definition)
127
128
// Global static module registration.
129
void
module::registerModules
(
void
) {
130
131
// miscellaneous
132
registerModule
(&miscdef1);
133
registerModule
(&miscdef2);
134
REGISTER_MISC
(
nodeset
);
135
REGISTER_MISC
(
substrate
);
136
137
// circuit components
138
REGISTER_CIRCUIT
(
resistor
);
139
REGISTER_CIRCUIT
(
capacitor
);
140
REGISTER_CIRCUIT
(
pac
);
141
REGISTER_CIRCUIT
(
inductor
);
142
REGISTER_CIRCUIT
(
vccs
);
143
REGISTER_CIRCUIT
(
cccs
);
144
REGISTER_CIRCUIT
(
vcvs
);
145
REGISTER_CIRCUIT
(
ccvs
);
146
REGISTER_CIRCUIT
(
biastee
);
147
REGISTER_CIRCUIT
(
dcfeed
);
148
REGISTER_CIRCUIT
(
dcblock
);
149
REGISTER_CIRCUIT
(
circulator
);
150
REGISTER_CIRCUIT
(
attenuator
);
151
REGISTER_CIRCUIT
(
isolator
);
152
REGISTER_CIRCUIT
(
trafo
);
153
REGISTER_CIRCUIT
(
strafo
);
154
REGISTER_CIRCUIT
(
vdc
);
155
REGISTER_CIRCUIT
(
idc
);
156
REGISTER_CIRCUIT
(
vac
);
157
REGISTER_CIRCUIT
(
iac
);
158
REGISTER_CIRCUIT
(
iexp
);
159
REGISTER_CIRCUIT
(
vexp
);
160
REGISTER_CIRCUIT
(
ifile
);
161
REGISTER_CIRCUIT
(
vfile
);
162
REGISTER_CIRCUIT
(
vam
);
163
REGISTER_CIRCUIT
(
vpm
);
164
REGISTER_CIRCUIT
(
vpulse
);
165
REGISTER_CIRCUIT
(
ipulse
);
166
REGISTER_CIRCUIT
(
vrect
);
167
REGISTER_CIRCUIT
(
irect
);
168
REGISTER_CIRCUIT
(
gyrator
);
169
REGISTER_CIRCUIT
(
phaseshifter
);
170
REGISTER_CIRCUIT
(
tswitch
);
171
REGISTER_CIRCUIT
(
relais
);
172
REGISTER_CIRCUIT
(
tline
);
173
REGISTER_CIRCUIT
(
tline4p
);
174
REGISTER_CIRCUIT
(
ctline
);
175
REGISTER_CIRCUIT
(
coaxline
);
176
REGISTER_CIRCUIT
(
rectline
);
177
REGISTER_CIRCUIT
(
twistedpair
);
178
REGISTER_CIRCUIT
(
rlcg
);
179
REGISTER_CIRCUIT
(
coupler
);
180
REGISTER_CIRCUIT
(
hybrid
);
181
REGISTER_CIRCUIT
(
diode
);
182
REGISTER_CIRCUIT
(
eqndefined
);
183
REGISTER_CIRCUIT
(
rfedd
);
184
REGISTER_CIRCUIT
(
diac
);
185
REGISTER_CIRCUIT
(
thyristor
);
186
REGISTER_CIRCUIT
(
triac
);
187
REGISTER_CIRCUIT
(
tunneldiode
);
188
REGISTER_CIRCUIT
(
msline
);
189
REGISTER_CIRCUIT
(
mscorner
);
190
REGISTER_CIRCUIT
(
msstep
);
191
REGISTER_CIRCUIT
(
msopen
);
192
REGISTER_CIRCUIT
(
msgap
);
193
REGISTER_CIRCUIT
(
msmbend
);
194
REGISTER_CIRCUIT
(
mscoupled
);
195
REGISTER_CIRCUIT
(
mstee
);
196
REGISTER_CIRCUIT
(
mscross
);
197
REGISTER_CIRCUIT
(
msvia
);
198
REGISTER_CIRCUIT
(
msrstub
);
199
REGISTER_CIRCUIT
(
bondwire
);
200
REGISTER_CIRCUIT
(
cpwline
);
201
REGISTER_CIRCUIT
(
cpwopen
);
202
REGISTER_CIRCUIT
(
cpwshort
);
203
REGISTER_CIRCUIT
(
cpwgap
);
204
REGISTER_CIRCUIT
(
cpwstep
);
205
REGISTER_CIRCUIT
(
iprobe
);
206
REGISTER_CIRCUIT
(
vprobe
);
207
REGISTER_CIRCUIT
(
jfet
);
208
REGISTER_CIRCUIT
(
bjt
);
209
REGISTER_CIRCUIT
(
spfile
);
210
REGISTER_CIRCUIT
(
vnoise
);
211
REGISTER_CIRCUIT
(
inoise
);
212
REGISTER_CIRCUIT
(
mosfet
);
213
REGISTER_CIRCUIT
(
amplifier
);
214
REGISTER_CIRCUIT
(
opamp
);
215
REGISTER_CIRCUIT
(
iinoise
);
216
REGISTER_CIRCUIT
(
mutual
);
217
REGISTER_CIRCUIT
(
mutual2
);
218
REGISTER_CIRCUIT
(
mutualx
);
219
REGISTER_CIRCUIT
(
ivnoise
);
220
REGISTER_CIRCUIT
(
vvnoise
);
221
REGISTER_CIRCUIT
(
inverter
);
222
REGISTER_CIRCUIT
(
logicnor
);
223
REGISTER_CIRCUIT
(
logicor
);
224
REGISTER_CIRCUIT
(
logicnand
);
225
REGISTER_CIRCUIT
(
logicand
);
226
REGISTER_CIRCUIT
(
logicxnor
);
227
REGISTER_CIRCUIT
(
logicxor
);
228
REGISTER_CIRCUIT
(
digisource
);
229
REGISTER_CIRCUIT
(
buffer
);
230
REGISTER_CIRCUIT
(
hicumL2V2p1
);
231
REGISTER_CIRCUIT
(
HBT_X
);
232
REGISTER_CIRCUIT
(
mod_amp
);
233
REGISTER_CIRCUIT
(
hic2_full
);
234
REGISTER_CIRCUIT
(
log_amp
);
235
REGISTER_CIRCUIT
(
hic0_full
);
236
REGISTER_CIRCUIT
(
potentiometer
);
237
REGISTER_CIRCUIT
(
MESFET
);
238
REGISTER_CIRCUIT
(
EKV26MOS
);
239
REGISTER_CIRCUIT
(
hicumL0V1p2
);
240
REGISTER_CIRCUIT
(
hicumL0V1p2g
);
241
REGISTER_CIRCUIT
(
hicumL0V1p3
);
242
REGISTER_CIRCUIT
(
hicumL2V2p23
);
243
REGISTER_CIRCUIT
(
hicumL2V2p24
);
244
REGISTER_CIRCUIT
(
photodiode
);
245
REGISTER_CIRCUIT
(
phototransistor
);
246
REGISTER_CIRCUIT
(
nigbt
);
247
REGISTER_CIRCUIT
(
dff_SR
);
248
REGISTER_CIRCUIT
(
tff_SR
);
249
REGISTER_CIRCUIT
(
jkff_SR
);
250
REGISTER_CIRCUIT
(
gatedDlatch
);
251
REGISTER_CIRCUIT
(
logic_1
);
252
REGISTER_CIRCUIT
(
logic_0
);
253
REGISTER_CIRCUIT
(
mux2to1
);
254
REGISTER_CIRCUIT
(
mux4to1
);
255
REGISTER_CIRCUIT
(
mux8to1
);
256
REGISTER_CIRCUIT
(
DLS_nto1
);
257
REGISTER_CIRCUIT
(
DLS_1ton
);
258
REGISTER_CIRCUIT
(
andor4x2
);
259
REGISTER_CIRCUIT
(
andor4x3
);
260
REGISTER_CIRCUIT
(
andor4x4
);
261
REGISTER_CIRCUIT
(
dmux2to4
);
262
REGISTER_CIRCUIT
(
dmux3to8
);
263
REGISTER_CIRCUIT
(
dmux4to16
);
264
REGISTER_CIRCUIT
(
ha1b
);
265
REGISTER_CIRCUIT
(
fa1b
);
266
REGISTER_CIRCUIT
(
fa2b
);
267
REGISTER_CIRCUIT
(
pad2bit
);
268
REGISTER_CIRCUIT
(
pad3bit
);
269
REGISTER_CIRCUIT
(
pad4bit
);
270
REGISTER_CIRCUIT
(
binarytogrey4bit
);
271
REGISTER_CIRCUIT
(
greytobinary4bit
);
272
REGISTER_CIRCUIT
(
comp_1bit
);
273
REGISTER_CIRCUIT
(
comp_2bit
);
274
REGISTER_CIRCUIT
(
comp_4bit
);
275
REGISTER_CIRCUIT
(
hpribin4bit
);
276
277
// analyses
278
REGISTER_ANALYSIS
(
dcsolver
);
279
REGISTER_ANALYSIS
(
acsolver
);
280
REGISTER_ANALYSIS
(
spsolver
);
281
REGISTER_ANALYSIS
(
trsolver
);
282
REGISTER_ANALYSIS
(
hbsolver
);
283
REGISTER_ANALYSIS
(
parasweep
);
284
}
285
286
// Global module unregistration.
287
void
module::unregisterModules
(
void
) {
288
qucs::hashiterator<module>
it;
289
for
(it =
qucs::hashiterator<module>
(
modules
); *it; ++it) {
290
delete
it.
currentVal
();
291
}
292
modules
.
clear
();
293
}
294
295
#if DEBUG
296
// header prefix
297
static
const
char
* def_prefix =
298
"/*\n"
299
" * qucsdefs.h - netlist definitions for the Qucs netlists\n"
300
" *\n"
301
" * This is free software; you can redistribute it and/or modify\n"
302
" * it under the terms of the GNU General Public License as published by\n"
303
" * the Free Software Foundation; either version 2, or (at your option)\n"
304
" * any later version.\n"
305
" * \n"
306
" */\n"
307
"\n"
308
"#ifndef __QUCSDEFS_H__\n"
309
"#define __QUCSDEFS_H__\n"
;
310
311
// header suffix
312
static
const
char
* def_suffix =
313
"\n"
314
"#endif /* __QUCSDEFS_H__ */\n"
;
315
316
// start of list of definitions
317
static
const
char
* def_start =
318
"\n"
319
"// List of available components.\n"
320
"struct define_t qucs_definition_available[] =\n"
;
321
322
// end of list entry
323
static
const
char
* def_stop =
324
"\n"
325
"static struct define_t def_End = {\n"
326
" ((char *) 0), -1, 1, 0, 0, req_Def, opt_Def };\n"
;
327
328
// Returns a compilable C-code string made from the given string.
329
static
char
* printstr (
const
char
* str) {
330
static
char
txt[256];
331
int
nostr = (str ==
PROP_NO_STR
);
332
sprintf (txt,
"%s%s%s"
,
333
(str && !nostr) ?
"\""
:
""
,
334
str ? nostr ?
"((char *) -1)"
: str :
"((char *) 0)"
,
335
(str && !nostr) ?
"\""
:
""
);
336
return
txt;
337
}
338
339
// Prints a property list as compilable C-code.
340
static
void
printprop (
const
char
* type,
const
char
* prefix,
341
struct
property_t
* prop) {
342
const
char
* key;
343
const
char
** str;
344
const
char
* txt;
345
fprintf
(stdout,
"static struct property_t %s_%s[] = {\n"
, prefix, type);
346
do
{
347
key = prop->
key
;
348
fprintf
(stdout,
" { %s, %d, "
, printstr (key), prop->
type
);
349
fprintf
(stdout,
"{ %g, %s }, "
, prop->
defaultval
.
d
,
350
printstr (prop->
defaultval
.
s
));
351
fprintf
(stdout,
"{ '%c', %g, %g, '%c',\n"
,
352
prop->
range
.
il
, prop->
range
.
l
, prop->
range
.
h
, prop->
range
.
ih
);
353
fprintf
(stdout,
" {"
);
354
str = prop->
range
.
str
;
355
do
{
356
txt = *str;
357
fprintf
(stdout,
" %s"
, printstr (txt));
358
if
(txt)
fprintf
(stdout,
","
);
359
str++;
360
}
361
while
(txt != NULL);
362
fprintf
(stdout,
" } } }"
);
363
if
(key)
fprintf
(stdout,
","
);
364
fprintf
(stdout,
"\n"
);
365
prop++;
366
}
367
while
(key != NULL);
368
fprintf
(stdout,
"};\n"
);
369
}
370
371
/* The function emits a complete list of the registered component
372
definitions as compilable C-code. */
373
void
module::print
(
void
) {
374
fprintf
(stdout, def_prefix);
375
qucs::hashiterator<module>
it;
376
for
(it =
qucs::hashiterator<module>
(
modules
); *it; ++it) {
377
module
* m = it.
currentVal
();
378
struct
define_t
* def = m->
definition
;
379
fprintf
(stdout,
"\n"
);
380
printprop (def->
type
,
"req"
, def->
required
);
381
fprintf
(stdout,
"\n"
);
382
printprop (def->
type
,
"opt"
, def->
optional
);
383
fprintf
(stdout,
"\n"
);
384
fprintf
(stdout,
"static struct define_t def_%s = {\n"
, def->
type
);
385
fprintf
(stdout,
" %s, %d, %d, %d, %d, req_%s, opt_%s };\n"
,
386
printstr (def->
type
), def->
nodes
, def->
action
, def->
substrate
,
387
def->
nonlinear
, def->
type
, def->
type
);
388
}
389
fprintf
(stdout, def_stop);
390
fprintf
(stdout, def_start);
391
fprintf
(stdout,
"{\n"
);
392
for
(it =
qucs::hashiterator<module>
(
modules
); *it; ++it) {
393
module
* m = it.
currentVal
();
394
struct
define_t
* def = m->
definition
;
395
fprintf
(stdout,
" def_%s,\n"
, def->
type
);
396
}
397
fprintf
(stdout,
" def_End\n"
);
398
fprintf
(stdout,
"};\n"
);
399
fprintf
(stdout, def_suffix);
400
}
401
#endif
/* DEBUG */
Generated on Tue Dec 25 2012 14:30:43 for My Project by
1.8.2