gtsam/wrap/FileWriter.cpp

57 lines
1.2 KiB
C++

/**
* @file FileWriter.cpp
*
* @date Jan 15, 2012
* @author Alex Cunningham
*/
#include "FileWriter.h"
#include "utilities.h"
#include <boost/date_time/gregorian/gregorian.hpp>
#include <fstream>
using namespace std;
using namespace boost::gregorian;
using namespace wrap;
/* ************************************************************************* */
FileWriter::FileWriter(const string& filename, const string& comment_str)
: filename_(filename), comment_str_(comment_str)
{
}
/* ************************************************************************* */
void FileWriter::emit(bool add_header, bool force) const {
// Standard write - just overwrite for verification
ofstream ofs(filename_.c_str());
if (!ofs) throw CantOpenFile(filename_);
// header
if (add_header) {
date today = day_clock::local_day();
ofs << comment_str_ << " automatically generated by wrap on " << today << endl;
}
// dump in stringstream
ofs << oss.str();
ofs.close();
// TODO: add the following checks
// check for existing file
// if exists and we are not forcing writing, read and compare
// if different, write the file with contents of this stream
// add header
}
/* ************************************************************************* */