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