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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3
|
21 |
|
22 */ |
|
23 |
382
|
24 #if !defined (octave_Range_h) |
|
25 #define octave_Range_h 1 |
|
26 |
3503
|
27 #include <iostream> |
4810
|
28 #include "dMatrix.h" |
3
|
29 |
1860
|
30 class |
|
31 Range |
3
|
32 { |
|
33 public: |
1860
|
34 |
1528
|
35 Range (void) |
4811
|
36 : rng_base (-1), rng_limit (-1), rng_inc (-1), rng_nelem (-1), cache () { } |
1528
|
37 |
|
38 Range (const Range& r) |
1860
|
39 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), |
4811
|
40 rng_nelem (r.rng_nelem), cache () { } |
3
|
41 |
1528
|
42 Range (double b, double l) |
1860
|
43 : rng_base (b), rng_limit (l), rng_inc (1), |
4811
|
44 rng_nelem (nelem_internal ()), cache () { } |
1528
|
45 |
|
46 Range (double b, double l, double i) |
1860
|
47 : rng_base (b), rng_limit (l), rng_inc (i), |
4811
|
48 rng_nelem (nelem_internal ()), cache () { } |
1528
|
49 |
4811
|
50 double base (void) const { return rng_base; } |
1528
|
51 double limit (void) const { return rng_limit; } |
4811
|
52 double inc (void) const { return rng_inc; } |
5275
|
53 octave_idx_type nelem (void) const { return rng_nelem; } |
3
|
54 |
2383
|
55 bool all_elements_are_ints (void) const; |
|
56 |
645
|
57 Matrix matrix_value (void) const; |
|
58 |
3
|
59 double min (void) const; |
|
60 double max (void) const; |
|
61 |
208
|
62 void sort (void); |
|
63 |
4811
|
64 void set_base (double b) |
|
65 { |
|
66 if (rng_base != b) |
|
67 { |
|
68 rng_base = b; |
|
69 clear_cache (); |
|
70 } |
|
71 } |
|
72 |
|
73 void set_limit (double l) |
|
74 { |
|
75 if (rng_limit != l) |
|
76 { |
|
77 rng_limit = l; |
|
78 clear_cache (); |
|
79 } |
|
80 } |
|
81 |
|
82 void set_inc (double i) |
|
83 { |
|
84 if (rng_inc != i) |
|
85 { |
|
86 rng_inc = i; |
|
87 clear_cache (); |
|
88 } |
|
89 } |
1528
|
90 |
3504
|
91 friend std::ostream& operator << (std::ostream& os, const Range& r); |
|
92 friend std::istream& operator >> (std::istream& is, Range& r); |
3
|
93 |
|
94 void print_range (void); |
|
95 |
|
96 private: |
1860
|
97 |
208
|
98 double rng_base; |
|
99 double rng_limit; |
|
100 double rng_inc; |
1860
|
101 |
5275
|
102 octave_idx_type rng_nelem; |
3
|
103 |
4811
|
104 mutable Matrix cache; |
|
105 |
5275
|
106 octave_idx_type nelem_internal (void) const; |
4811
|
107 |
|
108 void clear_cache (void) const { cache.resize (0, 0); } |
3
|
109 }; |
|
110 |
2599
|
111 extern Range operator - (const Range& r); |
|
112 |
3
|
113 #endif |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |