bugfix _keep_existing name ; added an overwriting option to use ios_base::trunc instead of ios_base::app
This commit is contained in:
parent
d8a1aedf01
commit
9d19cc2cfa
2 changed files with 16 additions and 6 deletions
|
|
@ -44,11 +44,16 @@ void eoFileMonitor::printHeader()
|
||||||
|
|
||||||
eoMonitor& eoFileMonitor::operator()(void)
|
eoMonitor& eoFileMonitor::operator()(void)
|
||||||
{
|
{
|
||||||
ofstream os(filename.c_str(), ios_base::app);
|
ofstream os(filename.c_str(),
|
||||||
|
overwrite ?
|
||||||
|
ios_base::out|ios_base::trunc // FIXME does not seems to work
|
||||||
|
:
|
||||||
|
ios_base::out|ios_base::app
|
||||||
|
);
|
||||||
|
|
||||||
if (!os)
|
if (!os)
|
||||||
{
|
{
|
||||||
string str = "eoFileMonitor: Could not append to " + filename;
|
string str = "eoFileMonitor: Could not write to " + filename;
|
||||||
throw runtime_error(str);
|
throw runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,21 +52,23 @@ public :
|
||||||
* @param _filename complete filename to write to
|
* @param _filename complete filename to write to
|
||||||
* @param _delim delimiter string to use between each item of the registered vector (e.g. of eoStats)
|
* @param _delim delimiter string to use between each item of the registered vector (e.g. of eoStats)
|
||||||
* @param _keep_existing if true, overwrite any existing file with the same name prior to any output
|
* @param _keep_existing if true, overwrite any existing file with the same name prior to any output
|
||||||
* @param _header print the header (with the descriptions of registered eoStats) at the beginning of the file
|
* @param _header print the header (with the descriptions of registered eoStats) at the beginning of the file (WARNING: true will discards header printing)
|
||||||
*/
|
*/
|
||||||
eoFileMonitor(
|
eoFileMonitor(
|
||||||
std::string _filename,
|
std::string _filename,
|
||||||
std::string _delim = " ",
|
std::string _delim = " ",
|
||||||
bool _keep_existing = false,
|
bool _keep_existing = false,
|
||||||
bool _header=false
|
bool _header = false,
|
||||||
|
bool _overwrite = false
|
||||||
)
|
)
|
||||||
: filename(_filename),
|
: filename(_filename),
|
||||||
delim(_delim),
|
delim(_delim),
|
||||||
keep(_keep_existing),
|
keep(_keep_existing),
|
||||||
header(_header),
|
header(_header),
|
||||||
firstcall(true)
|
firstcall(true),
|
||||||
|
overwrite(_overwrite)
|
||||||
{
|
{
|
||||||
if (!_keep) {
|
if (!_keep_existing) {
|
||||||
std::ofstream os (filename.c_str ());
|
std::ofstream os (filename.c_str ());
|
||||||
|
|
||||||
if (!os) {
|
if (!os) {
|
||||||
|
|
@ -108,6 +110,9 @@ private :
|
||||||
|
|
||||||
//! flag to avoid calling twice operator()(void)
|
//! flag to avoid calling twice operator()(void)
|
||||||
bool firstcall;
|
bool firstcall;
|
||||||
|
|
||||||
|
//! erase the entire file prior to writing in it (mode eos_base::
|
||||||
|
bool overwrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue