Qucs-core  0.0.19
variable.cpp
Go to the documentation of this file.
00001 /*
00002  * variable.cpp - generic variable class implementation
00003  *
00004  * Copyright (C) 2004, 2007 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 "logging.h"
00034 #include "equation.h"
00035 #include "components/microstrip/substrate.h"
00036 #include "analysis.h"
00037 #include "variable.h"
00038 
00039 namespace qucs {
00040 
00041 // Constructor creates an unnamed instance of the variable class.
00042 variable::variable () : name() {
00043   next = NULL;
00044   type = VAR_UNKNOWN;
00045   pass = true;
00046 }
00047 
00048 // This constructor creates a named instance of the variable class.
00049 variable::variable (const char * const n) {
00050   name = n ? std::string(n) : std::string();
00051   next = NULL;
00052   type = VAR_UNKNOWN;
00053   pass = true;
00054 }
00055 
00056 /* This copy constructor creates a instance of the variable class based
00057    on the given variable. */
00058 variable::variable (const variable & o) {
00059   this->name = o.name;
00060   type = o.type;
00061   next = o.next;
00062   pass = o.pass;
00063   value = o.value;
00064 }
00065 
00066 
00067 // Creates textual representation of a variable.
00068 const char * variable::toString (void) {
00069   std::string text;
00070   const char * str = NULL;
00071   char * val = NULL;
00072   switch (type) {
00073   case VAR_UNKNOWN:
00074     text = "variable";
00075     break;
00076   case VAR_CONSTANT:
00077     str = value.c->toString ();
00078     text = "constant: "+std::string(str);
00079     break;
00080   case VAR_VALUE:
00081     str = value.v->toString ();
00082     text = "value: "+std::string(str);
00083     break;
00084   case VAR_REFERENCE:
00085     str = value.r->toString ();
00086     val = value.r->getResult()->toString ();
00087     text = "reference: "+std::string(str)+" = "+std::string(val);
00088     break;
00089   case VAR_SUBSTRATE:
00090     str = value.s->getName ();
00091     text = "substrate: "+std::string(str);
00092     break;
00093   case VAR_ANALYSIS:
00094     str = value.a->getName ();
00095     text = "analysis: "+std::string(str);
00096     break;
00097   default:
00098     text = "?variable?";
00099     break;
00100   }
00101   return text.c_str();
00102 }
00103 
00104 } // namespace qucs