Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range.cpp
Go to the documentation of this file.
1 /*
2  * range.cpp - range 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 "range.h"
34 
35 namespace qucs {
36 
37 // Constructor creates an instance of the range class.
39  il = ih = '.';
40  l = h = 0.0;
41  txt = NULL;
42 }
43 
44 // Constructor creates an fully qualified instance of the range class.
45 range::range (char ilo, nr_double_t lo, nr_double_t hi, char ihi) {
46  il = ilo;
47  ih = ihi;
48  if (lo > hi) {
49  h = lo;
50  l = hi;
51  } else {
52  l = lo;
53  h = hi;
54  }
55  txt = NULL;
56 }
57 
58 /* This copy constructor creates a instance of the range class based
59  on the given range. */
60 range::range (const range & r) {
61  txt = r.txt ? strdup (r.txt) : NULL;
62  il = r.il;
63  ih = r.ih;
64  l = r.l;
65  h = r.h;
66 }
67 
68 /* Checks whether the given value is outside the range. */
69 bool range::outside (nr_double_t value) {
70  return !inside (value);
71 }
72 
73 /* Checks whether the given value is inside the range. */
74 bool range::inside (nr_double_t value) {
75  int err = 0;
76  if (il == '[' && (value < l))
77  err++;
78  if (il == ']' && !(value > l))
79  err++;
80  if (ih == '[' && !(value < h))
81  err++;
82  if (ih == ']' && (value > h))
83  err++;
84  return err == 0;
85 }
86 
87 // Destructor deletes an instance of the range class.
89  if (txt) free (txt);
90 }
91 
92 /* Returns a text representation of the range object. */
93 char * range::toString (void) {
94  char str[64];
95  sprintf (str, "%c%g,%g%c", il, l, h, ih);
96  if (txt) free (txt);
97  txt = strdup (str);
98  return txt;
99 }
100 
101 } // namespace qucs
char * toString(void)
Definition: range.cpp:93
r
Definition: parse_mdl.y:515
nr_double_t l
Definition: parse_netlist.y:47
nr_double_t lo(void)
Definition: parse_netlist.y:41
free($1)
bool outside(nr_double_t)
Definition: range.cpp:69
value
Definition: parse_vcd.y:315
bool inside(nr_double_t)
Definition: range.cpp:74
nr_double_t hi(void)
Definition: parse_netlist.y:42
nr_double_t h
Definition: parse_netlist.y:48