25 #if !defined (octave_idx_vector_h)
26 #define octave_idx_vector_h 1
40 template<
class T>
class Array;
41 template<
class T>
class Sparse;
67 template<
class T>
friend class std::auto_ptr;
94 virtual idx_base_rep *sort_uniq_clone (
bool uniq =
false) = 0;
105 virtual std::ostream& print (std::ostream& os)
const = 0;
139 { count++;
return this; }
145 std::ostream&
print (std::ostream& os)
const;
165 :
idx_base_rep (), start(_start), len(_len), step(_step) { }
168 : start(0), len(0), step(1) { }
177 {
return start + i * step; }
184 {
return len ?
std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1))))
194 {
return start == 0 && step == 1 && len == n; }
203 std::ostream&
print (std::ostream& os)
const;
249 { count++;
return this; }
254 {
return n == 1 && data == 0; }
260 std::ostream&
print (std::ostream& os)
const;
285 : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { }
288 : data (0), len (0), ext (0), aowner (0), orig_dims ()
327 std::ostream&
print (std::ostream& os)
const;
364 : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1),
365 aowner (0), orig_dims (od) { }
368 : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0),
390 { count++;
return this; }
397 {
return len == n && ext == n; }
401 std::ostream&
print (std::ostream& os)
const;
460 if (--rep->count == 0)
538 if (--rep->count == 0)
546 if (--rep->count == 0)
558 {
return rep->length (n); }
561 {
return rep->extent (n); }
564 {
return rep->xelem (n); }
567 {
return rep->checkelem (n); }
571 #if defined (BOUNDS_CHECKING)
572 return rep->checkelem (n);
574 return rep->xelem (n);
579 {
return ! rep->err; }
581 bool is_colon (
void)
const
582 {
return rep->idx_class () == class_colon; }
585 {
return rep->idx_class () == class_scalar; }
587 bool is_range (
void)
const
588 {
return rep->idx_class () == class_range; }
591 {
return rep->is_colon_equiv (n); }
594 {
return idx_vector (rep->sort_uniq_clone (uniq)); }
602 {
return orig_dimensions () (0); }
605 {
return orig_dimensions () (1); }
607 int orig_empty (
void)
const
608 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
612 std::ostream&
print (std::ostream& os)
const {
return rep->print (os); }
615 {
return a.
print (os); }
631 switch (rep->idx_class ())
641 const T *ssrc = src + start;
645 std::reverse_copy (ssrc - len + 1, ssrc + 1, dest);
647 std::fill_n (dest, len, *ssrc);
668 dest[i] = src[data[i]];
678 if (data[i]) *dest++ = src[i];
704 switch (rep->idx_class ())
714 T *sdest = dest + start;
718 std::reverse_copy (src, src + len, sdest - len + 1);
739 dest[data[i]] = src[i];
749 if (data[i]) dest[i] = *src++;
775 switch (rep->idx_class ())
778 std::fill (dest, dest + len, val);
785 T *sdest = dest + start;
787 std::fill (sdest, sdest + len, val);
789 std::fill (sdest - len + 1, sdest + 1, val);
820 if (data[i]) dest[i] = val;
838 template <
class Functor>
844 switch (rep->idx_class ())
856 for (i = start, j = start + len; i < j; i++) body (i);
858 for (i = start, j = start - len; i > j; i--) body (i);
860 for (i = 0, j = start; i < len; i++, j += step) body (j);
885 if (data[i]) body (i);
905 template <
class Functor>
911 switch (rep->idx_class ())
916 for (i = 0; i < len && body (i); i++) ;
927 for (i = start, j = start + len; i < j && body (i); i++) ;
929 for (i = start, j = start - len; i > j && body (i); i--) ;
931 for (i = 0, j = start; i < len && body (j); i++, j += step) ;
939 ret = body (r->
get_data ()) ? 1 : 0;
948 for (i = 0; i < len && body (data[i]); i++) ;
1014 void unconvert (idx_class_type& iclass,
1030 {
return (*
this) (n); }
1038 void sort (
bool uniq =
false)
1039 { *
this = sorted (uniq); }