3
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
3
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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 |
6108
|
31 OCTAVE_API |
1860
|
32 Range |
3
|
33 { |
|
34 public: |
1860
|
35 |
1528
|
36 Range (void) |
5347
|
37 : rng_base (0), rng_limit (0), rng_inc (0), rng_nelem (0), cache (1, 0) { } |
1528
|
38 |
|
39 Range (const Range& r) |
1860
|
40 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), |
4811
|
41 rng_nelem (r.rng_nelem), cache () { } |
3
|
42 |
1528
|
43 Range (double b, double l) |
1860
|
44 : rng_base (b), rng_limit (l), rng_inc (1), |
4811
|
45 rng_nelem (nelem_internal ()), cache () { } |
1528
|
46 |
|
47 Range (double b, double l, double i) |
1860
|
48 : rng_base (b), rng_limit (l), rng_inc (i), |
4811
|
49 rng_nelem (nelem_internal ()), cache () { } |
1528
|
50 |
4811
|
51 double base (void) const { return rng_base; } |
1528
|
52 double limit (void) const { return rng_limit; } |
4811
|
53 double inc (void) const { return rng_inc; } |
5275
|
54 octave_idx_type nelem (void) const { return rng_nelem; } |
3
|
55 |
2383
|
56 bool all_elements_are_ints (void) const; |
|
57 |
645
|
58 Matrix matrix_value (void) const; |
|
59 |
3
|
60 double min (void) const; |
|
61 double max (void) const; |
|
62 |
208
|
63 void sort (void); |
|
64 |
4811
|
65 void set_base (double b) |
|
66 { |
|
67 if (rng_base != b) |
|
68 { |
|
69 rng_base = b; |
|
70 clear_cache (); |
|
71 } |
|
72 } |
|
73 |
|
74 void set_limit (double l) |
|
75 { |
|
76 if (rng_limit != l) |
|
77 { |
|
78 rng_limit = l; |
|
79 clear_cache (); |
|
80 } |
|
81 } |
|
82 |
|
83 void set_inc (double i) |
|
84 { |
|
85 if (rng_inc != i) |
|
86 { |
|
87 rng_inc = i; |
|
88 clear_cache (); |
|
89 } |
|
90 } |
1528
|
91 |
6108
|
92 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r); |
|
93 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); |
3
|
94 |
|
95 void print_range (void); |
|
96 |
|
97 private: |
1860
|
98 |
208
|
99 double rng_base; |
|
100 double rng_limit; |
|
101 double rng_inc; |
1860
|
102 |
5275
|
103 octave_idx_type rng_nelem; |
3
|
104 |
4811
|
105 mutable Matrix cache; |
|
106 |
5275
|
107 octave_idx_type nelem_internal (void) const; |
4811
|
108 |
|
109 void clear_cache (void) const { cache.resize (0, 0); } |
3
|
110 }; |
|
111 |
6108
|
112 extern OCTAVE_API Range operator - (const Range& r); |
2599
|
113 |
3
|
114 #endif |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; End: *** |
|
120 */ |