#include #include #include #include #include #include #include #include #include "JLang/JCSV.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Get element in buffer at given index. * * \param buffer buffer * \param index index * \return element */ template inline typename T::value_type get(const T& buffer, int index) { typename T::const_iterator p = buffer.begin(); advance(p, index); return *p; } } /** * \file * * Example program to test assignment of comma separated values (see JCSV.hh). * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test assignment of comma separated values."); zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } const int a = 7; const int b = 8; const int c = 9; const int d = 10; { vector buffer; assign(buffer) = a, b, c, d; ASSERT(get(buffer,0) == a); ASSERT(get(buffer,1) == b); ASSERT(get(buffer,2) == c); ASSERT(get(buffer,3) == d); } { set buffer; assign(buffer) = d, c, b, a; ASSERT(get(buffer,0) == a); ASSERT(get(buffer,1) == b); ASSERT(get(buffer,2) == c); ASSERT(get(buffer,3) == d); } { map buffer; assign(buffer) = make_pair(1,-1), make_pair(2,-2), make_pair(3,-3), make_pair(4,-4); ASSERT(buffer[1] == -1); ASSERT(buffer[2] == -2); ASSERT(buffer[3] == -3); ASSERT(buffer[4] == -4); } { deque buffer; assign(front_inserter(buffer)) = b, a; assign(back_inserter (buffer)) = c, d; ASSERT(get(buffer,0) == a); ASSERT(get(buffer,1) == b); ASSERT(get(buffer,2) == c); ASSERT(get(buffer,3) == d); } return 0; }