Branch data Line data Source code
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.
38 : 28 : devstates::devstates () {
39 : 28 : nstates = 0;
40 : 28 : nvars = 0;
41 : 28 : states = NULL;
42 : 28 : nstate = 0;
43 : 28 : pstate = NULL;
44 : 28 : }
45 : :
46 : : // Constructor for device state class instance.
47 : 0 : devstates::devstates (int vars, int states) {
48 : 0 : deviceStates (vars, states);
49 : 0 : }
50 : :
51 : : // Destructor for device state class instance.
52 : 28 : devstates::~devstates () {
53 [ # # ][ + - ]: 28 : if (states) free (states);
54 : 28 : }
55 : :
56 : : /* Initializes the device state class instance containing the
57 : : specified number of variables and states. */
58 : 12153 : void devstates::deviceStates (int vars, int stats) {
59 : 12153 : nvars = vars;
60 : 12153 : nstates = stats;
61 [ + + ]: 12153 : if (states) free (states);
62 : 12153 : states = (nr_double_t *) malloc (sizeof (nr_double_t) * nvars * nstates);
63 : 12153 : nstate = 0;
64 : 12153 : pstate = states;
65 : 12153 : }
66 : :
67 : : // Returns the number of states.
68 : 24321 : int devstates::deviceStates (void) {
69 : 24321 : return nstates;
70 : : }
71 : :
72 : : // Sets the current state.
73 : 12344 : void devstates::deviceState (int state) {
74 : 12344 : nstate = state;
75 : 12344 : pstate = &states[nvars * nstate];
76 : 12344 : }
77 : :
78 : : // Returns the current state.
79 : 0 : int devstates::deviceState (void) {
80 : 0 : return nstate;
81 : : }
82 : :
83 : : // Access operator for the given variable in the current state.
84 : 0 : nr_double_t devstates::operator () (int var) const {
85 : 0 : return pstate[var];
86 : : }
87 : :
88 : : // Reference access operator for the given variable in the current state.
89 : 0 : nr_double_t& devstates::operator () (int var) {
90 : 0 : return pstate[var];
91 : : }
92 : :
93 : : // Returns the given variable in the current state.
94 : 0 : nr_double_t devstates::deviceVar (int var) const {
95 : 0 : return pstate[var];
96 : : }
97 : :
98 : : // Returns a reference to the given variable in the current state.
99 : 769828 : nr_double_t& devstates::deviceVar (int var) {
100 : 769828 : return pstate[var];
101 : : }
102 : :
103 : : } // namespace qucs
|