Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JArray.cc File Reference

Example program to test JTOOLS::JArray class. More...

#include <iostream>
#include <iomanip>
#include <iterator>
#include <cmath>
#include "JTools/JArray.hh"
#include "JTools/JMultiKey.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JTOOLS::JArray class.

Author
mdejong

Definition in file JArray.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 20 of file JArray.cc.

21{
22 using namespace std;
23 using namespace JPP;
24
25 int debug;
26
27 try {
28
29 JParser<> zap("Example program to test fixed length array class.");
30
31 zap['d'] = make_field(debug) = 3;
32
33 zap(argc, argv);
34 }
35 catch(const exception &error) {
36 FATAL(error.what() << endl);
37 }
38
39
40 {
41 //JArray<3, int> array(1, 2); // generates compiler error
42 //JArray<3, int> array(1, 2, 3, 4); // generates compiler error
43 //JArray<3, int> array(1, 2, "abc"); // generates compiler error
44 }
45
46 {
47 const int i0 = 1;
48
50
51 ASSERT(i0 == array[0]);
52 }
53
54 {
55 const int i0 = 1;
56 const int i1 = 2;
57
58 JArray<2, int> array(i0, i1);
59
60 ASSERT(i0 == array[0]);
61 ASSERT(i1 == array[1]);
62 }
63
64
65 {
66 const int N = 9;
67
68 typedef JArray<N, int> JArray1_t;
69 typedef JArray<N-1, int> JArray2_t;
70
71 JArray1_t array;
72
73 for (JArray1_t::iterator i = array.begin(); i != array.end(); ++i) {
74 *i = distance(array.begin(),i);
75 }
76
77 if (debug >= debug_t) {
78 cout << "input A ";
79 copy(array.begin(), array.end(), ostream_iterator<int>(cout, " "));
80 cout << endl;
81 }
82
83 {
84 JArray1_t buffer = array + array;
85
86 for (int i = 0; i != N; ++i) {
87 ASSERT(2*array[i] == buffer[i]);
88 }
89 }
90
91 {
92 JArray2_t buffer = array.pop_front();
93
94 if (debug >= debug_t) {
95 cout << "pop_front ";
96 copy(buffer.begin(), buffer.end(), ostream_iterator<int>(cout, " "));
97 cout << endl;
98 }
99
100 for (int i = 0; i != N-1; ++i) {
101 ASSERT(array[i+1] == buffer[i]);
102 }
103 }
104
105 {
106 JArray1_t buffer(array.pop_back(), array[N-1]);
107
108 ASSERT(array == buffer);
109 }
110
111 {
112 JArray2_t buffer = array.pop_back();
113
114 if (debug >= debug_t) {
115 cout << "pop_back ";
116 copy(buffer.begin(), buffer.end(), ostream_iterator<int>(cout, " "));
117 cout << endl;
118 }
119
120 for (int i = 0; i != N-1; ++i) {
121 ASSERT(array[i] == buffer[i]);
122 }
123 }
124 }
125
126 {
127 JArray<3, int> array(1, 2, 3);
128
130
131 if (debug >= debug_t) {
132 copy(p3.begin(), p3.end(), ostream_iterator<int>(cout, " "));
133 cout << endl;
134 }
135
136 ASSERT(array[0] == p3[0]);
137
138 JArray<2, const int> p2(p3.pop_front());
139
140 if (debug >= debug_t) {
141 copy(p2.begin(), p2.end(), ostream_iterator<int>(cout, " "));
142 cout << endl;
143 }
144
145 ASSERT(array[1] == p2[0]);
146
147 JArray<1, const int> p1(p2.pop_front());
148
149 if (debug >= debug_t) {
150 copy(p1.begin(), p1.end(), ostream_iterator<int>(cout, " "));
151 cout << endl;
152 }
153
154 ASSERT(array[2] == p1[0]);
155
156 //JArray<0, const int> p0(p1.pop_front()); // compile error, as should be
157 }
158
159 {
161
162 key.first = 0;
163 key.second.first = 1;
164
165 int i = 2;
166
167 JArray<3, int> array(key, i);
168
169 if (debug >= debug_t) {
170 copy(array.begin(), array.end(), ostream_iterator<int>(cout, " "));
171 cout << endl;
172 }
173
174 ASSERT(array[0] == key.first);
175 ASSERT(array[1] == key.second.first);
176 ASSERT(array[2] == i);
177
178 JMultiKey<3, int> ka(key, i);
180
181 ASSERT(ka == kb);
182 }
183
184 return 0;
185}
TPaveText * p1
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse command line options.
Definition JParser.hh:1698
One dimensional array of template objects with fixed length.
Definition JArray.hh:43
Multidimensional key.
Definition JMultiKey.hh:69
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).