Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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 "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

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file JArray.cc.

20 {
21  using namespace std;
22  using namespace JPP;
23 
24  int debug;
25 
26  try {
27 
28  JParser<> zap("Example program to test fixed length array class.");
29 
30  zap['d'] = make_field(debug) = 3;
31 
32  zap(argc, argv);
33  }
34  catch(const exception &error) {
35  FATAL(error.what() << endl);
36  }
37 
38 
39  {
40  const int i0 = 1;
41 
42  JArray<1, int> array(i0);
43 
44  ASSERT(i0 == array[0]);
45  }
46 
47  {
48  const int i0 = 1;
49  const int i1 = 2;
50 
51  JArray<2, int> array(i0, i1);
52 
53  ASSERT(i0 == array[0]);
54  ASSERT(i1 == array[1]);
55  }
56 
57 
58  {
59  const int N = 9;
60 
61  typedef JArray<N, int> JArray1_t;
62  typedef JArray<N-1, int> JArray2_t;
63 
64  JArray1_t array;
65 
66  for (JArray1_t::iterator i = array.begin(); i != array.end(); ++i) {
67  *i = distance(array.begin(),i);
68  }
69 
70  if (debug >= debug_t) {
71  cout << "input A ";
72  copy(array.begin(), array.end(), ostream_iterator<int>(cout, " "));
73  cout << endl;
74  }
75 
76  {
77  JArray1_t buffer = array + array;
78 
79  for (int i = 0; i != N; ++i) {
80  ASSERT(2*array[i] == buffer[i]);
81  }
82  }
83 
84  {
85  JArray2_t buffer = array.pop_front();
86 
87  if (debug >= debug_t) {
88  cout << "pop_front ";
89  copy(buffer.begin(), buffer.end(), ostream_iterator<int>(cout, " "));
90  cout << endl;
91  }
92 
93  for (int i = 0; i != N-1; ++i) {
94  ASSERT(array[i+1] == buffer[i]);
95  }
96  }
97 
98  {
99  JArray1_t buffer(array.pop_back(), array[N-1]);
100 
101  ASSERT(array == buffer);
102  }
103 
104  {
105  JArray2_t buffer = array.pop_back();
106 
107  if (debug >= debug_t) {
108  cout << "pop_back ";
109  copy(buffer.begin(), buffer.end(), ostream_iterator<int>(cout, " "));
110  cout << endl;
111  }
112 
113  for (int i = 0; i != N-1; ++i) {
114  ASSERT(array[i] == buffer[i]);
115  }
116  }
117  }
118 
119  {
120  JArray<3, int> array(1, 2, 3);
121 
122  JArray<3, const int> p3(array);
123 
124  if (debug >= debug_t) {
125  copy(p3.begin(), p3.end(), ostream_iterator<int>(cout, " "));
126  cout << endl;
127  }
128 
129  ASSERT(array[0] == p3[0]);
130 
131  JArray<2, const int> p2(p3.pop_front());
132 
133  if (debug >= debug_t) {
134  copy(p2.begin(), p2.end(), ostream_iterator<int>(cout, " "));
135  cout << endl;
136  }
137 
138  ASSERT(array[1] == p2[0]);
139 
140  JArray<1, const int> p1(p2.pop_front());
141 
142  if (debug >= debug_t) {
143  copy(p1.begin(), p1.end(), ostream_iterator<int>(cout, " "));
144  cout << endl;
145  }
146 
147  ASSERT(array[2] == p1[0]);
148 
149  //JArray<0, const int> p0(p1.pop_front()); // compile error, as should be
150  }
151 
152  return 0;
153 }
Utility class to parse command line options.
Definition: JParser.hh:1410
debug
Definition: JMessage.hh:27
TPaveText * p1
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40