Branch data Line data Source code
1 : : /*
2 : : * nodeset.cpp - node set class implementation
3 : : *
4 : : * Copyright (C) 2004, 2008 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 "object.h"
34 : : #include "netdefs.h"
35 : : #include "nodeset.h"
36 : :
37 : : namespace qucs {
38 : :
39 : : // Constructor creates an unnamed instance of the node set class.
40 : 2 : nodeset::nodeset () {
41 : 2 : name = NULL;
42 : 2 : value = 0.0;
43 : 2 : next = NULL;
44 : 2 : }
45 : :
46 : : // Constructor creates a named instance of the node set class.
47 : 0 : nodeset::nodeset (char * n) {
48 [ # # ][ # # ]: 0 : name = n ? strdup (n) : NULL;
49 : 0 : value = 0.0;
50 : 0 : next = NULL;
51 : 0 : }
52 : :
53 : : /* This full qualified constructor creates an instance of the node set
54 : : class containing both the key and the value of the node set. */
55 : 0 : nodeset::nodeset (char * n, nr_double_t val) {
56 [ # # ][ # # ]: 0 : name = n ? strdup (n) : NULL;
57 : 0 : value = val;
58 : 0 : next = NULL;
59 : 0 : }
60 : :
61 : : /* The copy constructor creates a new instance of the node set class
62 : : based on the given node set object. */
63 : 0 : nodeset::nodeset (const nodeset & p) {
64 : 0 : name = NULL;
65 [ # # ][ # # ]: 0 : if (p.name) name = strdup (p.name);
66 : 0 : value = p.value;
67 : 0 : next = p.next;
68 : 0 : }
69 : :
70 : : // Destructor deletes the node set object.
71 : 4 : nodeset::~nodeset () {
72 [ + - ][ # # ]: 2 : if (name) free (name);
73 [ - + ][ # # ]: 4 : }
74 : :
75 : : // Sets the name of the node set.
76 : 2 : void nodeset::setName (char * n) {
77 [ - + ]: 2 : if (name) free (name);
78 [ + - ]: 2 : name = n ? strdup (n) : NULL;
79 : 2 : }
80 : :
81 : : // Returns the name of the node set.
82 : 2 : char * nodeset::getName (void) {
83 : 2 : return name;
84 : : }
85 : :
86 : : /* Goes through the chained list of the node sets and looks for a node
87 : : set matching the given key and returns its value if possible. If
88 : : there is no such node set the function returns NULL. */
89 : 0 : nodeset * nodeset::findNodeset (char * n) {
90 [ # # ]: 0 : for (nodeset * p = this; p != NULL; p = p->getNext ()) {
91 [ # # ]: 0 : if (!strcmp (p->getName (), n)) return p;
92 : : }
93 : 0 : return NULL;
94 : : }
95 : :
96 : : // properties
97 : : PROP_REQ [] = {
98 : : { "U", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
99 : : PROP_OPT [] = {
100 : : PROP_NO_PROP };
101 : : struct define_t nodeset::miscdef =
102 : : { "NodeSet", 1, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
103 : :
104 : : } // namespace qucs
|