Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nasolution.cpp
Go to the documentation of this file.
1 /*
2  * nasolution.cpp - nodal analysis solution template class implementation
3  *
4  * Copyright (C) 2006 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 #include <assert.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "nasolution.h"
31 
32 namespace qucs {
33 
34 // Constructor creates an instance of the nasolution class.
35 template <class nr_type_t>
37 }
38 
39 /* This copy constructor creates a instance of the nasolution class based
40  on the given nasolution. */
41 template <class nr_type_t>
43  entries = valuelist< naentry<nr_type_t> > (p.entries);
44 }
45 
46 // Destructor deletes a nasolution object.
47 template <class nr_type_t>
49  clear ();
50 }
51 
52 // Resets the nasolution object.
53 template <class nr_type_t>
55  entries.clear ();
56 }
57 
58 // Adds a new solution entry into the nasolution list.
59 template <class nr_type_t>
60 void nasolution<nr_type_t>::add (char * n, nr_type_t value, int current) {
61  naentry<nr_type_t> * entry = new naentry<nr_type_t> (n, value, current);
62  entries.add (n, entry);
63 }
64 
65 // Finds the given nasolution entry in the list.
66 template <class nr_type_t>
68  for (valuelistiterator< naentry<nr_type_t> > it (entries); *it; ++it) {
69  naentry<nr_type_t> * na = it.currentVal ();
70  if (na->current == current) {
71  if (na->n && n && !strcmp (na->n, n))
72  return na;
73  }
74  }
75  return NULL;
76 }
77 
78 // Constructor creates an instance of the naentry class.
79 template <class nr_type_t>
81  value = 0;
82  n = NULL;
83  current = -1;
84 }
85 
86 // Constructor creates an instance of the naentry class.
87 template <class nr_type_t>
88 naentry<nr_type_t>::naentry (char * na, nr_type_t val, int cur) {
89  value = val;
90  n = na ? strdup (na) : NULL;
91  current = cur;
92 }
93 
94 /* This copy constructor creates a instance of the naentry class based
95  on the given naentry. */
96 template <class nr_type_t>
98  value = o.value;
99  n = o.n ? strdup (o.n) : NULL;
100  current = o.current;
101 }
102 
103 // Destructor deletes a naentry object.
104 template <class nr_type_t>
106  if (n) free (n);
107 }
108 
109 } // namespace qucs
n
Definition: parse_citi.y:147
valuelist< naentry< nr_type_t > > entries
Definition: nasolution.h:62
nr_type_t value
Definition: nasolution.h:45
void clear(void)
Definition: nasolution.cpp:54
naentry< nr_type_t > * find(char *, int)
Definition: nasolution.cpp:67
free($1)
void add(char *, nr_type_t, int)
Definition: nasolution.cpp:60
value
Definition: parse_vcd.y:315