Qucs-core
0.0.19
|
00001 /* 00002 * devstates.cpp - device state class implementation 00003 * 00004 * Copyright (C) 2006 Stefan Jahn <stefan@lkcc.org> 00005 * 00006 * This is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2, or (at your option) 00009 * any later version. 00010 * 00011 * This software is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this package; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 * $Id$ 00022 * 00023 */ 00024 00025 #if HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #include <string.h> 00032 00033 #include "devstates.h" 00034 00035 namespace qucs { 00036 00037 // Default constructor for device state class instance. 00038 devstates::devstates () { 00039 nstates = 0; 00040 nvars = 0; 00041 states = NULL; 00042 nstate = 0; 00043 pstate = NULL; 00044 } 00045 00046 // Constructor for device state class instance. 00047 devstates::devstates (int vars, int states) { 00048 deviceStates (vars, states); 00049 } 00050 00051 // Destructor for device state class instance. 00052 devstates::~devstates () { 00053 free (states); 00054 } 00055 00056 /* Initializes the device state class instance containing the 00057 specified number of variables and states. */ 00058 void devstates::deviceStates (int vars, int stats) { 00059 nvars = vars; 00060 nstates = stats; 00061 free (states); 00062 states = (nr_double_t *) malloc (sizeof (nr_double_t) * nvars * nstates); 00063 nstate = 0; 00064 pstate = states; 00065 } 00066 00067 // Returns the number of states. 00068 int devstates::deviceStates (void) { 00069 return nstates; 00070 } 00071 00072 // Sets the current state. 00073 void devstates::deviceState (int state) { 00074 nstate = state; 00075 pstate = &states[nvars * nstate]; 00076 } 00077 00078 // Returns the current state. 00079 int devstates::deviceState (void) { 00080 return nstate; 00081 } 00082 00083 // Access operator for the given variable in the current state. 00084 nr_double_t devstates::operator () (int var) const { 00085 return pstate[var]; 00086 } 00087 00088 // Reference access operator for the given variable in the current state. 00089 nr_double_t& devstates::operator () (int var) { 00090 return pstate[var]; 00091 } 00092 00093 // Returns the given variable in the current state. 00094 nr_double_t devstates::deviceVar (int var) const { 00095 return pstate[var]; 00096 } 00097 00098 // Returns a reference to the given variable in the current state. 00099 nr_double_t& devstates::deviceVar (int var) { 00100 return pstate[var]; 00101 } 00102 00103 } // namespace qucs