00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_Range_h)
00025 #define octave_Range_h 1
00026
00027 #include <iosfwd>
00028
00029 #include "dMatrix.h"
00030 #include "oct-sort.h"
00031
00032 class
00033 OCTAVE_API
00034 Range
00035 {
00036 public:
00037
00038 Range (void)
00039 : rng_base (0), rng_limit (0), rng_inc (0), rng_nelem (0), cache (1, 0) { }
00040
00041 Range (const Range& r)
00042 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc),
00043 rng_nelem (r.rng_nelem), cache (r.cache) { }
00044
00045 Range (double b, double l)
00046 : rng_base (b), rng_limit (l), rng_inc (1),
00047 rng_nelem (nelem_internal ()), cache () { }
00048
00049 Range (double b, double l, double i)
00050 : rng_base (b), rng_limit (l), rng_inc (i),
00051 rng_nelem (nelem_internal ()), cache () { }
00052
00053
00054 Range (double b, double i, octave_idx_type n);
00055
00056 double base (void) const { return rng_base; }
00057 double limit (void) const { return rng_limit; }
00058 double inc (void) const { return rng_inc; }
00059 octave_idx_type nelem (void) const { return rng_nelem; }
00060
00061 bool all_elements_are_ints (void) const;
00062
00063 Matrix matrix_value (void) const;
00064
00065 double min (void) const;
00066 double max (void) const;
00067
00068 void sort_internal (bool ascending = true);
00069 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true);
00070
00071 Matrix diag (octave_idx_type k = 0) const;
00072
00073 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
00074
00075 Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
00076 sortmode mode = ASCENDING) const;
00077
00078 sortmode is_sorted (sortmode mode = ASCENDING) const;
00079
00080 void set_base (double b)
00081 {
00082 if (rng_base != b)
00083 {
00084 rng_base = b;
00085 clear_cache ();
00086 }
00087 }
00088
00089 void set_limit (double l)
00090 {
00091 if (rng_limit != l)
00092 {
00093 rng_limit = l;
00094 clear_cache ();
00095 }
00096 }
00097
00098 void set_inc (double i)
00099 {
00100 if (rng_inc != i)
00101 {
00102 rng_inc = i;
00103 clear_cache ();
00104 }
00105 }
00106
00107 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r);
00108 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r);
00109
00110 friend OCTAVE_API Range operator - (const Range& r);
00111 friend OCTAVE_API Range operator + (double x, const Range& r);
00112 friend OCTAVE_API Range operator + (const Range& r, double x);
00113 friend OCTAVE_API Range operator - (double x, const Range& r);
00114 friend OCTAVE_API Range operator - (const Range& r, double x);
00115 friend OCTAVE_API Range operator * (double x, const Range& r);
00116 friend OCTAVE_API Range operator * (const Range& r, double x);
00117
00118 void print_range (void);
00119
00120 private:
00121
00122 double rng_base;
00123 double rng_limit;
00124 double rng_inc;
00125
00126 octave_idx_type rng_nelem;
00127
00128 mutable Matrix cache;
00129
00130 octave_idx_type nelem_internal (void) const;
00131
00132 void clear_cache (void) const { cache.resize (0, 0); }
00133
00134 };
00135
00136 extern OCTAVE_API Range operator - (const Range& r);
00137
00138 extern OCTAVE_API Range operator + (double x, const Range& r);
00139
00140 extern OCTAVE_API Range operator + (const Range& r, double x);
00141
00142 extern OCTAVE_API Range operator - (double x, const Range& r);
00143
00144 extern OCTAVE_API Range operator - (const Range& r, double x);
00145
00146 extern OCTAVE_API Range operator * (double x, const Range& r);
00147
00148 extern OCTAVE_API Range operator * (const Range& r, double x);
00149
00150 #endif
00151
00152
00153
00154
00155
00156