25 #if !defined (octave_idx_vector_h)
26 #define octave_idx_vector_h 1
39 template<
class T>
class Array;
66 template<
class T>
friend class std::auto_ptr;
93 virtual idx_base_rep *sort_uniq_clone (
bool uniq =
false) = 0;
104 virtual std::ostream& print (std::ostream& os)
const = 0;
138 { count++;
return this; }
144 std::ostream&
print (std::ostream& os)
const;
163 :
idx_base_rep (), start(_start), len(_len), step(_step) { }
166 : start(0), len(0), step(1) { }
175 {
return start + i * step; }
182 {
return len ?
std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1))))
192 {
return start == 0 && step == 1 && len == n; }
201 std::ostream&
print (std::ostream& os)
const;
246 { count++;
return this; }
251 {
return n == 1 && data == 0; }
257 std::ostream&
print (std::ostream& os)
const;
281 : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { }
284 : data (0), len (0), ext (0), aowner (0), orig_dims ()
323 std::ostream&
print (std::ostream& os)
const;
359 : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1),
360 aowner (0), orig_dims (od) { }
363 : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0),
385 { count++;
return this; }
392 {
return len == n && ext == n; }
396 std::ostream&
print (std::ostream& os)
const;
454 if (--rep->count == 0)
532 if (--rep->count == 0)
540 if (--rep->count == 0)
552 {
return rep->length (n); }
555 {
return rep->extent (n); }
558 {
return rep->xelem (n); }
561 {
return rep->checkelem (n); }
565 #if defined (BOUNDS_CHECKING)
566 return rep->checkelem (n);
568 return rep->xelem (n);
573 {
return ! rep->err; }
576 {
return rep->idx_class () == class_colon; }
579 {
return rep->idx_class () == class_scalar; }
582 {
return rep->idx_class () == class_range; }
585 {
return rep->is_colon_equiv (n); }
588 {
return idx_vector (rep->sort_uniq_clone (uniq)); }
596 {
return orig_dimensions () (0); }
599 {
return orig_dimensions () (1); }
602 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
606 std::ostream&
print (std::ostream& os)
const {
return rep->print (os); }
609 {
return a.
print (os); }
625 switch (rep->idx_class ())
628 std::copy (src, src + len, dest);
636 const T *ssrc = src + start;
638 std::copy (ssrc, ssrc + len, dest);
640 std::reverse_copy (ssrc - len + 1, ssrc + 1, dest);
642 std::fill_n (dest, len, *ssrc);
663 dest[i] = src[data[i]];
673 if (data[i]) *dest++ = src[i];
699 switch (rep->idx_class ())
702 std::copy (src, src + len, dest);
710 T *sdest = dest + start;
712 std::copy (src, src + len, sdest);
714 std::reverse_copy (src, src + len, sdest - len + 1);
735 dest[data[i]] = src[i];
745 if (data[i]) dest[i] = *src++;
771 switch (rep->idx_class ())
774 std::fill (dest, dest + len, val);
782 T *sdest = dest + start;
784 std::fill (sdest, sdest + len, val);
786 std::fill (sdest - len + 1, sdest + 1, val);
817 if (data[i]) dest[i] = val;
835 template <
class Functor>
841 switch (rep->idx_class ())
854 for (i = start, j = start + len; i < j; i++) body (i);
856 for (i = start, j = start - len; i > j; i--) body (i);
858 for (i = 0, j = start; i < len; i++, j += step) body (j);
883 if (data[i]) body (i);
903 template <
class Functor>
909 switch (rep->idx_class ())
914 for (i = 0; i < len && body (i); i++) ;
926 for (i = start, j = start + len; i < j && body (i); i++) ;
928 for (i = start, j = start - len; i > j && body (i); i--) ;
930 for (i = 0, j = start; i < len && body (j); i++, j += step) ;
938 ret = body (r->
get_data ()) ? 1 : 0;
947 for (i = 0; i < len && body (data[i]); i++) ;
1014 void unconvert (idx_class_type& iclass,
1030 {
return (*
this) (n); }
1033 {
return is_colon_equiv (n); }
1039 { *
this = sorted (uniq); }
octave_idx_type elem(octave_idx_type n) const
virtual Array< octave_idx_type > as_array(void)
idx_class_type idx_class(void) const
virtual ~idx_base_rep(void)
octave_idx_type length(octave_idx_type n) const
idx_base_rep * sort_uniq_clone(bool=false)
bool is_colon_equiv(octave_idx_type n, int) const
octave_idx_type extent(octave_idx_type n) const
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type extent(octave_idx_type n) const
idx_vector(const Array< octave_idx_type > &inda)
idx_class_type idx_class(void) const
static const idx_vector colon
octave_idx_type assign(const T *src, octave_idx_type n, T *dest) const
int orig_empty(void) const
octave_refcount< int > count
idx_vector(const Range &r)
octave_idx_type max(void) const
bool is_vector(const dim_vector &dim)
dim_vector orig_dimensions(void) const
octave_idx_type xelem(octave_idx_type n) const
octave_idx_type get_step(void) const
octave_idx_type fill(const T &val, octave_idx_type n, T *dest) const
octave_idx_type get_start(void) const
idx_class_type idx_class(void) const
bool is_colon_equiv(octave_idx_type n) const
octave_idx_type checkelem(octave_idx_type n) const
std::ostream & print(std::ostream &os) const
octave_idx_type length(octave_idx_type) const
idx_vector(const Array< octave_int< T > > &nda)
dim_vector orig_dimensions(void) const
octave_idx_type xelem(octave_idx_type) const
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type length(octave_idx_type) const
virtual bool is_colon_equiv(octave_idx_type) const
void loop(octave_idx_type n, Functor body) const
dim_vector orig_dimensions(void) const
static idx_vector_rep * nil_rep(void)
octave_idx_type index(const T *src, octave_idx_type n, T *dest) const
octave_idx_type length(octave_idx_type) const
dim_vector orig_dimensions(void) const
octave_idx_type length(octave_idx_type) const
idx_range_rep(octave_idx_type _start, octave_idx_type _len, octave_idx_type _step, direct)
virtual idx_class_type idx_class(void) const
octave_idx_type xelem(octave_idx_type i) const
dim_vector freeze(Array< idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
idx_vector_rep(octave_idx_type *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
idx_vector(octave_idx_type i)
octave_idx_type extent(octave_idx_type n) const
virtual octave_idx_type xelem(octave_idx_type i) const =0
idx_mask_rep(bool *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
void sort(bool uniq=false)
octave_idx_type orig_rows(void) const
virtual octave_idx_type checkelem(octave_idx_type i) const =0
idx_base_rep & operator=(const idx_base_rep &)
virtual dim_vector orig_dimensions(void) const
octave_idx_type bloop(octave_idx_type n, Functor body) const
bool is_colon_equiv(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
idx_vector(const Array< float > &nda)
Handles the reference counting for all the derived classes.
octave_idx_type xelem(octave_idx_type i) const
charNDArray max(char d, const charNDArray &m)
idx_class_type idx_class(void) const
octave_idx_type extent(octave_idx_type n) const
bool is_range(void) const
idx_vector(const Array< double > &nda)
idx_class_type idx_class(void) const
idx_vector(const Array< octave_idx_type > &inda, octave_idx_type ext)
idx_base_rep * sort_uniq_clone(bool=false)
idx_scalar_rep(octave_idx_type i, direct)
idx_vector(idx_base_rep *r)
idx_vector sorted(Array< octave_idx_type > &sidx) const
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
bool is_scalar(void) const
idx_vector(octave_idx_type start, octave_idx_type limit, octave_idx_type step=1)
const octave_idx_type * data
idx_vector(octave_int< T > x)
virtual idx_base_rep * sort_idx(Array< octave_idx_type > &)=0
idx_vector(const Sparse< bool > &nda)
octave_idx_type get_data(void) const
void unconvert(idx_class_type &iclass, double &scalar, Range &range, Array< double > &array, Array< bool > &mask) const
idx_class_type idx_class(void) const
Array< octave_idx_type > * aowner
dim_vector orig_dimensions(void) const
virtual idx_base_rep * sort_uniq_clone(bool uniq=false)=0
octave_idx_type orig_columns(void) const
bool is_colon_equiv(octave_idx_type) const
idx_base_rep * sort_uniq_clone(bool=false)
const octave_idx_type * get_data(void) const
const bool * get_data(void) const
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
virtual std::ostream & print(std::ostream &os) const =0
idx_vector sorted(bool uniq=false) const
bool is_colon_equiv(octave_idx_type n) const
bool is_colon(void) const
F77_RET_T const double * x
static bool scalar(const dim_vector &dims)
idx_vector(const idx_vector &a)
octave_idx_type extent(octave_idx_type n) const
octave_idx_type extent(octave_idx_type n) const
static idx_vector_rep * err_rep(void)