Mercurial > octave
comparison liboctave/Range.h @ 3:9a4c07481e61
[project @ 1993-08-08 01:20:23 by jwe]
Initial revision
author | jwe |
---|---|
date | Sun, 08 Aug 1993 01:21:46 +0000 |
parents | |
children | 380cb9ccc889 |
comparison
equal
deleted
inserted
replaced
2:c0190df9885d | 3:9a4c07481e61 |
---|---|
1 // Range.h -*- C++ -*- | |
2 /* | |
3 | |
4 Copyright (C) 1992, 1993 John W. Eaton | |
5 | |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with Octave; see the file COPYING. If not, write to the Free | |
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 */ | |
23 | |
24 #if !defined (_Range_h) | |
25 #define _Range_h 1 | |
26 | |
27 #ifdef __GNUG__ | |
28 #pragma interface | |
29 #endif | |
30 | |
31 #include <iostream.h> | |
32 | |
33 class Range | |
34 { | |
35 public: | |
36 Range (void); | |
37 Range (const Range& r); | |
38 Range (double b, double l); | |
39 Range (double b, double l, double i); | |
40 | |
41 double base (void) const; | |
42 double limit (void) const; | |
43 double inc (void) const; | |
44 int nelem (void) const; | |
45 | |
46 double min (void) const; | |
47 double max (void) const; | |
48 | |
49 void set_base (double b); | |
50 void set_limit (double l); | |
51 void set_inc (double i); | |
52 | |
53 friend ostream& operator << (ostream& os, const Range& r); | |
54 friend istream& operator >> (istream& is, Range& r); | |
55 | |
56 void print_range (void); | |
57 | |
58 private: | |
59 double _base; | |
60 double _limit; | |
61 double _inc; | |
62 int _nelem; | |
63 | |
64 int nelem_internal (void) const; | |
65 }; | |
66 | |
67 inline Range::Range (void) | |
68 { _base = -1; _limit = -1; _inc = -1; _nelem = -1; } | |
69 | |
70 inline Range::Range (const Range& r) | |
71 { _base = r._base; _limit = r._limit; _inc = r._inc; _nelem = r._nelem; } | |
72 | |
73 inline Range::Range (double b, double l) | |
74 { _base = b; _limit = l; _inc = 1; _nelem = nelem_internal (); } | |
75 | |
76 inline Range::Range (double b, double l, double i) | |
77 { _base = b; _limit = l; _inc = i; _nelem = nelem_internal (); } | |
78 | |
79 inline double Range::base (void) const { return _base; } | |
80 inline double Range::limit (void) const { return _limit; } | |
81 inline double Range::inc (void) const { return _inc; } | |
82 inline int Range::nelem (void) const { return _nelem; } | |
83 | |
84 inline void Range::set_base (double b) { _base = b; } | |
85 inline void Range::set_limit (double l) { _limit = l; } | |
86 inline void Range::set_inc (double i) { _inc = i; } | |
87 | |
88 // NOTE: max and min only return useful values if nelem > 0. | |
89 | |
90 inline double Range::min (void) const { return _inc > 0 ? _base : _limit; } | |
91 inline double Range::max (void) const { return _inc > 0 ? _limit : _base; } | |
92 | |
93 #endif | |
94 | |
95 /* | |
96 ;;; Local Variables: *** | |
97 ;;; mode: C++ *** | |
98 ;;; page-delimiter: "^/\\*" *** | |
99 ;;; End: *** | |
100 */ |