3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
3
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
382
|
23 #if !defined (octave_Range_h) |
|
24 #define octave_Range_h 1 |
|
25 |
3503
|
26 #include <iostream> |
4810
|
27 #include "dMatrix.h" |
3
|
28 |
1860
|
29 class |
|
30 Range |
3
|
31 { |
|
32 public: |
1860
|
33 |
1528
|
34 Range (void) |
4811
|
35 : rng_base (-1), rng_limit (-1), rng_inc (-1), rng_nelem (-1), cache () { } |
1528
|
36 |
|
37 Range (const Range& r) |
1860
|
38 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), |
4811
|
39 rng_nelem (r.rng_nelem), cache () { } |
3
|
40 |
1528
|
41 Range (double b, double l) |
1860
|
42 : rng_base (b), rng_limit (l), rng_inc (1), |
4811
|
43 rng_nelem (nelem_internal ()), cache () { } |
1528
|
44 |
|
45 Range (double b, double l, double i) |
1860
|
46 : rng_base (b), rng_limit (l), rng_inc (i), |
4811
|
47 rng_nelem (nelem_internal ()), cache () { } |
1528
|
48 |
4811
|
49 double base (void) const { return rng_base; } |
1528
|
50 double limit (void) const { return rng_limit; } |
4811
|
51 double inc (void) const { return rng_inc; } |
1528
|
52 int nelem (void) const { return rng_nelem; } |
3
|
53 |
2383
|
54 bool all_elements_are_ints (void) const; |
|
55 |
645
|
56 Matrix matrix_value (void) const; |
|
57 |
3
|
58 double min (void) const; |
|
59 double max (void) const; |
|
60 |
208
|
61 void sort (void); |
|
62 |
4811
|
63 void set_base (double b) |
|
64 { |
|
65 if (rng_base != b) |
|
66 { |
|
67 rng_base = b; |
|
68 clear_cache (); |
|
69 } |
|
70 } |
|
71 |
|
72 void set_limit (double l) |
|
73 { |
|
74 if (rng_limit != l) |
|
75 { |
|
76 rng_limit = l; |
|
77 clear_cache (); |
|
78 } |
|
79 } |
|
80 |
|
81 void set_inc (double i) |
|
82 { |
|
83 if (rng_inc != i) |
|
84 { |
|
85 rng_inc = i; |
|
86 clear_cache (); |
|
87 } |
|
88 } |
1528
|
89 |
3504
|
90 friend std::ostream& operator << (std::ostream& os, const Range& r); |
|
91 friend std::istream& operator >> (std::istream& is, Range& r); |
3
|
92 |
|
93 void print_range (void); |
|
94 |
|
95 private: |
1860
|
96 |
208
|
97 double rng_base; |
|
98 double rng_limit; |
|
99 double rng_inc; |
1860
|
100 |
208
|
101 int rng_nelem; |
3
|
102 |
4811
|
103 mutable Matrix cache; |
|
104 |
3
|
105 int nelem_internal (void) const; |
4811
|
106 |
|
107 void clear_cache (void) const { cache.resize (0, 0); } |
3
|
108 }; |
|
109 |
2599
|
110 extern Range operator - (const Range& r); |
|
111 |
3
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |