Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JArray.hh
Go to the documentation of this file.
1#ifndef __JTOOLS__JARRAY__
2#define __JTOOLS__JARRAY__
3
4#include <istream>
5#include <ostream>
6#include <iterator>
7#include <algorithm>
8
10#include "JTools/JMultiKey.hh"
11#include "JMath/JMath.hh"
12#include "JLang/JAssert.hh"
13#include "JLang/JClass.hh"
14#include "JLang/JException.hh"
15#include "JLang/JEquals.hh"
16#include "JLang/JManip.hh"
17
18
19/**
20 * \author mdejong
21 */
22
23namespace JTOOLS {}
24namespace JPP { using namespace JTOOLS; }
25
26namespace JTOOLS {
27
28 using JIO::JReader;
29 using JIO::JWriter;
30 using JMATH::JMath;
31 using JLANG::JEquals;
33
34
35 /**
36 * One dimensional array of template objects with fixed length.\n
37 * The internal data structure consists of a standard C-array.
38 */
39 template<unsigned int N, class T>
40 class JArray :
41 public JMath < JArray<N,T> >,
42 public JEquals< JArray<N,T> >
43 {
44 public:
45
46 typedef const T* const_pointer;
47 typedef T* pointer;
48 typedef const T* const_iterator;
49 typedef T* iterator;
50 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
51 typedef std::reverse_iterator<iterator> reverse_iterator;
52 typedef T& reference;
53 typedef const T& const_reference;
54 typedef unsigned int size_type;
56
57
58 /**
59 * Default constructor.
60 */
62 {
63 fill(T());
64 }
65
66
67 /**
68 * Copy constructor.
69 *
70 * \param array array
71 */
72 template<unsigned int M>
73 JArray(const JArray<M, T>& array)
74 {
75 STATIC_CHECK(M >= N);
76
77 std::copy_n(array.data(), N, this->data());
78 }
79
80
81 /**
82 * Copy constructor.
83 *
84 * \param array array
85 */
86 template<unsigned int M>
88 {
89 STATIC_CHECK(M >= N);
90
91 std::copy_n(array.data(), N, this->data());
92 }
93
94
95 /**
96 * Copy constructor.
97 *
98 * \param p pointer to data
99 */
100 JArray(const T* p)
101 {
102 std::copy_n(p, N, this->data());
103 }
104
105
106 /**
107 * Copy constructor.
108 *
109 * \param key multi-dimensional key
110 */
112 {
113 assign(key);
114 }
115
116
117 /**
118 * Copy constructor.
119 *
120 * \param key multi-dimensional key
121 */
123 {
124 assign(key);
125 }
126
127
128 /**
129 * Append constructor.
130 *
131 * \param array array
132 * \param value value
133 */
135 {
136 std::copy_n(array.data(), N-1, this->data());
137
138 this->buffer[N-1] = value;
139 }
140
141
142 /**
143 * Append constructor.
144 *
145 * \param array array
146 * \param value value
147 */
149 {
150 std::copy_n(array.data(), N-1, this->data());
151
152 this->buffer[N-1] = value;
153 }
154
155
156 /**
157 * Append constructor.
158 *
159 * \param key multi-dimensional key
160 * \param value value
161 */
163 {
164 assign(key, value);
165 }
166
167
168 /**
169 * Append constructor.
170 *
171 * \param key multi-dimensional key
172 * \param value value
173 */
175 {
176 assign(key, value);
177 }
178
179
180 /**
181 * Initialise constructor.
182 *
183 * \param value first value
184 * \param args remaining values
185 */
186 template<class ...Args>
187 JArray(argument_type value, const Args& ...args)
188 {
189 set(value, args...);
190 }
191
192
193 /**
194 * Set array.
195 *
196 * \param args values
197 */
198 template<class ...Args>
199 JArray& set(const Args& ...args)
200 {
201 STATIC_CHECK(N == sizeof...(Args));
202
203 __set__(0, args...);
204
205 return *this;
206 }
207
208
209 /**
210 * Type conversion operator.
211 *
212 * \return multi-key
213 */
214 operator JMultiKey<N, T>() const
215 {
216 return JMultiKey<N, T>(buffer[0], this->pop_front());
217 }
218
219
220 const_iterator begin() const { return buffer; } //!< get iterator to begin of data
221 const_iterator end() const { return buffer + N; } //!< get iterator to end of data
222
223
224 iterator begin() { return buffer; } //!< get iterator to begin of data
225 iterator end() { return buffer + N; } //!< get iterator to end of data
226
227
228 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
229 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to begin of data
230
231
232 reverse_iterator rbegin() { return reverse_iterator(end()); } //!< get reverse iterator to begin of data
233 reverse_iterator rend() { return reverse_iterator(begin()); } //!< get reverse iterator to end of data
234
235
236 /**
237 * Get element at given index.
238 *
239 * \param index index
240 * \return element
241 */
243 {
244 return buffer[index];
245 }
246
247
248 /**
249 * Get element at given index.
250 *
251 * \param index index
252 * \return element
253 */
255 {
256 return buffer[index];
257 }
258
259
260 /**
261 * Get element at given index.
262 *
263 * \param index index
264 * \return element at index
265 */
266 const_reference at(int index) const
267 {
268 if (index >= 0 && index < N)
269 return buffer[index];
270 else
271 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
272 }
273
274
275 /**
276 * Get element at given index.
277 *
278 * \param index index
279 * \return element at index
280 */
281 reference at(int index)
282 {
283 if (index >= 0 && index < N)
284 return buffer[index];
285 else
286 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
287 }
288
289
290 /**
291 * Get pointer to data.
292 *
293 * \return pointer to data
294 */
296 {
297 return buffer;
298 }
299
300
301 /**
302 * Get pointer to data.
303 *
304 * \return pointer to data
305 */
307 {
308 return buffer;
309 }
310
311
312 /**
313 * Get size of data.
314 *
315 * \return size of data
316 */
318 {
319 return N;
320 }
321
322
323 /**
324 * Make a copy in which the first element is removed.
325 *
326 * \return array
327 */
328 JArray<N-1, T> pop_front() const
329 {
330 return JArray<N-1, T>(&buffer[1]);
331 }
332
333
334 /**
335 * Make a copy in which the last element is removed.
336 *
337 * \return array
338 */
339 JArray<N-1, T> pop_back() const
340 {
341 return JArray<N-1, T>(buffer);
342 }
343
344
345 /**
346 * Fill array.
347 *
348 * \param value value
349 */
350 void fill(argument_type value)
351 {
352 for (int i = 0; i != N; ++i) {
353 buffer[i] = value;
354 }
355 }
356
357
358 /**
359 * Negate array.
360 *
361 * \return this array
362 */
364 {
365 for (int i = 0; i != N; ++i) {
366 buffer[i] = -buffer[i];
367 }
368
369 return *this;
370 }
371
372
373 /**
374 * Add array.
375 *
376 * \param array array
377 * \return this array
378 */
379 JArray& add(const JArray& array)
380 {
381 for (int i = 0; i != N; ++i) {
382 buffer[i] += array[i];
383 }
384
385 return *this;
386 }
387
388
389 /**
390 * Subtract array.
391 *
392 * \param array array
393 * \return this array
394 */
395 JArray& sub(const JArray& array)
396 {
397 for (int i = 0; i != N; ++i) {
398 buffer[i] -= array[i];
399 }
400
401 return *this;
402 }
403
404
405 /**
406 * Scale array.
407 *
408 * \param factor multiplication factor
409 * \return this array
410 */
411 JArray& mul(const double factor)
412 {
413 for (int i = 0; i != N; ++i) {
414 buffer[i] *= factor;
415 }
416
417 return *this;
418 }
419
420
421 /**
422 * Scale array.
423 *
424 * \param factor division factor
425 * \return this array
426 */
427 JArray& div(const double factor)
428 {
429 for (int i = 0; i != N; ++i) {
430 buffer[i] /= factor;
431 }
432
433 return *this;
434 }
435
436
437 /**
438 * Check equality.
439 *
440 * \param array array
441 * \return true if arrays are equal; else false
442 */
443 bool equals(const JArray<N, T>& array) const
444 {
445 for (int i = 0; i != N; ++i) {
446 if (buffer[i] != array[i]) {
447 return false;
448 }
449 }
450
451 return true;
452 }
453
454
455 /**
456 * Read array from input stream.
457 *
458 * \param in input stream
459 * \param array array
460 * \return input stream
461 */
462 friend inline std::istream& operator>>(std::istream& in, JArray& array)
463 {
464 for (iterator i = array.begin(); i != array.end(); ++i) {
465 in >> *i;
466 }
467
468 return in;
469 }
470
471
472 /**
473 * Write array to output stream.
474 *
475 * \param out output stream
476 * \param array array
477 * \return output stream
478 */
479 friend inline std::ostream& operator<<(std::ostream& out, const JArray& array)
480 {
481 for (const_iterator i = array.begin(); i != array.end(); ++i) {
482 out << ' ' << SCIENTIFIC(12,5) << *i;
483 }
484
485 return out;
486 }
487
488
489 /**
490 * Read array from input.
491 *
492 * \param in reader
493 * \param buffer array
494 * \return reader
495 */
496 friend inline JReader& operator>>(JReader& in, JArray& buffer)
497 {
498 for (iterator i = buffer.begin(); i != buffer.end(); ++i) {
499 in >> *i;
500 }
501
502 return in;
503 }
504
505
506 /**
507 * Write array to output.
508 *
509 * \param out writer
510 * \param buffer array
511 * \return writer
512 */
513 friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
514 {
515 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
516 out << *i;
517 }
518
519 return out;
520 }
521
522 protected:
523
524 T buffer[N];
525
526
527 /**
528 * Recursive method for setting array.
529 *
530 * \param i index
531 * \param x value at given index
532 * \param args remaining values
533 */
534 template<class ...Args>
535 void __set__(const int i, const argument_type x, const Args& ...args)
536 {
537 this->buffer[i] = x;
538
539 __set__(i + 1, args...);
540 }
541
542
543 /**
544 * Termination method for setting array.
545 *
546 * \param i index
547 */
548 void __set__(const int i) const
549 {}
550
551
552 /**
553 * Recursive method for setting array.
554 *
555 * \param key multi-dimensional key
556 */
557 template<unsigned int M>
558 void assign(const JMultiKey<M, T>& key)
559 {
560 buffer[N-M] = key.first;
561
562 assign(key.second);
563 }
564
565
566 /**
567 * Recursive method for setting array.
568 *
569 * \param key multi-dimensional key
570 */
571 template<unsigned int M>
573 {
574 buffer[N-M] = key.first;
575
576 assign(key.second);
577 }
578
579
580 /**
581 * Termination method for setting array.
582 *
583 * \param key one-dimensional key
584 */
585 void assign(const JMultiKey<1, T>& key)
586 {
587 buffer[N-1] = key.first;
588 }
589
590
591 /**
592 * Termination method for setting array.
593 *
594 * \param key one-dimensional key
595 */
597 {
598 buffer[N-1] = key.first;
599 }
600
601
602 /**
603 * Recursive method for setting array.
604 *
605 * \param key multi-dimensional key
606 * \param value value
607 */
608 template<unsigned int M>
609 void assign(const JMultiKey<M, T>& key, argument_type value)
610 {
611 buffer[N-M-1] = key.first;
612
613 assign(key.second, value);
614 }
615
616
617 /**
618 * Recursive method for setting array.
619 *
620 * \param key multi-dimensional key
621 * \param value value
622 */
623 template<unsigned int M>
625 {
626 buffer[N-M-1] = key.first;
627
628 assign(key.second, value);
629 }
630
631
632 /**
633 * Termination method for setting array.
634 *
635 * \param key one-dimensional key
636 * \param value value
637 */
638 void assign(const JMultiKey<1, T>& key, argument_type value)
639 {
640 buffer[N-2] = key.first;
641 buffer[N-1] = value;
642 }
643
644
645 /**
646 * Termination method for setting array.
647 *
648 * \param key one-dimensional key
649 * \param value value
650 */
652 {
653 buffer[N-2] = key.first;
654 buffer[N-1] = value;
655 }
656 };
657
658
659 /**
660 * One dimensional array of template objects with fixed length.
661 * The internal data structure consists of a standard C-array.
662 */
663 template<class T>
664 class JArray<1, T> :
665 public JMath < JArray<1,T> >,
666 public JEquals< JArray<1,T> >
667 {
668 public:
669
670 static const unsigned int N = 1;
671
672 typedef const T* const_pointer;
673 typedef T* pointer;
674 typedef const T* const_iterator;
675 typedef T* iterator;
676 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
677 typedef std::reverse_iterator<iterator> reverse_iterator;
678 typedef T& reference;
679 typedef const T& const_reference;
680 typedef unsigned int size_type;
682
683
684 /**
685 * Default constructor.
686 */
688 {
689 fill(T());
690 }
691
692
693 /**
694 * Copy constructor.
695 *
696 * \param array array
697 */
698 template<unsigned int M>
699 JArray(const JArray<M, T>& array)
700 {
701 buffer[0] = array[0];
702 }
703
704
705 /**
706 * Copy constructor.
707 *
708 * \param array array
709 */
710 template<unsigned int M>
712 {
713 buffer[0] = array[0];
714 }
715
716
717 /**
718 * Copy constructor.
719 *
720 * \param p pointer to data
721 */
722 JArray(const T* p)
723 {
724 buffer[0] = p[0];
725 }
726
727
728 /**
729 * Copy constructor.
730 *
731 * \param key multi-dimensional key
732 */
734 {
735 buffer[0] = key.first;
736 }
737
738
739 /**
740 * Copy constructor.
741 *
742 * \param key multi-dimensional key
743 */
745 {
746 buffer[0] = key.first;
747 }
748
749
750 /**
751 * Initialise constructor.
752 *
753 * \param value value;
754 */
756 {
757 buffer[0] = value;
758 }
759
760
761 /**
762 * Type conversion operator.
763 *
764 * \return multi-key
765 */
766 operator JMultiKey<N, T>() const
767 {
768 return JMultiKey<N, T>(buffer[0]);
769 }
770
771
772 const_iterator begin() const { return buffer; } //!< get iterator to begin of data
773 const_iterator end() const { return buffer + N; } //!< get iterator to end of data
774
775
776 iterator begin() { return buffer; } //!< get iterator to begin of data
777 iterator end() { return buffer + N; } //!< get iterator to end of data
778
779
780 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
781 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to begin of data
782
783
784 reverse_iterator rbegin() { return reverse_iterator(end()); } //!< get reverse iterator to begin of data
785 reverse_iterator rend() { return reverse_iterator(begin()); } //!< get reverse iterator to end of data
786
787
788 /**
789 * Get element at given index.
790 *
791 * \param index index
792 * \return element
793 */
795 {
796 return buffer[index];
797 }
798
799
800 /**
801 * Get element at given index.
802 *
803 * \param index index
804 * \return element
805 */
807 {
808 return buffer[index];
809 }
810
811
812 /**
813 * Get element at given index.
814 *
815 * \param index index
816 * \return element at index
817 */
818 const_reference at(int index) const
819 {
820 if (index == 0)
821 return buffer[index];
822 else
823 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
824 }
825
826
827 /**
828 * Get element at given index.
829 *
830 * \param index index
831 * \return element at index
832 */
833 reference at(int index)
834 {
835 if (index == 0)
836 return buffer[index];
837 else
838 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
839 }
840
841
842 /**
843 * Get pointer to data.
844 *
845 * \return pointer to data
846 */
848 {
849 return buffer;
850 }
851
852
853 /**
854 * Get pointer to data.
855 *
856 * \return pointer to data
857 */
859 {
860 return buffer;
861 }
862
863
864 /**
865 * Get size of data.
866 *
867 * \return size of data
868 */
870 {
871 return N;
872 }
873
874
875 /**
876 * Fill array.
877 *
878 * \param value value
879 */
880 void fill(argument_type value)
881 {
882 buffer[0] = value;
883 }
884
885
886 /**
887 * Negate array.
888 *
889 * \return this array
890 */
892 {
893 buffer[0] = -buffer[0];
894
895 return *this;
896 }
897
898
899 /**
900 * Add array.
901 *
902 * \param array array
903 * \return this array
904 */
905 JArray& add(const JArray& array)
906 {
907 buffer[0] += array[0];
908
909 return *this;
910 }
911
912
913 /**
914 * Subtract array.
915 *
916 * \param array array
917 * \return this array
918 */
919 JArray& sub(const JArray& array)
920 {
921 buffer[0] -= array[0];
922
923 return *this;
924 }
925
926
927 /**
928 * Scale array.
929 *
930 * \param factor multiplication factor
931 * \return this array
932 */
933 JArray& mul(const double factor)
934 {
935 buffer[0] *= factor;
936
937 return *this;
938 }
939
940
941 /**
942 * Scale array.
943 *
944 * \param factor division factor
945 * \return this array
946 */
947 JArray& div(const double factor)
948 {
949 buffer[0] /= factor;
950
951 return *this;
952 }
953
954
955 /**
956 * Check equality.
957 *
958 * \param array array
959 * \return true if arrays are equal; else false
960 */
961 bool equals(const JArray<N, T>& array) const
962 {
963 return buffer[0] == array[0];
964 }
965
966
967 /**
968 * Read array from input stream.
969 *
970 * \param in input stream
971 * \param array array
972 * \return input stream
973 */
974 friend inline std::istream& operator>>(std::istream& in, JArray& array)
975 {
976 for (iterator i = array.begin(); i != array.end(); ++i) {
977 in >> *i;
978 }
979
980 return in;
981 }
982
983
984 /**
985 * Write array to output stream.
986 *
987 * \param out output stream
988 * \param array array
989 * \return output stream
990 */
991 friend inline std::ostream& operator<<(std::ostream& out, const JArray& array)
992 {
993 for (const_iterator i = array.begin(); i != array.end(); ++i) {
994 out << ' ' << SCIENTIFIC(12,5) << *i;
995 }
996
997 return out;
998 }
999
1000
1001 /**
1002 * Read array from input.
1003 *
1004 * \param in reader
1005 * \param buffer array
1006 * \return reader
1007 */
1009 {
1010 return in >> buffer[0];
1011 }
1012
1013
1014 /**
1015 * Write array to output.
1016 *
1017 * \param out writer
1018 * \param buffer array
1019 * \return writer
1020 */
1021 friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1022 {
1023 return out << buffer[0];
1024 }
1025
1026 protected:
1028 };
1029
1030
1031 /**
1032 * One dimensional read-only array of template objects with fixed length.
1033 * The internal data structure consists of a simple C-pointer to the actual data.
1034 * The user should ensure that the data are persistent.
1035 */
1036 template<unsigned int N, class T>
1037 class JArray<N, const T> {
1038 public:
1039
1040 friend class JArray<N + 1, const T>;
1041
1042 typedef const T* const_pointer;
1043 typedef const T* const_iterator;
1044 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1045 typedef const T& const_reference;
1046 typedef unsigned int size_type;
1047
1048
1049 /**
1050 * Copy constructor.
1051 *
1052 * \param array array
1053 */
1054 template<unsigned int M>
1055 JArray(const JArray<M, T>& array) :
1056 p(array.data())
1057 {
1058 STATIC_CHECK(M >= N);
1059 }
1060
1061
1062 /**
1063 * Copy constructor.
1064 *
1065 * \param array array
1066 */
1067 template<unsigned int M>
1069 p(array.data())
1070 {
1071 STATIC_CHECK(M >= N);
1072 }
1073
1074
1075 /**
1076 * Type conversion operator.
1077 *
1078 * \return multi-key
1079 */
1080 operator JMultiKey<N, const T>() const
1081 {
1082 return JMultiKey<N, const T>(p[0], this->pop_front());
1083 }
1084
1085
1086 const_iterator begin() const { return p; } //!< get iterator to begin of data
1087 const_iterator end() const { return p + N; } //!< get iterator to end of data
1088
1089
1090 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
1091 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to end of data
1092
1093
1094 /**
1095 * Get element at given index.
1096 *
1097 * \param index index
1098 * \return element at index
1099 */
1101 {
1102 return p[index];
1103 }
1104
1105
1106 /**
1107 * Get element at given index.
1108 *
1109 * \param index index
1110 * \return element at index
1111 */
1112 const_reference at(int index) const
1113 {
1114 if (index >= 0 && index < N)
1115 return p[index];
1116 else
1117 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
1118 }
1119
1120
1121 /**
1122 * Get pointer to data.
1123 *
1124 * \return pointer to data
1125 */
1127 {
1128 return p;
1129 }
1130
1131
1132 /**
1133 * Get size of data.
1134 *
1135 * \return size of data
1136 */
1138 {
1139 return N;
1140 }
1141
1142
1143 /**
1144 * Make a copy in which the first element is removed.
1145 *
1146 * \return array
1147 */
1148 JArray<N-1, const T> pop_front() const
1149 {
1150 return JArray<N-1, const T>(p + 1);
1151 }
1152
1153
1154 /**
1155 * Make a copy in which the last element is removed.
1156 *
1157 * \return array
1158 */
1159 JArray<N-1, const T> pop_back() const
1160 {
1161 return JArray<N-1, const T>(p);
1162 }
1163
1164
1165 /**
1166 * Write array to output.
1167 *
1168 * \param out writer
1169 * \param buffer array
1170 * \return writer
1171 */
1172 friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1173 {
1174 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
1175 out << *i;
1176 }
1177
1178 return out;
1179 }
1180
1181 protected:
1182
1184
1185 /**
1186 * Constructor.
1187 *
1188 * \param __p pointer to data
1189 */
1190 JArray(const T* __p) :
1191 p(__p)
1192 {}
1193 };
1194
1195
1196 /**
1197 * One dimensional read-only array of template objects with fixed length.
1198 * The internal data structure consists of a simple C-pointer to the actual data.
1199 * The user should ensure that the data are persistent.
1200 */
1201 template<class T>
1202 class JArray<1, const T> {
1203 public:
1204
1205 static const unsigned int N = 1;
1206
1207 friend class JArray<N + 1, const T>;
1208
1209 typedef const T* const_pointer;
1210 typedef const T* const_iterator;
1211 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1212 typedef const T& const_reference;
1213 typedef unsigned int size_type;
1214
1215
1216 /**
1217 * Copy constructor.
1218 *
1219 * \param array array
1220 */
1221 template<unsigned int M>
1222 JArray(const JArray<M, T>& array) :
1223 p(array.data())
1224 {
1225 STATIC_CHECK(M >= N);
1226 }
1227
1228
1229 /**
1230 * Copy constructor.
1231 *
1232 * \param array array
1233 */
1234 template<unsigned int M>
1236 p(array.data())
1237 {
1238 STATIC_CHECK(M >= N);
1239 }
1240
1241
1242 /**
1243 * Type conversion operator.
1244 *
1245 * \return multi-key
1246 */
1247 operator JMultiKey<1, const T>() const
1248 {
1249 return JMultiKey<1, const T>(p[0]);
1250 }
1251
1252
1253 const_iterator begin() const { return p; } //!< get iterator to begin of data
1254 const_iterator end() const { return p + N; } //!< get iterator to end of data
1255
1256
1257 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
1258 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to end of data
1259
1260
1261 /**
1262 * Get element at given index.
1263 *
1264 * \param index index
1265 * \return element at index
1266 */
1268 {
1269 return p[index];
1270 }
1271
1272
1273 /**
1274 * Get element at given index.
1275 *
1276 * \param index index
1277 * \return element at index
1278 */
1279 const_reference at(int index) const
1280 {
1281 if (index >= 0 && index < N)
1282 return p[index];
1283 else
1284 THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
1285 }
1286
1287
1288 /**
1289 * Get pointer to data.
1290 *
1291 * \return pointer to data
1292 */
1294 {
1295 return p;
1296 }
1297
1298
1299 /**
1300 * Get size of data.
1301 *
1302 * \return size of data
1303 */
1305 {
1306 return N;
1307 }
1308
1309
1310 /**
1311 * Write array to output.
1312 *
1313 * \param out writer
1314 * \param buffer array
1315 * \return writer
1316 */
1317 friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1318 {
1319 return out << buffer[0];
1320 }
1321
1322 protected:
1323
1325
1326 /**
1327 * Constructor.
1328 *
1329 * \param __p pointer to data
1330 */
1331 JArray(const T* __p) :
1332 p(__p)
1333 {}
1334 };
1335}
1336
1337#endif
#define STATIC_CHECK(expr)
Definition JAssert.hh:31
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O manipulators.
Base class for data structures with artithmetic capabilities.
Interface for binary input.
Interface for binary output.
Exception for accessing an index in a collection that is outside of its range.
const_pointer data() const
Get pointer to data.
Definition JArray.hh:847
const T * const_pointer
Definition JArray.hh:672
JArray()
Default constructor.
Definition JArray.hh:687
const_reference at(int index) const
Get element at given index.
Definition JArray.hh:818
reference at(int index)
Get element at given index.
Definition JArray.hh:833
pointer data()
Get pointer to data.
Definition JArray.hh:858
const_iterator begin() const
get iterator to begin of data
Definition JArray.hh:772
JArray & negate()
Negate array.
Definition JArray.hh:891
JArray(argument_type value)
Initialise constructor.
Definition JArray.hh:755
JArray(const JMultiKey< 1, T > &key)
Copy constructor.
Definition JArray.hh:733
JArray & sub(const JArray &array)
Subtract array.
Definition JArray.hh:919
friend std::istream & operator>>(std::istream &in, JArray &array)
Read array from input stream.
Definition JArray.hh:974
const_iterator end() const
get iterator to end of data
Definition JArray.hh:773
iterator end()
get iterator to end of data
Definition JArray.hh:777
JArray & div(const double factor)
Scale array.
Definition JArray.hh:947
std::reverse_iterator< iterator > reverse_iterator
Definition JArray.hh:677
JArray(const JMultiKey< 1, const T > &key)
Copy constructor.
Definition JArray.hh:744
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition JArray.hh:676
reverse_iterator rend()
get reverse iterator to end of data
Definition JArray.hh:785
unsigned int size_type
Definition JArray.hh:680
JArray & add(const JArray &array)
Add array.
Definition JArray.hh:905
const_reverse_iterator rend() const
get reverse iterator to begin of data
Definition JArray.hh:781
const_reference operator[](int index) const
Get element at given index.
Definition JArray.hh:794
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition JArray.hh:711
reference operator[](int index)
Get element at given index.
Definition JArray.hh:806
JLANG::JClass< T >::argument_type argument_type
Definition JArray.hh:681
static size_type size()
Get size of data.
Definition JArray.hh:869
const T & const_reference
Definition JArray.hh:679
iterator begin()
get iterator to begin of data
Definition JArray.hh:776
JArray(const JArray< M, T > &array)
Copy constructor.
Definition JArray.hh:699
JArray & mul(const double factor)
Scale array.
Definition JArray.hh:933
const T * const_iterator
Definition JArray.hh:674
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition JArray.hh:1021
JArray(const T *p)
Copy constructor.
Definition JArray.hh:722
void fill(argument_type value)
Fill array.
Definition JArray.hh:880
friend JReader & operator>>(JReader &in, JArray &buffer)
Read array from input.
Definition JArray.hh:1008
friend std::ostream & operator<<(std::ostream &out, const JArray &array)
Write array to output stream.
Definition JArray.hh:991
reverse_iterator rbegin()
get reverse iterator to begin of data
Definition JArray.hh:784
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition JArray.hh:780
bool equals(const JArray< N, T > &array) const
Check equality.
Definition JArray.hh:961
JArray(const T *__p)
Constructor.
Definition JArray.hh:1331
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition JArray.hh:1235
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition JArray.hh:1211
const_iterator begin() const
get iterator to begin of data
Definition JArray.hh:1253
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition JArray.hh:1257
static size_type size()
Get size of data.
Definition JArray.hh:1304
const_reference at(int index) const
Get element at given index.
Definition JArray.hh:1279
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition JArray.hh:1317
const_reverse_iterator rend() const
get reverse iterator to end of data
Definition JArray.hh:1258
const_reference operator[](int index) const
Get element at given index.
Definition JArray.hh:1267
const_pointer data() const
Get pointer to data.
Definition JArray.hh:1293
JArray(const JArray< M, T > &array)
Copy constructor.
Definition JArray.hh:1222
const_iterator end() const
get iterator to end of data
Definition JArray.hh:1254
const_reference at(int index) const
Get element at given index.
Definition JArray.hh:1112
const_reference operator[](int index) const
Get element at given index.
Definition JArray.hh:1100
const_reverse_iterator rend() const
get reverse iterator to end of data
Definition JArray.hh:1091
JArray(const T *__p)
Constructor.
Definition JArray.hh:1190
static size_type size()
Get size of data.
Definition JArray.hh:1137
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition JArray.hh:1044
JArray(const JArray< M, T > &array)
Copy constructor.
Definition JArray.hh:1055
const_iterator begin() const
get iterator to begin of data
Definition JArray.hh:1086
JArray< N-1, const T > pop_front() const
Make a copy in which the first element is removed.
Definition JArray.hh:1148
JArray< N-1, const T > pop_back() const
Make a copy in which the last element is removed.
Definition JArray.hh:1159
const_pointer data() const
Get pointer to data.
Definition JArray.hh:1126
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition JArray.hh:1068
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition JArray.hh:1172
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition JArray.hh:1090
const_iterator end() const
get iterator to end of data
Definition JArray.hh:1087
One dimensional array of template objects with fixed length.
Definition JArray.hh:43
const_reference operator[](int index) const
Get element at given index.
Definition JArray.hh:242
JArray(const JMultiKey< N-1, T > &key, argument_type value)
Append constructor.
Definition JArray.hh:162
const_iterator end() const
get iterator to end of data
Definition JArray.hh:221
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition JArray.hh:87
void assign(const JMultiKey< 1, const T > &key, argument_type value)
Termination method for setting array.
Definition JArray.hh:651
JArray(const T *p)
Copy constructor.
Definition JArray.hh:100
JArray(const JMultiKey< N, T > &key)
Copy constructor.
Definition JArray.hh:111
const T & const_reference
Definition JArray.hh:53
JArray< N-1, T > pop_back() const
Make a copy in which the last element is removed.
Definition JArray.hh:339
JArray & add(const JArray &array)
Add array.
Definition JArray.hh:379
JArray & negate()
Negate array.
Definition JArray.hh:363
friend std::istream & operator>>(std::istream &in, JArray &array)
Read array from input stream.
Definition JArray.hh:462
JArray & div(const double factor)
Scale array.
Definition JArray.hh:427
const_reference at(int index) const
Get element at given index.
Definition JArray.hh:266
void fill(argument_type value)
Fill array.
Definition JArray.hh:350
JArray(const JArray< M, T > &array)
Copy constructor.
Definition JArray.hh:73
void assign(const JMultiKey< 1, const T > &key)
Termination method for setting array.
Definition JArray.hh:596
void assign(const JMultiKey< 1, T > &key, argument_type value)
Termination method for setting array.
Definition JArray.hh:638
JArray()
Default constructor.
Definition JArray.hh:61
JArray & mul(const double factor)
Scale array.
Definition JArray.hh:411
const T * const_pointer
Definition JArray.hh:46
const_pointer data() const
Get pointer to data.
Definition JArray.hh:295
JArray< N-1, T > pop_front() const
Make a copy in which the first element is removed.
Definition JArray.hh:328
bool equals(const JArray< N, T > &array) const
Check equality.
Definition JArray.hh:443
void __set__(const int i, const argument_type x, const Args &...args)
Recursive method for setting array.
Definition JArray.hh:535
const_reverse_iterator rend() const
get reverse iterator to begin of data
Definition JArray.hh:229
const_iterator begin() const
get iterator to begin of data
Definition JArray.hh:220
JArray(const JMultiKey< N, const T > &key)
Copy constructor.
Definition JArray.hh:122
const T * const_iterator
Definition JArray.hh:48
static size_type size()
Get size of data.
Definition JArray.hh:317
iterator begin()
get iterator to begin of data
Definition JArray.hh:224
unsigned int size_type
Definition JArray.hh:54
void assign(const JMultiKey< M, T > &key)
Recursive method for setting array.
Definition JArray.hh:558
JLANG::JClass< T >::argument_type argument_type
Definition JArray.hh:55
JArray & sub(const JArray &array)
Subtract array.
Definition JArray.hh:395
JArray(const JArray< N-1, T > &array, argument_type value)
Append constructor.
Definition JArray.hh:134
void assign(const JMultiKey< M, T > &key, argument_type value)
Recursive method for setting array.
Definition JArray.hh:609
iterator end()
get iterator to end of data
Definition JArray.hh:225
void __set__(const int i) const
Termination method for setting array.
Definition JArray.hh:548
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition JArray.hh:50
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition JArray.hh:228
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition JArray.hh:513
reverse_iterator rbegin()
get reverse iterator to begin of data
Definition JArray.hh:232
void assign(const JMultiKey< M, const T > &key, argument_type value)
Recursive method for setting array.
Definition JArray.hh:624
reference at(int index)
Get element at given index.
Definition JArray.hh:281
JArray(argument_type value, const Args &...args)
Initialise constructor.
Definition JArray.hh:187
reverse_iterator rend()
get reverse iterator to end of data
Definition JArray.hh:233
pointer data()
Get pointer to data.
Definition JArray.hh:306
void assign(const JMultiKey< M, const T > &key)
Recursive method for setting array.
Definition JArray.hh:572
friend JReader & operator>>(JReader &in, JArray &buffer)
Read array from input.
Definition JArray.hh:496
JArray(const JMultiKey< N-1, const T > &key, argument_type value)
Append constructor.
Definition JArray.hh:174
reference operator[](int index)
Get element at given index.
Definition JArray.hh:254
friend std::ostream & operator<<(std::ostream &out, const JArray &array)
Write array to output stream.
Definition JArray.hh:479
JArray(const JArray< N-1, const T > &array, argument_type value)
Append constructor.
Definition JArray.hh:148
JArray & set(const Args &...args)
Set array.
Definition JArray.hh:199
void assign(const JMultiKey< 1, T > &key)
Termination method for setting array.
Definition JArray.hh:585
std::reverse_iterator< iterator > reverse_iterator
Definition JArray.hh:51
Multidimensional key.
Definition JMultiKey.hh:69
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488