Qucs-core  0.0.19
nodeset.cpp
Go to the documentation of this file.
00001 /*
00002  * nodeset.cpp - node set class implementation
00003  *
00004  * Copyright (C) 2004, 2008 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 "object.h"
00034 #include "netdefs.h"
00035 #include "nodeset.h"
00036 
00037 namespace qucs {
00038 
00039 // Constructor creates an unnamed instance of the node set class.
00040 nodeset::nodeset () {
00041   name = NULL;
00042   value = 0.0;
00043   next = NULL;
00044 }
00045 
00046 // Constructor creates a named instance of the node set class.
00047 nodeset::nodeset (char * n) {
00048   name = n ? strdup (n) : NULL;
00049   value = 0.0;
00050   next = NULL;
00051 }
00052 
00053 /* This full qualified constructor creates an instance of the node set
00054    class containing both the key and the value of the node set. */
00055 nodeset::nodeset (char * n, nr_double_t val) {
00056   name = n ? strdup (n) : NULL;
00057   value = val;
00058   next = NULL;
00059 }
00060 
00061 /* The copy constructor creates a new instance of the node set class
00062    based on the given node set object. */
00063 nodeset::nodeset (const nodeset & p) {
00064   name = NULL;
00065   if (p.name) name = strdup (p.name);
00066   value = p.value;
00067   next = p.next;
00068 }
00069 
00070 // Destructor deletes the node set object.
00071 nodeset::~nodeset () {
00072   free (name);
00073 }
00074 
00075 // Sets the name of the node set.
00076 void nodeset::setName (char * n) {
00077   free (name);
00078   name = n ? strdup (n) : NULL;
00079 }
00080 
00081 // Returns the name of the node set.
00082 char * nodeset::getName (void) {
00083   return name;
00084 }
00085 
00086 /* Goes through the chained list of the node sets and looks for a node
00087    set matching the given key and returns its value if possible.  If
00088    there is no such node set the function returns NULL. */
00089 nodeset * nodeset::findNodeset (char * n) {
00090   for (nodeset * p = this; p != NULL; p = p->getNext ()) {
00091     if (!strcmp (p->getName (), n)) return p;
00092   }
00093   return NULL;
00094 }
00095 
00096 // properties
00097 PROP_REQ [] = {
00098   { "U", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
00099 PROP_OPT [] = {
00100   PROP_NO_PROP };
00101 struct define_t nodeset::miscdef =
00102   { "NodeSet", 1, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
00103 
00104 } // namespace qucs