Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
devstates.cpp
Go to the documentation of this file.
1 /*
2  * devstates.cpp - device state 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 #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 "devstates.h"
34 
35 namespace qucs {
36 
37 // Default constructor for device state class instance.
39  nstates = 0;
40  nvars = 0;
41  states = NULL;
42  nstate = 0;
43  pstate = NULL;
44 }
45 
46 // Constructor for device state class instance.
47 devstates::devstates (int vars, int states) {
48  deviceStates (vars, states);
49 }
50 
51 // Destructor for device state class instance.
53  if (states) free (states);
54 }
55 
56 /* Initializes the device state class instance containing the
57  specified number of variables and states. */
58 void devstates::deviceStates (int vars, int stats) {
59  nvars = vars;
60  nstates = stats;
61  if (states) free (states);
62  states = (nr_double_t *) malloc (sizeof (nr_double_t) * nvars * nstates);
63  nstate = 0;
64  pstate = states;
65 }
66 
67 // Returns the number of states.
69  return nstates;
70 }
71 
72 // Sets the current state.
73 void devstates::deviceState (int state) {
74  nstate = state;
75  pstate = &states[nvars * nstate];
76 }
77 
78 // Returns the current state.
80  return nstate;
81 }
82 
83 // Access operator for the given variable in the current state.
84 nr_double_t devstates::operator () (int var) const {
85  return pstate[var];
86 }
87 
88 // Reference access operator for the given variable in the current state.
89 nr_double_t& devstates::operator () (int var) {
90  return pstate[var];
91 }
92 
93 // Returns the given variable in the current state.
94 nr_double_t devstates::deviceVar (int var) const {
95  return pstate[var];
96 }
97 
98 // Returns a reference to the given variable in the current state.
99 nr_double_t& devstates::deviceVar (int var) {
100  return pstate[var];
101 }
102 
103 } // namespace qucs
nr_double_t operator()(int) const
Definition: devstates.cpp:84
nr_double_t * states
Definition: devstates.h:52
nr_double_t * pstate
Definition: devstates.h:53
template class for storing state variables.
Definition: states.h:38
free($1)
int deviceState(void)
Definition: devstates.cpp:79
nr_double_t deviceVar(int) const
Definition: devstates.cpp:94
var
Definition: parse_citi.y:145
int deviceStates(void)
Definition: devstates.cpp:68