My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
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: range.cpp 1825 2011-03-11 20:42:14Z ela $
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
// Constructor creates an instance of the range class.
36
range::range
() {
37
il = ih =
'.'
;
38
l = h = 0.0;
39
txt = NULL;
40
}
41
42
// Constructor creates an fully qualified instance of the range class.
43
range::range
(
char
ilo, nr_double_t lo, nr_double_t hi,
char
ihi) {
44
il = ilo;
45
ih = ihi;
46
if
(lo > hi) {
47
h =
lo
;
48
l =
hi
;
49
}
else
{
50
l =
lo
;
51
h =
hi
;
52
}
53
txt = NULL;
54
}
55
56
/* This copy constructor creates a instance of the range class based
57
on the given range. */
58
range::range
(
const
range
& r) {
59
txt = r.txt ? strdup (r.txt) : NULL;
60
il = r.il;
61
ih = r.ih;
62
l = r.l;
63
h = r.h;
64
}
65
66
/* Checks whether the given value is outside the range. */
67
bool
range::outside
(nr_double_t value) {
68
return
!
inside
(value);
69
}
70
71
/* Checks whether the given value is inside the range. */
72
bool
range::inside
(nr_double_t value) {
73
int
err = 0;
74
if
(il ==
'['
&& (value < l))
75
err++;
76
if
(il ==
']'
&& !(value > l))
77
err++;
78
if
(ih ==
'['
&& !(value < h))
79
err++;
80
if
(ih ==
']'
&& (value > h))
81
err++;
82
return
err == 0;
83
}
84
85
// Destructor deletes an instance of the range class.
86
range::~range
() {
87
if
(txt) free (txt);
88
}
89
90
/* Returns a text representation of the range object. */
91
char
*
range::toString
(
void
) {
92
char
str[64];
93
sprintf (str,
"%c%g,%g%c"
, il, l, h, ih);
94
if
(txt) free (txt);
95
txt = strdup (str);
96
return
txt;
97
}
Generated on Tue Dec 25 2012 14:30:35 for My Project by
1.8.2