#include #include #include #include #include #include "JLang/JSTDObjectWriter.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Check if two ranges are equal. * * \param __begin1 begin of first data set * \param __end1 end of first data set * \param __begin2 begin of second data set * \param __end2 end of second data set * \return true if two data sets are equals; else false */ template inline bool equals(U __begin1, U __end1, V __begin2, V __end2) { U p = __begin1; V q = __begin2; for ( ; p != __end1 && q != __end2; ++p, ++q) { if (*p != *q) { return false; } } return (p == __end1 && q == __end2); } template void print(std::ostream& out, int debug, const char* title, T __begin, T __end) { using namespace std; using namespace JPP; if (debug >= debug_t) { out << title << endl; copy(__begin, __end, ostream_iterator(out, " ")); out << endl; } } } /** * \file * * Example program to test JLANG::JSTDObjectWriter class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test object output using STD containers."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; vector data; data.push_back(3.0); data.push_back(2.0); data.push_back(1.0); print(cout, debug, "data", data.begin(), data.end()); { typedef vector buffer_type; buffer_type buffer; JSTDObjectWriter out(buffer); for (vector::const_iterator i = data.begin(); i != data.end(); ++i) { out.put(*i); } print(cout, debug, "JSTDObjectWriter(vector&);", buffer.begin(), buffer.end()); ASSERT(equals(data.begin(), data.end(), buffer.begin(), buffer.end())); } { typedef set buffer_type; buffer_type buffer; JSTDObjectWriter out(buffer); for (vector::const_iterator i = data.begin(); i != data.end(); ++i) { out.put(*i); } print(cout, debug, "JSTDObjectWriter(set&);", buffer.begin(), buffer.end()); ASSERT(equals(data.rbegin(), data.rend(), buffer.begin(), buffer.end())); } return 0; }