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
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: devstates.cpp 1825 2011-03-11 20:42:14Z 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
#include <string.h>
32
33
#include "
devstates.h
"
34
35
// Default constructor for device state class instance.
36
devstates::devstates
() {
37
nstates = 0;
38
nvars = 0;
39
states
= NULL;
40
nstate = 0;
41
pstate = NULL;
42
}
43
44
// Constructor for device state class instance.
45
devstates::devstates
(
int
vars,
int
states
) {
46
deviceStates
(vars, states);
47
}
48
49
// Destructor for device state class instance.
50
devstates::~devstates
() {
51
if
(
states
) free (
states
);
52
}
53
54
/* Initializes the device state class instance containing the
55
specified number of variables and states. */
56
void
devstates::deviceStates
(
int
vars,
int
stats) {
57
nvars = vars;
58
nstates = stats;
59
if
(
states
) free (
states
);
60
states
= (nr_double_t *) malloc (
sizeof
(nr_double_t) * nvars * nstates);
61
nstate = 0;
62
pstate =
states
;
63
}
64
65
// Returns the number of states.
66
int
devstates::deviceStates
(
void
) {
67
return
nstates;
68
}
69
70
// Sets the current state.
71
void
devstates::deviceState
(
int
state) {
72
nstate = state;
73
pstate = &
states
[nvars * nstate];
74
}
75
76
// Returns the current state.
77
int
devstates::deviceState
(
void
) {
78
return
nstate;
79
}
80
81
// Access operator for the given variable in the current state.
82
nr_double_t
devstates::operator ()
(
int
var)
const
{
83
return
pstate[var];
84
}
85
86
// Reference access operator for the given variable in the current state.
87
nr_double_t&
devstates::operator ()
(
int
var) {
88
return
pstate[var];
89
}
90
91
// Returns the given variable in the current state.
92
nr_double_t
devstates::deviceVar
(
int
var)
const
{
93
return
pstate[var];
94
}
95
96
// Returns a reference to the given variable in the current state.
97
nr_double_t&
devstates::deviceVar
(
int
var) {
98
return
pstate[var];
99
}
Generated on Tue Dec 25 2012 14:30:33 for My Project by
1.8.2