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