Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
9 #include "JIO/JSerialisable.hh"
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 
23 namespace JTOOLS {}
24 namespace JPP { using namespace JTOOLS; }
25 
26 namespace 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>
87  JArray(const JArray<M, const T>& array)
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  */
134  JArray(const JArray<N-1, T>& array, argument_type value)
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  const_iterator begin() const { return buffer; } //!< get iterator to begin of data
210  const_iterator end() const { return buffer + N; } //!< get iterator to end of data
211 
212 
213  iterator begin() { return buffer; } //!< get iterator to begin of data
214  iterator end() { return buffer + N; } //!< get iterator to end of data
215 
216 
217  const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
218  const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to begin of data
219 
220 
221  reverse_iterator rbegin() { return reverse_iterator(end()); } //!< get reverse iterator to begin of data
222  reverse_iterator rend() { return reverse_iterator(begin()); } //!< get reverse iterator to end of data
223 
224 
225  /**
226  * Get element at given index.
227  *
228  * \param index index
229  * \return element
230  */
231  const_reference operator[](int index) const
232  {
233  return buffer[index];
234  }
235 
236 
237  /**
238  * Get element at given index.
239  *
240  * \param index index
241  * \return element
242  */
244  {
245  return buffer[index];
246  }
247 
248 
249  /**
250  * Get element at given index.
251  *
252  * \param index index
253  * \return element at index
254  */
255  const_reference at(int index) const
256  {
257  if (index >= 0 && index < N)
258  return buffer[index];
259  else
260  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
261  }
262 
263 
264  /**
265  * Get element at given index.
266  *
267  * \param index index
268  * \return element at index
269  */
270  reference at(int index)
271  {
272  if (index >= 0 && index < N)
273  return buffer[index];
274  else
275  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
276  }
277 
278 
279  /**
280  * Get pointer to data.
281  *
282  * \return pointer to data
283  */
285  {
286  return buffer;
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 size of data.
303  *
304  * \return size of data
305  */
306  static size_type size()
307  {
308  return N;
309  }
310 
311 
312  /**
313  * Make a copy in which the first element is removed.
314  *
315  * \return array
316  */
317  JArray<N-1, T> pop_front() const
318  {
319  return JArray<N-1, T>(&buffer[1]);
320  }
321 
322 
323  /**
324  * Make a copy in which the last element is removed.
325  *
326  * \return array
327  */
328  JArray<N-1, T> pop_back() const
329  {
330  return JArray<N-1, T>(buffer);
331  }
332 
333 
334  /**
335  * Fill array.
336  *
337  * \param value value
338  */
339  void fill(argument_type value)
340  {
341  for (int i = 0; i != N; ++i) {
342  buffer[i] = value;
343  }
344  }
345 
346 
347  /**
348  * Negate array.
349  *
350  * \return this array
351  */
353  {
354  for (int i = 0; i != N; ++i) {
355  buffer[i] = -buffer[i];
356  }
357 
358  return *this;
359  }
360 
361 
362  /**
363  * Add array.
364  *
365  * \param array array
366  * \return this array
367  */
368  JArray& add(const JArray& array)
369  {
370  for (int i = 0; i != N; ++i) {
371  buffer[i] += array[i];
372  }
373 
374  return *this;
375  }
376 
377 
378  /**
379  * Subtract array.
380  *
381  * \param array array
382  * \return this array
383  */
384  JArray& sub(const JArray& array)
385  {
386  for (int i = 0; i != N; ++i) {
387  buffer[i] -= array[i];
388  }
389 
390  return *this;
391  }
392 
393 
394  /**
395  * Scale array.
396  *
397  * \param factor multiplication factor
398  * \return this array
399  */
400  JArray& mul(const double factor)
401  {
402  for (int i = 0; i != N; ++i) {
403  buffer[i] *= factor;
404  }
405 
406  return *this;
407  }
408 
409 
410  /**
411  * Scale array.
412  *
413  * \param factor division factor
414  * \return this array
415  */
416  JArray& div(const double factor)
417  {
418  for (int i = 0; i != N; ++i) {
419  buffer[i] /= factor;
420  }
421 
422  return *this;
423  }
424 
425 
426  /**
427  * Check equality.
428  *
429  * \param array array
430  * \return true if arrays are equal; else false
431  */
432  bool equals(const JArray<N, T>& array) const
433  {
434  for (int i = 0; i != N; ++i) {
435  if (buffer[i] != array[i]) {
436  return false;
437  }
438  }
439 
440  return true;
441  }
442 
443 
444  /**
445  * Read array from input stream.
446  *
447  * \param in input stream
448  * \param array array
449  * \return input stream
450  */
451  friend inline std::istream& operator>>(std::istream& in, JArray& array)
452  {
453  for (iterator i = array.begin(); i != array.end(); ++i) {
454  in >> *i;
455  }
456 
457  return in;
458  }
459 
460 
461  /**
462  * Write array to output stream.
463  *
464  * \param out output stream
465  * \param array array
466  * \return output stream
467  */
468  friend inline std::ostream& operator<<(std::ostream& out, const JArray& array)
469  {
470  for (const_iterator i = array.begin(); i != array.end(); ++i) {
471  out << ' ' << SCIENTIFIC(12,5) << *i;
472  }
473 
474  return out;
475  }
476 
477 
478  /**
479  * Read array from input.
480  *
481  * \param in reader
482  * \param buffer array
483  * \return reader
484  */
486  {
487  for (iterator i = buffer.begin(); i != buffer.end(); ++i) {
488  in >> *i;
489  }
490 
491  return in;
492  }
493 
494 
495  /**
496  * Write array to output.
497  *
498  * \param out writer
499  * \param buffer array
500  * \return writer
501  */
502  friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
503  {
504  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
505  out << *i;
506  }
507 
508  return out;
509  }
510 
511  protected:
512 
514 
515 
516  /**
517  * Recursive method for setting array.
518  *
519  * \param i index
520  * \param x value at given index
521  * \param args remaining values
522  */
523  template<class ...Args>
524  void __set__(const int i, const argument_type x, const Args& ...args)
525  {
526  this->buffer[i] = x;
527 
528  __set__(i + 1, args...);
529  }
530 
531 
532  /**
533  * Termination method for setting array.
534  *
535  * \param i index
536  */
537  void __set__(const int i) const
538  {}
539 
540 
541  /**
542  * Recursive method for setting array.
543  *
544  * \param key multi-dimensional key
545  */
546  template<unsigned int M>
547  void assign(const JMultiKey<M, T>& key)
548  {
549  buffer[N-M] = key.first;
550 
551  assign(key.second);
552  }
553 
554 
555  /**
556  * Recursive method for setting array.
557  *
558  * \param key multi-dimensional key
559  */
560  template<unsigned int M>
561  void assign(const JMultiKey<M, const T>& key)
562  {
563  buffer[N-M] = key.first;
564 
565  assign(key.second);
566  }
567 
568 
569  /**
570  * Termination method for setting array.
571  *
572  * \param key one-dimensional key
573  */
574  void assign(const JMultiKey<1, T>& key)
575  {
576  buffer[N-1] = key.first;
577  }
578 
579 
580  /**
581  * Termination method for setting array.
582  *
583  * \param key one-dimensional key
584  */
585  void assign(const JMultiKey<1, const T>& key)
586  {
587  buffer[N-1] = key.first;
588  }
589 
590 
591  /**
592  * Recursive method for setting array.
593  *
594  * \param key multi-dimensional key
595  * \param value value
596  */
597  template<unsigned int M>
598  void assign(const JMultiKey<M, T>& key, argument_type value)
599  {
600  buffer[N-M-1] = key.first;
601 
602  assign(key.second, value);
603  }
604 
605 
606  /**
607  * Recursive method for setting array.
608  *
609  * \param key multi-dimensional key
610  * \param value value
611  */
612  template<unsigned int M>
614  {
615  buffer[N-M-1] = key.first;
616 
617  assign(key.second, value);
618  }
619 
620 
621  /**
622  * Termination method for setting array.
623  *
624  * \param key one-dimensional key
625  * \param value value
626  */
627  void assign(const JMultiKey<1, T>& key, argument_type value)
628  {
629  buffer[N-2] = key.first;
630  buffer[N-1] = value;
631  }
632 
633 
634  /**
635  * Termination method for setting array.
636  *
637  * \param key one-dimensional key
638  * \param value value
639  */
641  {
642  buffer[N-2] = key.first;
643  buffer[N-1] = value;
644  }
645  };
646 
647 
648  /**
649  * One dimensional array of template objects with fixed length.
650  * The internal data structure consists of a standard C-array.
651  */
652  template<class T>
653  class JArray<1, T> :
654  public JMath < JArray<1,T> >,
655  public JEquals< JArray<1,T> >
656  {
657  public:
658 
659  static const unsigned int N = 1;
660 
661  typedef const T* const_pointer;
662  typedef T* pointer;
663  typedef const T* const_iterator;
664  typedef T* iterator;
665  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
666  typedef std::reverse_iterator<iterator> reverse_iterator;
667  typedef T& reference;
668  typedef const T& const_reference;
669  typedef unsigned int size_type;
671 
672 
673  /**
674  * Default constructor.
675  */
677  {
678  fill(T());
679  }
680 
681 
682  /**
683  * Copy constructor.
684  *
685  * \param array array
686  */
687  template<unsigned int M>
688  JArray(const JArray<M, T>& array)
689  {
690  buffer[0] = array[0];
691  }
692 
693 
694  /**
695  * Copy constructor.
696  *
697  * \param array array
698  */
699  template<unsigned int M>
701  {
702  buffer[0] = array[0];
703  }
704 
705 
706  /**
707  * Copy constructor.
708  *
709  * \param p pointer to data
710  */
711  JArray(const T* p)
712  {
713  buffer[0] = p[0];
714  }
715 
716 
717  /**
718  * Copy constructor.
719  *
720  * \param key multi-dimensional key
721  */
723  {
724  buffer[0] = key.first;
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  * Initialise constructor.
741  *
742  * \param value value;
743  */
745  {
746  buffer[0] = value;
747  }
748 
749 
750  const_iterator begin() const { return buffer; } //!< get iterator to begin of data
751  const_iterator end() const { return buffer + N; } //!< get iterator to end of data
752 
753 
754  iterator begin() { return buffer; } //!< get iterator to begin of data
755  iterator end() { return buffer + N; } //!< get iterator to end of data
756 
757 
758  const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
759  const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to begin of data
760 
761 
762  reverse_iterator rbegin() { return reverse_iterator(end()); } //!< get reverse iterator to begin of data
763  reverse_iterator rend() { return reverse_iterator(begin()); } //!< get reverse iterator to end of data
764 
765 
766  /**
767  * Get element at given index.
768  *
769  * \param index index
770  * \return element
771  */
772  const_reference operator[](int index) const
773  {
774  return buffer[index];
775  }
776 
777 
778  /**
779  * Get element at given index.
780  *
781  * \param index index
782  * \return element
783  */
785  {
786  return buffer[index];
787  }
788 
789 
790  /**
791  * Get element at given index.
792  *
793  * \param index index
794  * \return element at index
795  */
796  const_reference at(int index) const
797  {
798  if (index == 0)
799  return buffer[index];
800  else
801  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
802  }
803 
804 
805  /**
806  * Get element at given index.
807  *
808  * \param index index
809  * \return element at index
810  */
811  reference at(int index)
812  {
813  if (index == 0)
814  return buffer[index];
815  else
816  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
817  }
818 
819 
820  /**
821  * Get pointer to data.
822  *
823  * \return pointer to data
824  */
826  {
827  return buffer;
828  }
829 
830 
831  /**
832  * Get pointer to data.
833  *
834  * \return pointer to data
835  */
837  {
838  return buffer;
839  }
840 
841 
842  /**
843  * Get size of data.
844  *
845  * \return size of data
846  */
847  static size_type size()
848  {
849  return N;
850  }
851 
852 
853  /**
854  * Fill array.
855  *
856  * \param value value
857  */
858  void fill(argument_type value)
859  {
860  buffer[0] = value;
861  }
862 
863 
864  /**
865  * Negate array.
866  *
867  * \return this array
868  */
870  {
871  buffer[0] = -buffer[0];
872 
873  return *this;
874  }
875 
876 
877  /**
878  * Add array.
879  *
880  * \param array array
881  * \return this array
882  */
883  JArray& add(const JArray& array)
884  {
885  buffer[0] += array[0];
886 
887  return *this;
888  }
889 
890 
891  /**
892  * Subtract array.
893  *
894  * \param array array
895  * \return this array
896  */
897  JArray& sub(const JArray& array)
898  {
899  buffer[0] -= array[0];
900 
901  return *this;
902  }
903 
904 
905  /**
906  * Scale array.
907  *
908  * \param factor multiplication factor
909  * \return this array
910  */
911  JArray& mul(const double factor)
912  {
913  buffer[0] *= factor;
914 
915  return *this;
916  }
917 
918 
919  /**
920  * Scale array.
921  *
922  * \param factor division factor
923  * \return this array
924  */
925  JArray& div(const double factor)
926  {
927  buffer[0] /= factor;
928 
929  return *this;
930  }
931 
932 
933  /**
934  * Check equality.
935  *
936  * \param array array
937  * \return true if arrays are equal; else false
938  */
939  bool equals(const JArray<N, T>& array) const
940  {
941  return buffer[0] == array[0];
942  }
943 
944 
945  /**
946  * Read array from input stream.
947  *
948  * \param in input stream
949  * \param array array
950  * \return input stream
951  */
952  friend inline std::istream& operator>>(std::istream& in, JArray& array)
953  {
954  for (iterator i = array.begin(); i != array.end(); ++i) {
955  in >> *i;
956  }
957 
958  return in;
959  }
960 
961 
962  /**
963  * Write array to output stream.
964  *
965  * \param out output stream
966  * \param array array
967  * \return output stream
968  */
969  friend inline std::ostream& operator<<(std::ostream& out, const JArray& array)
970  {
971  for (const_iterator i = array.begin(); i != array.end(); ++i) {
972  out << ' ' << SCIENTIFIC(12,5) << *i;
973  }
974 
975  return out;
976  }
977 
978 
979  /**
980  * Read array from input.
981  *
982  * \param in reader
983  * \param buffer array
984  * \return reader
985  */
987  {
988  return in >> buffer[0];
989  }
990 
991 
992  /**
993  * Write array to output.
994  *
995  * \param out writer
996  * \param buffer array
997  * \return writer
998  */
999  friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1000  {
1001  return out << buffer[0];
1002  }
1003 
1004  protected:
1005  T buffer[1];
1006  };
1007 
1008 
1009  /**
1010  * One dimensional read-only array of template objects with fixed length.
1011  * The internal data structure consists of a simple C-pointer to the actual data.
1012  * The user should ensure that the data are persistent.
1013  */
1014  template<unsigned int N, class T>
1015  class JArray<N, const T> {
1016  public:
1017 
1018  friend class JArray<N + 1, const T>;
1019 
1020  typedef const T* const_pointer;
1021  typedef const T* const_iterator;
1022  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1023  typedef const T& const_reference;
1024  typedef unsigned int size_type;
1025 
1026 
1027  /**
1028  * Copy constructor.
1029  *
1030  * \param array array
1031  */
1032  template<unsigned int M>
1033  JArray(const JArray<M, T>& array) :
1034  p(array.data())
1035  {
1036  STATIC_CHECK(M >= N);
1037  }
1038 
1039 
1040  /**
1041  * Copy constructor.
1042  *
1043  * \param array array
1044  */
1045  template<unsigned int M>
1046  JArray(const JArray<M, const T>& array) :
1047  p(array.data())
1048  {
1049  STATIC_CHECK(M >= N);
1050  }
1051 
1052 
1053  const_iterator begin() const { return p; } //!< get iterator to begin of data
1054  const_iterator end() const { return p + N; } //!< get iterator to end of data
1055 
1056 
1057  const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
1058  const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to end of data
1059 
1060 
1061  /**
1062  * Get element at given index.
1063  *
1064  * \param index index
1065  * \return element at index
1066  */
1067  const_reference operator[](int index) const
1068  {
1069  return p[index];
1070  }
1071 
1072 
1073  /**
1074  * Get element at given index.
1075  *
1076  * \param index index
1077  * \return element at index
1078  */
1079  const_reference at(int index) const
1080  {
1081  if (index >= 0 && index < N)
1082  return p[index];
1083  else
1084  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
1085  }
1086 
1087 
1088  /**
1089  * Get pointer to data.
1090  *
1091  * \return pointer to data
1092  */
1094  {
1095  return p;
1096  }
1097 
1098 
1099  /**
1100  * Get size of data.
1101  *
1102  * \return size of data
1103  */
1104  static size_type size()
1105  {
1106  return N;
1107  }
1108 
1109 
1110  /**
1111  * Make a copy in which the first element is removed.
1112  *
1113  * \return array
1114  */
1115  JArray<N-1, const T> pop_front() const
1116  {
1117  return JArray<N-1, const T>(p + 1);
1118  }
1119 
1120 
1121  /**
1122  * Make a copy in which the last element is removed.
1123  *
1124  * \return array
1125  */
1126  JArray<N-1, const T> pop_back() const
1127  {
1128  return JArray<N-1, const T>(p);
1129  }
1130 
1131 
1132  /**
1133  * Write array to output.
1134  *
1135  * \param out writer
1136  * \param buffer array
1137  * \return writer
1138  */
1139  friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1140  {
1141  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
1142  out << *i;
1143  }
1144 
1145  return out;
1146  }
1147 
1148  protected:
1149 
1151 
1152  /**
1153  * Constructor.
1154  *
1155  * \param __p pointer to data
1156  */
1157  JArray(const T* __p) :
1158  p(__p)
1159  {}
1160  };
1161 
1162 
1163  /**
1164  * One dimensional read-only array of template objects with fixed length.
1165  * The internal data structure consists of a simple C-pointer to the actual data.
1166  * The user should ensure that the data are persistent.
1167  */
1168  template<class T>
1169  class JArray<1, const T> {
1170  public:
1171 
1172  static const unsigned int N = 1;
1173 
1174  friend class JArray<N + 1, const T>;
1175 
1176  typedef const T* const_pointer;
1177  typedef const T* const_iterator;
1178  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1179  typedef const T& const_reference;
1180  typedef unsigned int size_type;
1181 
1182 
1183  /**
1184  * Copy constructor.
1185  *
1186  * \param array array
1187  */
1188  template<unsigned int M>
1189  JArray(const JArray<M, T>& array) :
1190  p(array.data())
1191  {
1192  STATIC_CHECK(M >= N);
1193  }
1194 
1195 
1196  /**
1197  * Copy constructor.
1198  *
1199  * \param array array
1200  */
1201  template<unsigned int M>
1202  JArray(const JArray<M, const T>& array) :
1203  p(array.data())
1204  {
1205  STATIC_CHECK(M >= N);
1206  }
1207 
1208 
1209  const_iterator begin() const { return p; } //!< get iterator to begin of data
1210  const_iterator end() const { return p + N; } //!< get iterator to end of data
1211 
1212 
1213  const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } //!< get reverse iterator to begin of data
1214  const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //!< get reverse iterator to end of data
1215 
1216 
1217  /**
1218  * Get element at given index.
1219  *
1220  * \param index index
1221  * \return element at index
1222  */
1223  const_reference operator[](int index) const
1224  {
1225  return p[index];
1226  }
1227 
1228 
1229  /**
1230  * Get element at given index.
1231  *
1232  * \param index index
1233  * \return element at index
1234  */
1235  const_reference at(int index) const
1236  {
1237  if (index >= 0 && index < N)
1238  return p[index];
1239  else
1240  THROW(JIndexOutOfRange, "invalid index " << 0 << " <= " << index << " < " << N);
1241  }
1242 
1243 
1244  /**
1245  * Get pointer to data.
1246  *
1247  * \return pointer to data
1248  */
1250  {
1251  return p;
1252  }
1253 
1254 
1255  /**
1256  * Get size of data.
1257  *
1258  * \return size of data
1259  */
1260  static size_type size()
1261  {
1262  return N;
1263  }
1264 
1265 
1266  /**
1267  * Write array to output.
1268  *
1269  * \param out writer
1270  * \param buffer array
1271  * \return writer
1272  */
1273  friend inline JWriter& operator<<(JWriter& out, const JArray& buffer)
1274  {
1275  return out << buffer[0];
1276  }
1277 
1278  protected:
1279 
1281 
1282  /**
1283  * Constructor.
1284  *
1285  * \param __p pointer to data
1286  */
1287  JArray(const T* __p) :
1288  p(__p)
1289  {}
1290  };
1291 }
1292 
1293 #endif
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition: JArray.hh:1057
JArray & sub(const JArray &array)
Subtract array.
Definition: JArray.hh:897
const T * const_iterator
Definition: JArray.hh:663
const T * const_pointer
Definition: JArray.hh:46
friend std::istream & operator>>(std::istream &in, JArray &array)
Read array from input stream.
Definition: JArray.hh:952
const_reverse_iterator rend() const
get reverse iterator to begin of data
Definition: JArray.hh:218
Exceptions.
JArray(const T *__p)
Constructor.
Definition: JArray.hh:1287
Interface for binary output.
JArray(const JMultiKey< N-1, T > &key, argument_type value)
Append constructor.
Definition: JArray.hh:162
friend std::ostream & operator<<(std::ostream &out, const JArray &array)
Write array to output stream.
Definition: JArray.hh:468
JArray & div(const double factor)
Scale array.
Definition: JArray.hh:416
JArray & div(const double factor)
Scale array.
Definition: JArray.hh:925
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:109
JArray(const JArray< N-1, T > &array, argument_type value)
Append constructor.
Definition: JArray.hh:134
static size_type size()
Get size of data.
Definition: JArray.hh:1260
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition: JArray.hh:1202
static size_type size()
Get size of data.
Definition: JArray.hh:306
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition: JArray.hh:502
void __set__(const int i, const argument_type x, const Args &...args)
Recursive method for setting array.
Definition: JArray.hh:524
friend std::istream & operator>>(std::istream &in, JArray &array)
Read array from input stream.
Definition: JArray.hh:451
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:209
const_reference operator[](int index) const
Get element at given index.
Definition: JArray.hh:231
reference at(int index)
Get element at given index.
Definition: JArray.hh:270
pointer data()
Get pointer to data.
Definition: JArray.hh:295
const_reverse_iterator rend() const
get reverse iterator to end of data
Definition: JArray.hh:1058
friend JReader & operator>>(JReader &in, JArray &buffer)
Read array from input.
Definition: JArray.hh:485
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:1249
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
reference operator[](int index)
Get element at given index.
Definition: JArray.hh:243
void assign(const JMultiKey< M, T > &key, argument_type value)
Recursive method for setting array.
Definition: JArray.hh:598
pointer data()
Get pointer to data.
Definition: JArray.hh:836
T & reference
Definition: JArray.hh:52
void assign(const JMultiKey< 1, T > &key, argument_type value)
Termination method for setting array.
Definition: JArray.hh:627
reference at(int index)
Get element at given index.
Definition: JArray.hh:811
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
JArray & mul(const double factor)
Scale array.
Definition: JArray.hh:400
const_reverse_iterator rend() const
get reverse iterator to end of data
Definition: JArray.hh:1214
JArray< N-1, T > pop_front() const
Make a copy in which the first element is removed.
Definition: JArray.hh:317
JArray & add(const JArray &array)
Add array.
Definition: JArray.hh:368
void fill(argument_type value)
Fill array.
Definition: JArray.hh:339
iterator begin()
get iterator to begin of data
Definition: JArray.hh:213
friend JReader & operator>>(JReader &in, JArray &buffer)
Read array from input.
Definition: JArray.hh:986
JLANG::JClass< T >::argument_type argument_type
Definition: JArray.hh:670
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition: JArray.hh:1213
JArray & set(const Args &...args)
Set array.
Definition: JArray.hh:199
JArray & negate()
Negate array.
Definition: JArray.hh:869
JArray & sub(const JArray &array)
Subtract array.
Definition: JArray.hh:384
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: JArray.hh:1178
JArray()
Default constructor.
Definition: JArray.hh:61
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition: JArray.hh:1139
JArray(const JArray< M, T > &array)
Copy constructor.
Definition: JArray.hh:73
friend std::ostream & operator<<(std::ostream &out, const JArray &array)
Write array to output stream.
Definition: JArray.hh:969
const_reference operator[](int index) const
Get element at given index.
Definition: JArray.hh:1223
iterator begin()
get iterator to begin of data
Definition: JArray.hh:754
Multidimensional key.
Definition: JMultiKey.hh:34
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:1093
const T * const_pointer
Definition: JArray.hh:661
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JArray & negate()
Negate array.
Definition: JArray.hh:352
void assign(const JMultiKey< 1, T > &key)
Termination method for setting array.
Definition: JArray.hh:574
const_reference at(int index) const
Get element at given index.
Definition: JArray.hh:1079
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:1209
void assign(const JMultiKey< 1, const T > &key)
Termination method for setting array.
Definition: JArray.hh:585
const_reference at(int index) const
Get element at given index.
Definition: JArray.hh:1235
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:750
void assign(const JMultiKey< 1, const T > &key, argument_type value)
Termination method for setting array.
Definition: JArray.hh:640
reference operator[](int index)
Get element at given index.
Definition: JArray.hh:784
iterator end()
get iterator to end of data
Definition: JArray.hh:755
JArray(const T *__p)
Constructor.
Definition: JArray.hh:1157
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:1054
void fill(argument_type value)
Fill array.
Definition: JArray.hh:858
JArray & add(const JArray &array)
Add array.
Definition: JArray.hh:883
do set_variable OUTPUT_DIRECTORY $WORKDIR T
const_reference operator[](int index) const
Get element at given index.
Definition: JArray.hh:1067
static size_type size()
Get size of data.
Definition: JArray.hh:1104
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:751
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
std::reverse_iterator< iterator > reverse_iterator
Definition: JArray.hh:51
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition: JArray.hh:1273
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:210
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition: JArray.hh:1046
unsigned int size_type
Definition: JArray.hh:669
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: JArray.hh:1022
JArray(const JMultiKey< N, const T > &key)
Copy constructor.
Definition: JArray.hh:122
void assign(const JMultiKey< M, const T > &key, argument_type value)
Recursive method for setting array.
Definition: JArray.hh:613
void __set__(const int i) const
Termination method for setting array.
Definition: JArray.hh:537
Interface for binary input.
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:1053
JArray< N-1, T > pop_back() const
Make a copy in which the last element is removed.
Definition: JArray.hh:328
One dimensional array of template objects with fixed length.
Definition: JArray.hh:40
reverse_iterator rend()
get reverse iterator to end of data
Definition: JArray.hh:222
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: JArray.hh:50
I/O manipulators.
const_reference at(int index) const
Get element at given index.
Definition: JArray.hh:796
const_reference at(int index) const
Get element at given index.
Definition: JArray.hh:255
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition: JArray.hh:87
JArray()
Default constructor.
Definition: JArray.hh:676
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:1210
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition: JArray.hh:758
const_reference operator[](int index) const
Get element at given index.
Definition: JArray.hh:772
JArray(const JArray< M, T > &array)
Copy constructor.
Definition: JArray.hh:1033
JArray(argument_type value)
Initialise constructor.
Definition: JArray.hh:744
JArray(const JMultiKey< 1, const T > &key)
Copy constructor.
Definition: JArray.hh:733
unsigned int size_type
Definition: JArray.hh:54
const_reverse_iterator rbegin() const
get reverse iterator to begin of data
Definition: JArray.hh:217
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: JArray.hh:665
#define STATIC_CHECK(expr)
Definition: JAssert.hh:31
JArray(const JArray< M, T > &array)
Copy constructor.
Definition: JArray.hh:688
JArray(const T *p)
Copy constructor.
Definition: JArray.hh:711
JArray< N-1, const T > pop_back() const
Make a copy in which the last element is removed.
Definition: JArray.hh:1126
JArray(const T *p)
Copy constructor.
Definition: JArray.hh:100
T * iterator
Definition: JArray.hh:49
JArray(const JArray< M, T > &array)
Copy constructor.
Definition: JArray.hh:1189
bool equals(const JArray< N, T > &array) const
Check equality.
Definition: JArray.hh:432
void assign(const JMultiKey< M, T > &key)
Recursive method for setting array.
Definition: JArray.hh:547
reverse_iterator rend()
get reverse iterator to end of data
Definition: JArray.hh:763
JArray & mul(const double factor)
Scale array.
Definition: JArray.hh:911
JLANG::JClass< T >::argument_type argument_type
Definition: JArray.hh:55
JArray< N-1, const T > pop_front() const
Make a copy in which the first element is removed.
Definition: JArray.hh:1115
Base class for data structures with artithmetic capabilities.
const T & const_reference
Definition: JArray.hh:668
bool equals(const JArray< N, T > &array) const
Check equality.
Definition: JArray.hh:939
const T & const_reference
Definition: JArray.hh:53
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:825
JArray(const JMultiKey< N, T > &key)
Copy constructor.
Definition: JArray.hh:111
static size_type size()
Get size of data.
Definition: JArray.hh:847
JArray(const JArray< M, const T > &array)
Copy constructor.
Definition: JArray.hh:700
iterator end()
get iterator to end of data
Definition: JArray.hh:214
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
reverse_iterator rbegin()
get reverse iterator to begin of data
Definition: JArray.hh:221
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
void assign(const JMultiKey< M, const T > &key)
Recursive method for setting array.
Definition: JArray.hh:561
JArray(const JMultiKey< N-1, const T > &key, argument_type value)
Append constructor.
Definition: JArray.hh:174
JArray(const JMultiKey< 1, T > &key)
Copy constructor.
Definition: JArray.hh:722
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:284
reverse_iterator rbegin()
get reverse iterator to begin of data
Definition: JArray.hh:762
const T * const_iterator
Definition: JArray.hh:48
const_reverse_iterator rend() const
get reverse iterator to begin of data
Definition: JArray.hh:759
std::reverse_iterator< iterator > reverse_iterator
Definition: JArray.hh:666
JArray(const JArray< N-1, const T > &array, argument_type value)
Append constructor.
Definition: JArray.hh:148
friend JWriter & operator<<(JWriter &out, const JArray &buffer)
Write array to output.
Definition: JArray.hh:999
JArray(argument_type value, const Args &...args)
Initialise constructor.
Definition: JArray.hh:187