#include #include #include #include #include #include #include #include #include #include "JLang/JFileStream.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test JLANG::JFileStream class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string file_name = "test_file.txt"; int debug; try { JParser<> zap("Example program to test file streaming."); zap['f'] = make_field(file_name) = "test_file.txt"; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } vector data_in; data_in.push_back("hello"); data_in.push_back("world"); { int fd = open(file_name.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); ASSERT(fd != -1); JFileOutputStream os(fd); for (vector::const_iterator i = data_in.begin(); i != data_in.end(); ++i) { os << *i << endl; } close(fd); } vector data_out; { int fd = open(file_name.c_str(), O_RDWR); ASSERT(fd != -1); JFileInputStream is(fd); for (string buffer; getline(is,buffer); ) { data_out.push_back(buffer); } close(fd); } if (debug >= debug_t) { cout << "data_in "; copy(data_in .begin(), data_in .end(), ostream_iterator(cout, " ")); cout << endl; cout << "data_out "; copy(data_out.begin(), data_out.end(), ostream_iterator(cout, " ")); cout << endl; } ASSERT(data_in == data_out); return 0; }