Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JCSV.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <deque>
6#include <set>
7#include <map>
8#include <iterator>
9#include <algorithm>
10
11#include "JLang/JCSV.hh"
12#include "Jeep/JParser.hh"
13#include "Jeep/JMessage.hh"
14
15namespace {
16
17 /**
18 * Get element in buffer at given index.
19 *
20 * \param buffer buffer
21 * \param index index
22 * \return element
23 */
24 template<class T>
25 inline typename T::value_type get(const T& buffer, int index)
26 {
27 typename T::const_iterator p = buffer.begin();
28
29 advance(p, index);
30
31 return *p;
32 }
33}
34
35
36/**
37 * \file
38 *
39 * Example program to test assignment of comma separated values (see JCSV.hh).
40 * \author mdejong
41 */
42int main(int argc, char **argv)
43{
44 using namespace std;
45 using namespace JPP;
46
47 int debug;
48
49 try {
50
51 JParser<> zap("Example program to test assignment of comma separated values.");
52
53 zap['d'] = make_field(debug) = 0;
54
55 zap(argc, argv);
56 }
57 catch(const exception &error) {
58 FATAL(error.what() << endl);
59 }
60
61 const int a = 7;
62 const int b = 8;
63 const int c = 9;
64 const int d = 10;
65
66 {
67 vector<int> buffer;
68
69 assign(buffer) = a, b, c, d;
70
71 ASSERT(get(buffer,0) == a);
72 ASSERT(get(buffer,1) == b);
73 ASSERT(get(buffer,2) == c);
74 ASSERT(get(buffer,3) == d);
75 }
76
77 {
78 set<int> buffer;
79
80 assign(buffer) = d, c, b, a;
81
82 ASSERT(get(buffer,0) == a);
83 ASSERT(get(buffer,1) == b);
84 ASSERT(get(buffer,2) == c);
85 ASSERT(get(buffer,3) == d);
86 }
87
88 {
89 map<int, int> buffer;
90
91 assign(buffer) = make_pair(1,-1), make_pair(2,-2), make_pair(3,-3), make_pair(4,-4);
92
93 ASSERT(buffer[1] == -1);
94 ASSERT(buffer[2] == -2);
95 ASSERT(buffer[3] == -3);
96 ASSERT(buffer[4] == -4);
97 }
98
99 {
100 deque<int> buffer;
101
102 assign(front_inserter(buffer)) = b, a;
103 assign(back_inserter (buffer)) = c, d;
104
105 ASSERT(get(buffer,0) == a);
106 ASSERT(get(buffer,1) == b);
107 ASSERT(get(buffer,2) == c);
108 ASSERT(get(buffer,3) == d);
109 }
110
111 return 0;
112}
int main(int argc, char **argv)
Definition JCSV.cc:42
Utility method to assign multiple values to STD container.
General purpose messaging.
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.