Branch data Line data Source code
1 : : /*
2 : : * variable.cpp - generic variable class implementation
3 : : *
4 : : * Copyright (C) 2004, 2007 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$
22 : : *
23 : : */
24 : :
25 : : #if HAVE_CONFIG_H
26 : : # include <config.h>
27 : : #endif
28 : :
29 : : #include <stdio.h>
30 : : #include <stdlib.h>
31 : : #include <string.h>
32 : :
33 : : #include "logging.h"
34 : : #include "equation.h"
35 : : #include "components/microstrip/substrate.h"
36 : : #include "analysis.h"
37 : : #include "variable.h"
38 : :
39 : : namespace qucs {
40 : :
41 : : // Constructor creates an unnamed instance of the variable class.
42 : 0 : variable::variable () : name() {
43 : 0 : next = NULL;
44 : 0 : type = VAR_UNKNOWN;
45 : 0 : pass = true;
46 : 0 : }
47 : :
48 : : // This constructor creates a named instance of the variable class.
49 : 90 : variable::variable (const char * const n) {
50 [ + - ][ + - ]: 90 : name = n ? std::string(n) : std::string();
[ # # ][ + - ]
[ + - ]
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
51 : 90 : next = NULL;
52 : 90 : type = VAR_UNKNOWN;
53 : 90 : pass = true;
54 : 90 : }
55 : :
56 : : /* This copy constructor creates a instance of the variable class based
57 : : on the given variable. */
58 : 81 : variable::variable (const variable & o) {
59 [ + - # # ]: 81 : this->name = o.name;
60 : 81 : type = o.type;
61 : 81 : next = o.next;
62 : 81 : pass = o.pass;
63 : 81 : value = o.value;
64 : 81 : }
65 : :
66 : :
67 : : // Creates textual representation of a variable.
68 : 0 : const char * variable::toString (void) {
69 [ # # ]: 0 : std::string text;
70 : 0 : char * str = NULL;
71 : 0 : char * val = NULL;
72 [ # # # # : 0 : switch (type) {
# # # ]
73 : : case VAR_UNKNOWN:
74 [ # # ]: 0 : text = "variable";
75 : 0 : break;
76 : : case VAR_CONSTANT:
77 [ # # ]: 0 : str = value.c->toString ();
78 [ # # ][ # # ]: 0 : text = "constant: "+std::string(str);
[ # # ]
79 : 0 : break;
80 : : case VAR_VALUE:
81 [ # # ]: 0 : str = value.v->toString ();
82 [ # # ][ # # ]: 0 : text = "value: "+std::string(str);
[ # # ]
83 : 0 : break;
84 : : case VAR_REFERENCE:
85 [ # # ]: 0 : str = value.r->toString ();
86 [ # # ]: 0 : val = value.r->getResult()->toString ();
87 [ # # ][ # # ]: 0 : text = "reference: "+std::string(str)+" = "+std::string(val);
[ # # ][ # # ]
[ # # ][ # # ]
88 : 0 : break;
89 : : case VAR_SUBSTRATE:
90 : 0 : str = value.s->getName ();
91 [ # # ][ # # ]: 0 : text = "substrate: "+std::string(str);
[ # # ]
92 : 0 : break;
93 : : case VAR_ANALYSIS:
94 : 0 : str = value.a->getName ();
95 [ # # ][ # # ]: 0 : text = "analysis: "+std::string(str);
[ # # ]
96 : 0 : break;
97 : : default:
98 [ # # ]: 0 : text = "?variable?";
99 : 0 : break;
100 : : }
101 : 0 : return text.c_str();
102 : : }
103 : :
104 : : } // namespace qucs
|