FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
vector/Iterator.hpp
1#ifndef __vector_Iterator_HPP
2#define __vector_Iterator_HPP "Created 21.05.2006 12:12:12 by werner"
3
4#include "fvectorAPI.h"
5#include <eagle/FixedArray.hpp>
6#include "VVector.hpp"
7#include "Index.hpp"
8#include <typeinfo>
9#include "HyperslabParameters.hpp"
10
11#include <memcore/Verbose.hpp>
12
13#if defined(__GNUC__) && defined(_GLIBCXX_USE_NOEXCEPT)
14#define USE_NOEXCEPT _GLIBCXX_USE_NOEXCEPT
15#else
16#define USE_NOEXCEPT throw()
17#endif
18
19#define COOL_ITERATOR
20
21
22
23
24
25namespace Fiber
26{
27 using std::type_info;
29
30typedef Eagle::Mult Mult;
31typedef Eagle::Div Div;
32typedef Eagle::Add Add;
33typedef Eagle::Sub Sub;
34
35template <int Configuration> struct RangeFailureAction;
36
37template <>
39{
40static void check(const char*funcname, index_t i, index_t max_i)
41 {}
42
43 const char* what() const USE_NOEXCEPT override
44 {
45 return "Range check error";
46 }
47};
48
49template <>
51{
52static void check(const char*funcname, index_t i, index_t max_i)
53 {
54// std::cout << "HERE!" << std::endl;
55
56 if (i>=max_i)
57 {
58 Assertion( i<max_i, "Range check Failure: " + std::to_string(i) + "/" + std::to_string(max_i) );
59 }
60 }
61
62 const char* what() const USE_NOEXCEPT override
63 {
64 return "Range check error";
65 }
66};
67
69{
70 RangeException(const char*func, index_t i, index_t max_i)
71 {}
72
73 const char* what() const USE_NOEXCEPT override
74 {
75 return "Range check error";
76 }
77};
78
79template <>
81{
82static void check(const char*funcname, index_t i, index_t max_i)
83 {
84 if (i>=max_i)
85 {
86 throw RangeException(funcname, i, max_i);
87 }
88 }
89
90 const char* what() const USE_NOEXCEPT override
91 {
92 return "Range check error";
93 }
94};
95
96template <>
98{
99static void check(const char*funcname, index_t i, index_t max_i)
100 {
101 if (i>=max_i)
102 {
103 std::cerr << "RangeFailueAction<3>: ERROR " << funcname << ":" << i << " of " << max_i << " accessed!" << std::endl;
104 throw RangeException(funcname, i, max_i);
105 }
106 }
107
108 const char*what() const USE_NOEXCEPT override
109 {
110 return "Range check error";
111 }
112};
113
114
115#ifndef FIBER_VECTOR_RANGE_FAILURE_ACTION
116#ifdef NDEBUG
117#define FIBER_VECTOR_RANGE_FAILURE_ACTION 0
118#else
119#define FIBER_VECTOR_RANGE_FAILURE_ACTION 1
120#endif
121#endif
122
124
125template <class T>
126 class Iterator;
127
128template <int Components, class T>
129 class Iterator<FixedArray<T, Components> >;
130
131
147template <class T>
149{
150private:
152 T*data;
153
154protected:
156 using HyperslabParameters::stride;
157 using HyperslabParameters::offset;
158 using HyperslabParameters::shift;
159 using HyperslabParameters::cropped;
160
161 void incPtr(index_t what)
162 {
163 data += what;
164 }
165
166public:
168 typedef typename info_t::element_t element_info_t;
169
174 : HyperslabParameters(Length, Stride, Offset)
175 , data(Data)
176 {
177#ifdef FIBER_ITERATOR_NULLPTR_ASSERTION
178 Assert(Data);
179#elif defined(FIBER_ITERATOR_NULLPTR_WARNING)
180 if (!data)
181 {
182 Verbose(0) << "ElementIterator constructed with NULL pointer, provided length is " << Length;
183 }
184#endif
185 }
186
190 , data (It.data)
191 {
192#ifdef FIBER_ITERATOR_NULLPTR_ASSERTION
193 Assert(It.data);
194#elif defined(FIBER_ITERATOR_NULLPTR_WARNING)
195 if (!data)
196 {
197 Verbose(0) << "ElementIterator constructed with NULL pointer, provided length is " << Length;
198 }
199#endif
200 }
201
205 , data (newData)
206 {
207#ifdef FIBER_ITERATOR_NULLPTR_ASSERTION
208 Assert( newData );
209#elif defined(FIBER_ITERATOR_NULLPTR_WARNING)
210 if (!data)
211 {
212 Verbose(0) << "ElementIterator constructed with NULL pointer, provided length is " << Length;
213 }
214#endif
215 }
216
219 : HyperslabParameters(i, It)
220 , data (It.data)
221 {
222#ifdef FIBER_ITERATOR_NULLPTR_ASSERTION
223 Assert(It.data);
224#elif defined(FIBER_ITERATOR_NULLPTR_WARNING)
225 if (!data)
226 {
227 Verbose(0) << "ElementIterator constructed with NULL pointer, provided length is " << Length;
228 }
229#endif
230 }
231
234 {
235 data = newData;
237
238#ifdef FIBER_ITERATOR_NULLPTR_ASSERTION
239 Assert( data );
240#elif defined(FIBER_ITERATOR_NULLPTR_WARNING)
241 if (!data)
242 {
243 Verbose(0) << "ElementIterator setNew Data with NULL pointer, provided length is " << Length;
244 }
245#endif
246 if( stride == 1 )
247 {
248 offset = length;
249 //incPtr = length;
250 //shift = It.getShift();
251 //cropped= It.getCropped();
252 }
253 else
254 {
255 offset = 0;
256 //stride = sizeof(Eagle::FixedArray<T, Components>)/sizeof(T);
257 //incPtr = Eagle::FixedArray<T, Components>;
258 //this->shift = It.getShift();
259 //this->length = It.getLength();
260 //this->cropped= It.getCropped();
261 }
262 }
263
266 T*ptr(int c=0) const
267 {
268 if (!data)
269 return 0;
270
271 return data+c*offset;
272 }
273
285 T&getElement(index_t i, int c) const
286 {
287 index_t index = getIndex(i,c);
288
289 // printf("i: %ld, c: %d, index: %ld, getLength: %ld, count: %ld ", i, c, index, getLength(), count() );
290 // printf("stride: %ld, offset: %ld, shift: %ld, cropped: %ld\n", stride, offset, shift, cropped);
291
292 DefaultRangeFailureAction::check(__FUNCTION__, index, getLength() );
293 DefaultRangeFailureAction::check(__FUNCTION__, i , count() );
294// DefaultRangeFailureAction::check(__PRETTY_FUNCTION__, index, size() );
295
296 return data[index];
297 }
298
303 operator bool() const
304 {
305 return data!=0;
306 }
307
308 // MSVC GCC SGI C++
309#if defined(_IOSTREAM_) || defined(_GLIBCXX_OSTREAM) || defined(_CPP_IOSTREAM) || defined(__SGI_STL_IOSTREAM) || defined(__clang__)
310#define ITERATOR_OSTREAM
311 friend std::ostream&operator<<(std::ostream&os, const ElementIterator&It)
312 {
313 os << '(' << It.shift << " + i)*" << It.stride << " + c*" << It.offset
314 << " ; " << It.length << " elements of type "
315 << typeid (T).name() << ", " << It.count() << " iterable.\n"
316 ;
317 return os;
318 }
319#endif
320
321};
322
323
327template <class T>
329{
330protected:
332 using ElementIterator<T>::stride;
333 using ElementIterator<T>::offset;
334 using ElementIterator<T>::shift;
335 using ElementIterator<T>::cropped;
336
337public:
339 using ElementIterator<T>::count;
340 using ElementIterator<T>::ptr;
341 using ElementIterator<T>::getStride;
342 using ElementIterator<T>::getOffset;
343// using ElementIterator<T>::operator();
345
346 IteratorBase(index_t Length, T*d, index_t Stride, index_t Offset)
347 : ElementIterator<T>(Length, d, Stride, Offset)
348 {}
349
352 {}
353
356 : ElementIterator<T>(IB,d)
357 {}
358
360 : ElementIterator<T>(ishift, P, Add() )
361 {}
362};
363
364
365template <class T>
366 class Iterator;
367
368template <int C, class T>
369 class Iterator<FixedArray<T, C> >;
370
371template <class T, int C>
373 {
374 public: typedef FixedArray<T, C> array_t;
375 };
376
377template <class T>
379 {
380 public: typedef T array_t;
381 };
382
383
384template <class Type>
390
391
392
393template <class T>
395{
396 index_t myIndex;
397 const Iterator<T>&myContainer;
398
400 : myIndex(theIndex)
401 , myContainer(theContainer)
402 {}
403
404 bool operator!=(const const_ranged_for_iterator&RFI) const
405 {
406 return myIndex !=RFI.myIndex;
407 }
408
409 void operator++()
410 {
411 myIndex++;
412 }
413
414 const T&operator*() const
415 {
416 return myContainer[ myIndex ];
417 }
418};
419
420
421template <class T>
423{
424 index_t myIndex;
425 Iterator<T>&myContainer;
426
428 : myIndex(theIndex)
429 , myContainer(theContainer)
430 {}
431
432 bool operator!=(const ranged_for_iterator&RFI) const
433 {
434 return myIndex !=RFI.myIndex;
435 }
436
437 void operator++()
438 {
439 myIndex++;
440 }
441
442//#ifndef NON_INDEXABLE_ITERATOR
443 T*operator->() const
444 {
445 return &myContainer[ myIndex ];
446 }
447
448 operator T&() const
449 {
450 return myContainer[ myIndex ];
451 }
452
453 T& operator=(const T&value) const
454 {
455 return myContainer[ myIndex ] = value;
456 }
457
458#if 0
459 struct proxy
460 {
461 T&t;
462 index_t myIndex;
463
464 operator T&() const { return t; }
465 T&operator*() const { return t; }
466
467 T*operator->() const
468 {
469 return &t;
470 }
471
472 T& operator=(const T&value) const
473 {
474 return t = value;
475 }
476
477 index_t getIndex() const
478 {
479 return myIndex;
480 }
481 };
482
483 proxy operator*()
484 {
485 return { myContainer[ myIndex ], myIndex };
486 }
487
488#elif 1
489 // allows to call the getIndex() function on iterators
490 const ranged_for_iterator&operator*() const
491 {
492 return *this;
493 }
494#else
495 T&operator*() const
496 {
497 return myContainer[ myIndex ];
498 }
499#endif
500
501 index_t getIndex() const
502 {
503 return myIndex;
504 }
505};
506
507
508
509
523template <class T>
524class Iterator : public IteratorBase<T>
525{
526protected:
527 using IteratorBase<T>::length;
528 using IteratorBase<T>::stride;
529 using IteratorBase<T>::offset;
530 using IteratorBase<T>::shift;
531 using IteratorBase<T>::cropped;
532
533public:
534 typedef IteratorBase<T> Base_t;
535
537 using IteratorBase<T>::count;
538 using IteratorBase<T>::ptr;
539 using IteratorBase<T>::getStride;
540 using IteratorBase<T>::getOffset;
542// using IteratorBase<T>::operator();
543
544 typedef T value_t;
545
547 typedef typename FI::element_t component_t;
549
554
555#if 0 // better not allow this constructor, should force using first version
557 Iterator(T*Ptr, index_t howmany)
559 {}
560#endif
561
564 : IteratorBase<T>(P, Ptr)
565 {}
566
569 : IteratorBase<T>(P)
570 {}
571
573 Iterator(const Iterator&P, int)
574 : IteratorBase<T>(P)
575 {}
576
580 template <int Components>
582 : IteratorBase<T>(howmany*Components, // that many doubles exist
583 Ptr?Ptr->ptr(component):0,
584 sizeof(FixedArray<T, Components>)/sizeof(T), // stride
585 0)
586 {
587 assert(component<Components);
588 }
589
590 template <int Components>
591 Iterator(const Iterator<FixedArray<T, Components> >&It, int component)
592 : IteratorBase<T>(It.count()*Components, // that many doubles exist
593 It?It.ptr():0,
594 sizeof(Eagle::FixedArray<T, Components>)/sizeof(T), // stride
595 0)
596 {
597 assert(component<Components);
598 if (It.isSeparatedCompound() )
599 {
601 // puts("------------------------------------------------------Created a XXYYZZ");fflush(stdout);
602 index_t nElements = It.getLength() / Components;
603 this->stride = 1;
604 this->offset = nElements;
605 this->length = nElements;
606 this->incPtr( nElements );
607 this->shift = It.getShift();
608 this->cropped= It.getCropped();
609 }
610 else
611 {
613 // puts("------------------------------------------------------Created a XYZXYZ");fflush(stdout);
614 this->incPtr( component );
615 this->stride = sizeof(Eagle::FixedArray<T, Components>)/sizeof(T);
616 this->offset = 0;
617 this->shift = It.getShift();
618 this->length = It.getLength();
619 this->cropped= It.getCropped();
620 }
621 }
622
623
630 template <int Components>
632 : IteratorBase<T>(Length*Components,
633 Ptr?Ptr->ptr(component):0,
634 sizeof(Eagle::VVector<Components, T>)/sizeof(T), // stride (incl. eventual alignment!)
635 0) // offset
636 {
637 assert(component<Components);
638 }
639
642 : IteratorBase<T>(ishift, P, Add() )
643 {
644// printf("Addition pointer constructor: old count %d, offset %d, new count %d\n",
645// P.count(), Offset, count() );
646 }
647
650
653
654 friend Iterator operator+(const Iterator&P, uint32_t i)
655 {
656 return Iterator(i, P, Add() );
657 }
658
659 friend Iterator operator+(uint32_t i, const Iterator&P)
660 {
661 return Iterator(i, P, Add() );
662 }
663
664 friend Iterator operator+(const Iterator&P, uint64_t i)
665 {
666 return Iterator(i, P, Add() );
667 }
668
669 friend Iterator operator+(uint64_t i, const Iterator&P)
670 {
671 return Iterator(i, P, Add() );
672 }
673
674
675
676 friend Iterator operator+(const Iterator&P, int32_t i)
677 {
678 return Iterator(i, P, Add() );
679 }
680
681 friend Iterator operator+(int32_t i, const Iterator&P)
682 {
683 return Iterator(i, P, Add() );
684 }
685
686 friend Iterator operator+(const Iterator&P, int64_t i)
687 {
688 return Iterator(i, P, Add() );
689 }
690
691 friend Iterator operator+(int64_t i, const Iterator&P)
692 {
693 return Iterator(i, P, Add() );
694 }
695
696#if 0
697 friend Iterator operator+(const Iterator&P, long long i)
698 {
699 return Iterator(i, P, Add() );
700 }
701
702 friend Iterator operator+(long long i, const Iterator&P)
703 {
704 return Iterator(i, P, Add() );
705 }
706#endif
707
709 typedef T& reference_t;
710
713 {
714 return getElement(i,0);
715 }
716
718 const T&getValue(index_t i) const
719 {
720 return getElement(i,0);
721 }
722
724 void set(const T&Value)
725 {
726 for(index_t i=0; i<count(); i++)
727 {
728 getElement(i,0) = Value;
729 }
730 }
731
732 const_ranged_for_iterator<T> begin() const
733 {
734 return const_ranged_for_iterator<T>(0, *this);
735 }
736
737 const_ranged_for_iterator<T> end() const
738 {
739 return const_ranged_for_iterator<T>(count(), *this);
740 }
741
742 ranged_for_iterator<T> begin()
743 {
744 return ranged_for_iterator<T>(0, *this);
745 }
746
747 ranged_for_iterator<T> end()
748 {
749 return ranged_for_iterator<T>(count(), *this);
750 }
751
752 template <class S>
753 T&operator[](const ranged_for_iterator<S>&I)
754 {
755 return (*this)[I.myIndex];
756 }
757
758 template <class S>
759 const T&operator[](const ranged_for_iterator<S>&I) const
760 {
761 return (*this)[I.myIndex];
762 }
763
764 template <class S>
765 T&operator[](const const_ranged_for_iterator<S>&I)
766 {
767 return (*this)[I.myIndex];
768 }
769
770 template <class S>
771 const T&operator[](const const_ranged_for_iterator<S>&I) const
772 {
773 return (*this)[I.myIndex];
774 }
775};
776
777
778#if 0
779template <class T>
780 class constViewPtr<const T> : public ViewPtrBase<const T, 1>
781{
782// const T*data;
783// index_t stride, offset;
784
785public:
786 using ViewPtrBase<T, 1>::data;
787 using ViewPtrBase<T, 1>::stride;
788 using ViewPtrBase<T, 1>::offset;
789
790 typedef T value_t;
791
793 ViewPtr(const T*ptr)
794 : ViewPtrBase<const T, 1>(ptr, 1, 0)
795 {}
796
798 ViewPtr(const ViewPtr&P)
799 : ViewPtrBase<const T, 1>(P.data, P.stride, P.offset)
800 {}
801
805 template <int Components>
806 ViewPtr(const FixedArray<Components, T>*ptr, int component)
807 : ViewPtrBase<const T, 1>(ptr->ptr(0),
808 sizeof(FixedArray<Components, T>)/sizeof(T) ,
809 component)
810 {
811 assert(component<Components);
812 }
813
814
818 template <int Components>
819 ViewPtr(const VVector<Components, T>*ptr, int component)
820 : ViewPtrBase<const T,1>(ptr->ptr(0),
821 stride(sizeof(VVector<Components, T>)/sizeof(T) ),
822 component)
823 {}
824
825
829 ViewPtr(const ViewPtr&P, index_t ElementShift)
830 : ViewPtrBase<const T,1>(P.data + P.stride*ElementShift, P.stride, P.offset)
831//.. : data(P.data + P.stride*ElementShift), stride(P.stride), offset(P.offset)
832 {}
833
839 void setOffset(int o)
840 {
841 offset = o;
842 }
843
844 const T&operator[](index_t i) const
845 {
846 return data[i*stride + offset];
847 }
848};
849#endif
850
851
864template <class Iterator>
866 {
867 typedef typename Iterator::array_t array_t;
868 enum { Components = Iterator::Components };
869 typedef typename Iterator::element_value_t element_value_t;
870
871 const Iterator&owner;
872 index_t idx;
873
874 public:
881 : owner(Owner), idx(Idx)
882 {}
883
888 operator array_t() const
889 {
891 for(int c=0; c<Components; c++)
892 {
893 retval[c] = owner.getComponent(idx,c);
894 }
895 return retval;
896 }
897
900 {
901 for(int c=0; c<Components; c++)
902 {
903 owner.getComponent(idx,c) = v[c];
904 }
905 return *this;
906 }
907
908
911 {
912 for(int c=0; c<Components; c++)
913 {
914 owner.getComponent(idx,c) = in.owner.getComponent( in.idx, c);
915 }
916 return *this;
917 }
918
919 typedef element_value_t value_type;
920 enum { SIZE = Components };
921
927 {
928 return Eagle::Assignment<ElementProxy, 0>(*this, x);
929 }
930
931
934 {
935 for(int c=0; c<Components; c++)
936 {
937 owner.getComponent(idx,c) += v[c];
938 }
939 return *this;
940 }
941
944 {
945 for(int c=0; c<Components; c++)
946 {
947 owner.getComponent(idx,c) -= v[c];
948 }
949 return *this;
950 }
951
953 element_value_t&operator[](int c) const
954 {
955 return owner.getComponent(idx,c);
956 }
957 };
958
959
960
961
962template <int C, class T>
964{
966
969
972
975
976 index_t myIndex;
977 Iterator<array_t>&myContainer;
978
980 : myIndex(theIndex)
981 , myContainer(theContainer)
982 {}
983
984 bool operator!=(const ranged_for_iterator&RFI) const
985 {
986 return myIndex !=RFI.myIndex;
987 }
988
989 void operator++()
990 {
991 myIndex++;
992 }
993
994#ifndef NON_INDEXABLE_ITERATOR
995 const ranged_for_iterator&operator*() const
996 {
997 return *this;
998 }
999
1000 operator Proxy() const
1001 {
1002 return myContainer[ myIndex ];
1003 }
1004
1007 {
1008 return myContainer.getComponent(myIndex,c);
1009 }
1010
1011#else
1012 Proxy operator*() const
1013 {
1014 return myContainer[ myIndex ];
1015 }
1016#endif
1017
1018 index_t getIndex() const
1019 {
1020 return myIndex;
1021 }
1022};
1023
1024
1038template <int C, class T>
1039class Iterator<Eagle::FixedArray<T, C> > : public IteratorBase<T>
1040{
1041public:
1042 using IteratorBase<T>::ptr;
1043 using IteratorBase<T>::getStride;
1044 using IteratorBase<T>::getOffset;
1045 using IteratorBase<T>::getLength;
1046 using IteratorBase<T>::count;
1047 using IteratorBase<T>::getElement;
1048// using IteratorBase<T>::operator();
1049
1051 enum { Components = C };
1052
1055
1058
1061
1064
1071 : IteratorBase<T>(Length*C, Ptr ? Ptr->ptr(0) : 0,
1072 C, // stride: size of each element
1073 1) // offset: from one element to the next one is one step
1074 {}
1075
1083 : IteratorBase<T>(size*C, Ptr, 1, size)
1084 {}
1085
1090 : IteratorBase<T>(ishift, P, Add() )
1091 {
1092// printf("Addition pointer constructor: old count %d, offset %d, new count %d; size=%d, components=%d\n",
1093// P.count(), ishift, count(),
1094// P.size(), C);
1095 }
1096
1097/*
1098 Iterator<Vector<C, T> > vec() const
1099 {
1100 return Iterator<Vector<C, T> >();
1101 }
1102*/
1103
1104 friend Iterator<FixedArray<T, C> > operator+(const Iterator<FixedArray<T, C> >&P, int32_t i)
1105 {
1106 return Iterator<FixedArray<T,C> >(i, P, Add() );
1107 }
1108
1109 friend Iterator<FixedArray<T,C> > operator+(int32_t i, const Iterator<FixedArray<T,C> >&P)
1110 {
1111 return Iterator<FixedArray<T,C> >(i, P, Add() );
1112 }
1113
1114
1115 friend Iterator<FixedArray<T,C> > operator+(const Iterator<FixedArray<T,C> >&P, int64_t i)
1116 {
1117 return Iterator<FixedArray<T,C> >(i, P, Add() );
1118 }
1119
1120 friend Iterator<FixedArray<T,C> > operator+(int64_t i, const Iterator<FixedArray<T,C> >&P)
1121 {
1122 return Iterator<FixedArray<T,C> >(i, P, Add() );
1123 }
1124
1125
1126
1127 friend Iterator<FixedArray<T, C> > operator+(const Iterator<FixedArray<T, C> >&P, uint32_t i)
1128 {
1129 return Iterator<FixedArray<T,C> >(i, P, Add() );
1130 }
1131
1132 friend Iterator<FixedArray<T,C> > operator+(uint32_t i, const Iterator<FixedArray<T,C> >&P)
1133 {
1134 return Iterator<FixedArray<T,C> >(i, P, Add() );
1135 }
1136
1137 friend Iterator<FixedArray<T,C> > operator+(const Iterator<FixedArray<T,C> >&P, uint64_t i)
1138 {
1139 return Iterator<FixedArray<T,C> >(i, P, Add() );
1140 }
1141
1142 friend Iterator<FixedArray<T,C> > operator+(uint64_t i, const Iterator<FixedArray<T,C> >&P)
1143 {
1144 return Iterator<FixedArray<T,C> >(i, P, Add() );
1145 }
1146
1147#if 0
1148 friend Iterator<FixedArray<T,C> > operator+(const Iterator<FixedArray<T,C> >&P, long long i)
1149 {
1150 return Iterator<FixedArray<T,C> >(i, P, Add() );
1151 }
1152
1153 friend Iterator<FixedArray<T,C> > operator+(long long i, const Iterator<FixedArray<T,C> >&P)
1154 {
1155 return Iterator<FixedArray<T,C> >(i, P, Add() );
1156 }
1157#endif
1158
1159 Iterator<T> getComponent(int i) const
1160 {
1161 return Iterator<T>(*this, i);
1162 }
1163
1164
1165 T&getComponent(index_t i, int c) const
1166 {
1167 assert(c<Components);
1168 return getElement(i,c);
1169 }
1170
1171 typedef Proxy reference_t;
1172
1175 {
1176 return Proxy(*this, i);
1177 }
1178
1181 {
1183 for(int c=0; c<Components; c++)
1184 {
1185 retval[c] = getComponent(i,c);
1186 }
1187 return retval;
1188 }
1189
1190
1192 {
1193 return const_ranged_for_iterator<array_t>(0, *this);
1194 }
1195
1196 const_ranged_for_iterator<array_t> end() const
1197 {
1198 return const_ranged_for_iterator<array_t>(count(), *this);
1199 }
1200
1201 ranged_for_iterator<array_t> begin()
1202 {
1203 return ranged_for_iterator<array_t>(0, *this);
1204 }
1205
1206 ranged_for_iterator<array_t> end()
1207 {
1208 return ranged_for_iterator<array_t>(count(), *this);
1209 }
1210
1211 template <class S>
1212 T&operator[](const ranged_for_iterator<S>&I)
1213 {
1214 return (*this)[I.myIndex];
1215 }
1216
1217 template <class S>
1218 const T&operator[](const ranged_for_iterator<S>&I) const
1219 {
1220 return (*this)[I.myIndex];
1221 }
1222
1223 template <class S>
1224 T&operator[](const const_ranged_for_iterator<S>&I)
1225 {
1226 return (*this)[I.myIndex];
1227 }
1228
1229 template <class S>
1230 const T&operator[](const const_ranged_for_iterator<S>&I) const
1231 {
1232 return (*this)[I.myIndex];
1233 }
1234
1235};
1236
1247template <class VectorType>
1248inline Iterator<typename FixedArrayTrait<typename Eagle::MetaInfo<VectorType>::element_t, Eagle::MetaInfo<VectorType>::MULTIPLICITY>::array_t >
1250{
1252//typedef FixedArray<typename FI::element_t, FI::MULTIPLICITY> array_t;
1254
1255array_t*data = V.ptr();
1256
1258 retval.setCount( V.count() );
1259 return retval;
1260}
1261
1267template <class Type>
1269{
1270 return It;
1271}
1272
1273/*
1274template <int N, class Type>
1275inline Iterator<typename FixedArrayTrait<Type, N>::array_t > array_iterator(const Iterator<FixedArray<Type, N> >&It)
1276{
1277 return It;
1278}
1279*/
1280
1281template <class Type>
1282inline Iterator<Type> array_iterator(const Iterator<FixedArray<Type, 1> >&It)
1283{
1284Type*data = It.ptr();
1285
1286Iterator<Type> retval( It.getLength(), data );
1287 retval.setCount( It.count() );
1288 return retval;
1289}
1290
1291
1292
1293template <int N, class Type>
1294inline Iterator<Eagle::Vector<Type,N> > vector_iterator(const Iterator<Eagle::VVector<N, Type> >&It)
1295{
1296 return Iterator<Eagle::Vector<Type,N> >( It, &It.ptr()->vec() );
1297}
1298
1299template <class T>
1301{
1302// return array_iterator( *this );
1303 return array_iterator( farray_iterator( *this ) );
1304}
1305
1306template <class T>
1311
1312// Iterator<component_t> getComponent(int i) const;
1313
1314
1315} /* namespace Fiber */
1316
1317#endif /* __vector_Iterator_HPP */
constexpr complex< _Tp > & operator=(const _Tp &)
basic_ostream< char > ostream
valarray< size_t > stride() const
valarray< size_t > size() const
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cerr
Vectorized vector.
Definition VVector.hpp:288
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
An iterator which allows to access each component element type of an array of vectors,...
Definition vector/Iterator.hpp:149
index_t length
The length (number of elements) of the data array.
Definition HyperslabParameters.hpp:37
ElementIterator(const ElementIterator &It)
Copy Constructor.
Definition vector/Iterator.hpp:188
ElementIterator(index_t Length, T *Data, index_t Stride, index_t Offset)
Construct an element iterator.
Definition vector/Iterator.hpp:173
ElementIterator(index_t i, const ElementIterator &It, const Add &)
Addition Constructor.
Definition vector/Iterator.hpp:218
void SetNewData(T *newData, index_t newLength)
Change the stored data chunk to a new location and length.
Definition vector/Iterator.hpp:233
T & getElement(index_t i, int c) const
Element access (no range check!).
Definition vector/Iterator.hpp:285
ElementIterator(const HyperslabParameters &It, T *newData)
Constructor compatible iterator with new data.
Definition vector/Iterator.hpp:203
T * ptr(int c=0) const
Return pointer to data, which is good for C interface, but otherwise, avoid that.
Definition vector/Iterator.hpp:266
A proxy for Iterators, such that an Iterator's element looks like an Iterator's element (!...
Definition vector/Iterator.hpp:866
element_value_t & operator[](int c) const
access a component of the element
Definition vector/Iterator.hpp:953
ElementProxy & operator-=(const array_t &v)
Self-substraction operator.
Definition vector/Iterator.hpp:943
Eagle::Assignment< ElementProxy, 0 > operator=(const element_value_t &x)
Overloading of the assignment operator such that the comma operator may be used to assign components ...
Definition vector/Iterator.hpp:926
ElementProxy(const Iterator &Owner, index_t Idx)
Construct an ElementProxy as a reference to a specific element in a given array, which is accessed vi...
Definition vector/Iterator.hpp:880
ElementProxy & operator=(const array_t &v)
Assign an array element.
Definition vector/Iterator.hpp:899
ElementProxy & operator+=(const array_t &v)
Self-addition operator.
Definition vector/Iterator.hpp:933
ElementProxy & operator=(const ElementProxy &in)
Assign an array element from another element proxy.
Definition vector/Iterator.hpp:910
Definition vector/Iterator.hpp:373
A set of integer values which describes how to iterate over a certain set of values.
Definition HyperslabParameters.hpp:34
index_t getIndex(index_t i, int c) const
Given a major and a minor index, compute the overall index in the dataset according to.
Definition HyperslabParameters.hpp:176
bool isSeparatedCompound() const
Tell if the iterator refers to a data set which is built from arrays of structure members,...
Definition HyperslabParameters.hpp:108
index_t getLength() const
Return the number of elements which can be accessed through this ElementIterator.
Definition HyperslabParameters.hpp:76
index_t length
The length (number of elements) of the data array.
Definition HyperslabParameters.hpp:37
void setCount(index_t size)
Set the maximally allowed count, i.e.
Definition HyperslabParameters.hpp:156
index_t count() const
Return the number of steps which can be traversed through this ElementIterator.
Definition HyperslabParameters.hpp:147
Intermediate base class for generic iterators.
Definition vector/Iterator.hpp:329
IteratorBase(const HyperslabParameters &IB, T *d)
Construct compatible iterator with different data.
Definition vector/Iterator.hpp:355
Iterator(index_t Length, FixedArray< T, C > *Ptr)
Construct a pointer to a field of arrays from a native pointer to arrays.
Definition vector/Iterator.hpp:1070
Iterator< array_t > Iterator_t
Shortcut type definition to this iterator itself.
Definition vector/Iterator.hpp:1060
T element_value_t
Export the type of each element.
Definition vector/Iterator.hpp:1057
FixedArray< T, Components > array_t
Export the type of the fixed array.
Definition vector/Iterator.hpp:1054
array_t getValue(index_t i) const
The copy-by-value version of retrieving an element.
Definition vector/Iterator.hpp:1180
Iterator(index_t size, T *Ptr)
Construct a pointer to a field of arrays from an array of fields which reside consecutive in memory.
Definition vector/Iterator.hpp:1082
Proxy operator[](index_t i) const
Access an element of the array.
Definition vector/Iterator.hpp:1174
ElementProxy< Iterator_t > Proxy
The associated proxy type for element access.
Definition vector/Iterator.hpp:1063
Iterator(index_t ishift, const Iterator &P, const Add &)
Addition Constructor.
Definition vector/Iterator.hpp:1089
Implementation of an Iterator to a sequence of elements, which might be contiguous or a projection of...
Definition vector/Iterator.hpp:525
Iterator(index_t howmany, T *Ptr)
Construct view pointer from contiguous storage.
Definition vector/Iterator.hpp:551
T & operator[](index_t i) const
Access an element of the array, writeable.
Definition vector/Iterator.hpp:712
Iterator(index_t howmany, FixedArray< T, Components > *Ptr, int component)
Construct view pointer to a single component within a contiguous storage of array objects.
Definition vector/Iterator.hpp:581
Iterator(index_t Length, Eagle::VVector< Components, T > *Ptr, int component)
Construct view pointer to a single component within a contigous storage of array objects.
Definition vector/Iterator.hpp:631
T & reference_t
The reference type.
Definition vector/Iterator.hpp:709
const T & getValue(index_t i) const
Get the value, readonly.
Definition vector/Iterator.hpp:718
Iterator< array_t > getArrayIterator() const
Get an iterator that operates on associated FixedArray<> subjects.
Definition vector/Iterator.hpp:1300
Iterator(const Iterator &P)
Copy Constructor.
Definition vector/Iterator.hpp:568
Iterator< component_t > getComponent(int n) const
Get an iterator that operates on the nth component.
Definition vector/Iterator.hpp:1307
Iterator(const Iterator &P, int)
Copy Constructor with irrelevant member selection2.
Definition vector/Iterator.hpp:573
Iterator(index_t ishift, const Iterator &P, const Add &)
Addition Constructor.
Definition vector/Iterator.hpp:641
void set(const T &Value)
Set all elements to the same value.
Definition vector/Iterator.hpp:724
Iterator(const Iterator< FixedArray< T, Components > > &It, int component)
Definition vector/Iterator.hpp:591
Iterator(const HyperslabParameters &P, T *Ptr)
Construct iterator with alternative data, but otherwise compatible properties.
Definition vector/Iterator.hpp:563
Column< R, value > operator*(const Matrix< R, C, value > &A, const Column< C, value > &V)
Anemone_Context_t operator<<(Anemone &A, VRenderContext &VC)
Iterator< typename FixedArrayTrait< typename Eagle::MetaInfo< VectorType >::element_t, Eagle::MetaInfo< VectorType >::MULTIPLICITY >::array_t > farray_iterator(const Iterator< VectorType > &V)
Convert an iterator to a contiguous array of vectors into an iterator over elements which are FixedAr...
Definition vector/Iterator.hpp:1249
Operator<'-'> Sub
Operator<'+'> Add
Operator<' *'> Mult
Operator<'/'> Div
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
Iterator< Type > array_iterator(const Iterator< Type > &It)
Specialization of the array_iterator() function for Iterators on what is already a FixedArray.
Definition vector/Iterator.hpp:1268
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
string to_string(const Eagle::FixedArray< ElementType, N > &A, const char *OpenBrace="{", const char *CloseBrace="}", const char *Separator=",")
Definition vector/Iterator.hpp:386
Definition vector/Iterator.hpp:35
Definition vector/Iterator.hpp:395
element_value_t & operator[](int c) const
access a component of the element
Definition vector/Iterator.hpp:1006
ElementProxy< Iterator_t > Proxy
The associated proxy type for element access.
Definition vector/Iterator.hpp:974
T element_value_t
Export the type of each element.
Definition vector/Iterator.hpp:968
Iterator< array_t > Iterator_t
Shortcut type definition to this iterator itself.
Definition vector/Iterator.hpp:971
Definition vector/Iterator.hpp:423