Mercurial > octave
annotate liboctave/Range.h @ 7463:2467639bd8c0
eliminate UNDEFINED sort mode
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 08 Feb 2008 16:00:16 -0500 |
parents | 1032e24f199f |
children | 36594d5bbe13 |
rev | line source |
---|---|
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> |
7458 | 28 |
4810 | 29 #include "dMatrix.h" |
7458 | 30 #include "oct-sort.h" |
3 | 31 |
1860 | 32 class |
6108 | 33 OCTAVE_API |
1860 | 34 Range |
3 | 35 { |
36 public: | |
1860 | 37 |
1528 | 38 Range (void) |
5347 | 39 : rng_base (0), rng_limit (0), rng_inc (0), rng_nelem (0), cache (1, 0) { } |
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; } |
5275 | 56 octave_idx_type 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 | |
7458 | 65 void sort_internal (bool ascending = true); |
66 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
67 | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
68 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 69 |
70 Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
71 sortmode mode = ASCENDING) const; |
208 | 72 |
4811 | 73 void set_base (double b) |
74 { | |
75 if (rng_base != b) | |
76 { | |
77 rng_base = b; | |
78 clear_cache (); | |
79 } | |
80 } | |
81 | |
82 void set_limit (double l) | |
83 { | |
84 if (rng_limit != l) | |
85 { | |
86 rng_limit = l; | |
87 clear_cache (); | |
88 } | |
89 } | |
90 | |
91 void set_inc (double i) | |
92 { | |
93 if (rng_inc != i) | |
94 { | |
95 rng_inc = i; | |
96 clear_cache (); | |
97 } | |
98 } | |
1528 | 99 |
6108 | 100 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r); |
101 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); | |
3 | 102 |
103 void print_range (void); | |
104 | |
105 private: | |
1860 | 106 |
208 | 107 double rng_base; |
108 double rng_limit; | |
109 double rng_inc; | |
1860 | 110 |
5275 | 111 octave_idx_type rng_nelem; |
3 | 112 |
4811 | 113 mutable Matrix cache; |
114 | |
5275 | 115 octave_idx_type nelem_internal (void) const; |
4811 | 116 |
117 void clear_cache (void) const { cache.resize (0, 0); } | |
3 | 118 }; |
119 | |
6108 | 120 extern OCTAVE_API Range operator - (const Range& r); |
2599 | 121 |
3 | 122 #endif |
123 | |
124 /* | |
125 ;;; Local Variables: *** | |
126 ;;; mode: C++ *** | |
127 ;;; End: *** | |
128 */ |