Line 1... |
Line 1... |
// $Id: Rtools.cpp 521 2013-05-20 22:16:45Z mueller $
|
// $Id: Rtools.cpp 606 2014-11-24 07:08:51Z mueller $
|
//
|
//
|
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2011-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
Line 11... |
Line 11... |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
|
// 2014-11-23 606 1.0.4 add TimeOfDayAsDouble()
|
|
// 2014-11-08 602 1.0.5 add (int) cast in snprintf to match %d type
|
|
// 2014-08-22 584 1.0.4 use nullptr
|
// 2013-05-04 516 1.0.3 add CreateBackupFile()
|
// 2013-05-04 516 1.0.3 add CreateBackupFile()
|
// 2013-02-13 481 1.0.2 remove Throw(Logic|Runtime)(); use Rexception
|
// 2013-02-13 481 1.0.2 remove Throw(Logic|Runtime)(); use Rexception
|
// 2011-04-10 376 1.0.1 add ThrowLogic(), ThrowRuntime()
|
// 2011-04-10 376 1.0.1 add ThrowLogic(), ThrowRuntime()
|
// 2011-03-12 368 1.0 Initial version
|
// 2011-03-12 368 1.0 Initial version
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: Rtools.cpp 521 2013-05-20 22:16:45Z mueller $
|
\version $Id: Rtools.cpp 606 2014-11-24 07:08:51Z mueller $
|
\brief Implemenation of Rtools .
|
\brief Implemenation of Rtools .
|
*/
|
*/
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
|
|
#include <iostream>
|
#include <iostream>
|
#include <vector>
|
#include <vector>
|
|
|
Line 52... |
Line 56... |
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
std::string Flags2String(uint32_t flags, const RflagName* fnam, char delim)
|
std::string Flags2String(uint32_t flags, const RflagName* fnam, char delim)
|
{
|
{
|
if (fnam == 0)
|
if (fnam == nullptr)
|
throw Rexception("Rtools::Flags2String()","Bad args: fnam==NULL");
|
throw Rexception("Rtools::Flags2String()","Bad args: fnam==nullptr");
|
|
|
string rval;
|
string rval;
|
while (fnam->mask) {
|
while (fnam->mask) {
|
if (flags & fnam->mask) {
|
if (flags & fnam->mask) {
|
if (!rval.empty()) rval += delim;
|
if (!rval.empty()) rval += delim;
|
Line 118... |
Line 122... |
|
|
vector<string> fnames;
|
vector<string> fnames;
|
fnames.push_back(fname);
|
fnames.push_back(fname);
|
for (size_t i=1; i<=nbackup; i++) {
|
for (size_t i=1; i<=nbackup; i++) {
|
char fnum[4];
|
char fnum[4];
|
snprintf(fnum, 4, "%d", i);
|
snprintf(fnum, 4, "%d", (int)i);
|
fnames.push_back(fbase + "_" + fnum + fext);
|
fnames.push_back(fbase + "_" + fnum + fext);
|
}
|
}
|
|
|
for (size_t i=nbackup; i>0; i--) {
|
for (size_t i=nbackup; i>0; i--) {
|
string fnam_new = fnames[i];
|
string fnam_new = fnames[i];
|
Line 168... |
Line 172... |
}
|
}
|
}
|
}
|
return true;
|
return true;
|
}
|
}
|
|
|
|
//------------------------------------------+-----------------------------------
|
|
//! Returns the time-of-day as \c double value
|
|
/*!
|
|
Calls \c gettimeofday() and returns the current time as a \c double.
|
|
This is convenient for calculations with time values.
|
|
|
|
\returns time is seconds as \a double with micro second resolution.
|
|
\throws Rexception in case \c gettimeofday() fails.
|
|
*/
|
|
|
|
double TimeOfDayAsDouble()
|
|
{
|
|
struct timeval tval;
|
|
int irc = ::gettimeofday(&tval, 0);
|
|
if (irc < 0) {
|
|
throw Rexception("Rtools::TimeOfDayAsDouble()",
|
|
"gettimeofday failed with ", errno);
|
|
}
|
|
|
|
return double(tval.tv_sec) + 1.e-6*double(tval.tv_usec);
|
|
}
|
|
|
} // end namespace Rtools
|
} // end namespace Rtools
|
} // end namespace Retro
|
} // end namespace Retro
|
|
|
No newline at end of file
|
No newline at end of file
|