Encapsulated representation of simulation time. More...
#include <Util/SimTime.H>
Public Member Functions | |
SimTime () | |
Default constructor; initialize to time=0. | |
std::string | toString (bool with_suffix=false) const |
Convert to string. | |
double | secs () const |
Return the number of seconds represented. | |
double | msecs () const |
Return the number of milliseconds represented. | |
double | usecs () const |
Return the number of microseconds represented. | |
int64 | nsecs () const |
Return the number of nanoseconds represented. | |
double | hertz () const |
Return the rate (inverse seconds) represented. | |
bool | nonzero () const |
Return true if the time represented is non-zero. | |
SimTime & | operator+= (const SimTime &step) |
Plus-equals. | |
SimTime | operator+ (const SimTime &that) const |
result=time1+time2 | |
SimTime | operator- (const SimTime &that) const |
result=time1-time2 | |
SimTime | operator* (const double x) const |
result=time*factor | |
SimTime | operator* (const int x) const |
result=time*factor | |
SimTime | operator* (const int64 x) const |
result=time*factor | |
bool | operator< (const SimTime &that) const |
compare time1<time2 | |
bool | operator<= (const SimTime &that) const |
compare time1<=time2 | |
bool | operator> (const SimTime &that) const |
compare time1>time2 | |
bool | operator>= (const SimTime &that) const |
compare time1>=time2 | |
bool | operator== (const SimTime &that) const |
compare time1==time2 | |
bool | operator!= (const SimTime &that) const |
compare time1!=time2 | |
Static Public Member Functions | |
static SimTime | ZERO () |
Pseudo-constructor; returns time=0. | |
static SimTime | MAX () |
Pseudo-constructor; builds the largest representable time. | |
static SimTime | SECS (double s) |
Pseudo-constructor; returns time=s seconds. | |
static SimTime | MSECS (double ms) |
Pseudo-constructor; returns time=ms milliseconds. | |
static SimTime | USECS (double us) |
Pseudo-constructor; returns time=us microseconds. | |
static SimTime | NSECS (int64 ns) |
Pseudo-constructor; returns time=ns nanoseconds. | |
static SimTime | HERTZ (double hz) |
Pseudo-constructor; returns time=1/hz seconds. | |
static SimTime | computeDeltaT (const SimTime &interval, const SimTime ×tep) |
Return a delta-t close to timestep for traversing the given interval. | |
static SimTime | fromString (const std::string &s, const char *default_suffix=0) |
Convert from string. |
Encapsulated representation of simulation time.
Basic arithmetic operators are supported. The idea is to not rely on a particular representation, but currently we are using a 64-bit signed integer to represent the number of microseconds or nanoseconds.
With this representation, the possible range of values is -2^(-63)/10^9 seconds = -9.2e+9 seconds, to 2^(63)/10^9 seconds = 9.2e+9 seconds. So, roughly: 33 bits are used to represent the integer portion, 30 bits to represent the fractional portion, and 1 bit for the sign. That means that this representation has a somewhat larger range of values than does the standard 32+32 bit 'struct timeval' from <sys/time.h>, which uses 32 bits for the integral portion, and 32 bits for the fractional portion (of which 12 bits are wasted since the fractional portion represents microseconds and so only 20 bits are needed to get up to 10^6).
In order to avoid losing precision, you should avoid calling secs() or msecs() etc. and doing math on the results; instead, do math using SimTime's builtin operators, and only convert to secs() or msecs() when absolutely necessary (e.g., to display the time to the user).
Definition at line 72 of file SimTime.H.
SimTime::SimTime | ( | ) | [inline] |
Default constructor; initialize to time=0.
Definition at line 76 of file SimTime.H.
Referenced by computeDeltaT(), MAX(), MSECS(), NSECS(), operator*(), operator+(), operator-(), SECS(), USECS(), and ZERO().
static SimTime SimTime::computeDeltaT | ( | const SimTime & | interval, | |
const SimTime & | timestep | |||
) | [inline, static] |
Return a delta-t close to timestep for traversing the given interval.
Definition at line 100 of file SimTime.H.
References SimTime().
Referenced by FrictionSaccadeController::doEvolve(), SimulationViewerStd::getTraj(), LeakyIntFire::integrate(), WinnerTakeAllGreedy::integrate(), LeakyIntegrator::integrate(), WinnerTakeAllStdOptim::integrate(), WinnerTakeAllTempNote::integrate(), LeakyIntFireAdp::integrate(), and WinnerTakeAllStd::integrate().
SimTime SimTime::fromString | ( | const std::string & | s, | |
const char * | default_suffix = 0 | |||
) | [static] |
Convert from string.
If default_suffix=null, then a valid suffix must be present to indicate the units represented by the number. If default_suffix==non-null, then that suffix will be used if the string itself doesn't contain a units suffix.
Definition at line 60 of file SimTime.C.
References MAX(), max(), min(), and NSECS().
Referenced by convertFromString(), EyeTrace::EyeTrace(), FrameRange::fromString(), HandTrace::HandTrace(), and ColorbarsInput::setConfigInfo().
double SimTime::hertz | ( | ) | const [inline] |
Return the rate (inverse seconds) represented.
Definition at line 140 of file SimTime.H.
Referenced by UcbMpegOutputStream::makeEncoder(), Stimulus2D::peekFrameSpec(), V4L2grabber::start1(), BobDeinterlacer::start2(), and EyeSFile::start2().
static SimTime SimTime::HERTZ | ( | double | hz | ) | [inline, static] |
Pseudo-constructor; returns time=1/hz seconds.
Definition at line 97 of file SimTime.H.
References SECS().
Referenced by XCgrabber::getNaturalFrameTime(), DC1394Grabber2::getNaturalFrameTime(), RTSPGrabber::getNaturalFrameTime(), XCgrabberFlex::getNaturalFrameTime(), IEEE1394grabber::getNaturalFrameTime(), V4Lgrabber::start1(), and V4L2grabber::start1().
static SimTime SimTime::MAX | ( | ) | [inline, static] |
Pseudo-constructor; builds the largest representable time.
Definition at line 82 of file SimTime.H.
References max(), and SimTime().
Referenced by fromString().
double SimTime::msecs | ( | ) | const [inline] |
Return the number of milliseconds represented.
Definition at line 128 of file SimTime.H.
Referenced by DirectFeedChannel::doInput(), SimulationViewerSurpCont::drawTime(), SimulationViewerStd::drawTime(), SimulationViewerNerdCam::drawTime(), SaccadeController::dumpQueues(), SimEventQueueDebug::evolve(), EyeTrace::EyeTrace(), SaccadeController::getDecision(), HandTrace::HandTrace(), DirectFeedChannel::inputPyramid(), DirectFeedChannel::outputAvailable(), SimEventQueueDebug::postHelper(), SimEventQueueDebug::prune(), SaccadeController::resetPos(), SimEventQueueDebug::resetTime(), SimulationViewerStats::save1(), SimulationViewerNerdCam::saveResults(), SimulationViewerSurpCont::saveResults(), FrameRange::toString(), SimEventClockTick::toString(), SimEventRetinaImage::toString(), InputFrameSeries::update(), and OutputFrameSeries::update().
static SimTime SimTime::MSECS | ( | double | ms | ) | [inline, static] |
Pseudo-constructor; returns time=ms milliseconds.
Definition at line 88 of file SimTime.H.
References SimTime().
Referenced by FrameRange::fromString(), and RawVisualCortex::getVCOutput().
bool SimTime::nonzero | ( | ) | const [inline] |
int64 SimTime::nsecs | ( | ) | const [inline] |
Return the number of nanoseconds represented.
Definition at line 136 of file SimTime.H.
Referenced by SimLayer::evolve(), SimUnit::evolve(), Structure< T >::evolve(), and SVEMNPlot::PlotBuf::push().
Pseudo-constructor; returns time=ns nanoseconds.
Definition at line 94 of file SimTime.H.
References SimTime().
Referenced by SimLayer::evolve(), SimUnit::evolve(), Structure< T >::evolve(), and fromString().
bool SimTime::operator!= | ( | const SimTime & | that | ) | const [inline] |
SimTime SimTime::operator* | ( | const int | x | ) | const [inline] |
SimTime SimTime::operator* | ( | const double | x | ) | const [inline] |
bool SimTime::operator< | ( | const SimTime & | that | ) | const [inline] |
bool SimTime::operator<= | ( | const SimTime & | that | ) | const [inline] |
bool SimTime::operator== | ( | const SimTime & | that | ) | const [inline] |
bool SimTime::operator> | ( | const SimTime & | that | ) | const [inline] |
bool SimTime::operator>= | ( | const SimTime & | that | ) | const [inline] |
double SimTime::secs | ( | ) | const [inline] |
Return the number of seconds represented.
Definition at line 124 of file SimTime.H.
Referenced by AlphaDecoder::AlphaDecoder(), SingleOpponentChannel::centerSurround(), FrictionSaccadeController::computeWhenNewDecision(), FrictionSaccadeController::computeWhenNewPercept(), FrictionSaccadeController::doEvolve(), FlickerChannel::doInput(), RectDecoder::getOutput(), HistDecoder::getOutput(), Stimulus2D::getTotalTime(), SimulationViewerStd::getTraj(), SingleChannelBeo::handleInput(), LeakyIntFire::integrate(), SaliencyMapFast::integrate(), LeakyIntegrator::integrate(), WinnerTakeAllStdOptim::integrate(), LeakyIntFireAdp::integrate(), Stimulus2D::next(), ColorbarsInput::readFrame(), Stimulus2D::setFrameNumber(), EyeSFile::start2(), and toString().
static SimTime SimTime::SECS | ( | double | s | ) | [inline, static] |
Pseudo-constructor; returns time=s seconds.
Definition at line 85 of file SimTime.H.
References SimTime().
Referenced by AlphaDecoder::AlphaDecoder(), SingleChannelBeoServer::check(), Timer::getSimTime(), Stimulus2D::getTotalTime(), HERTZ(), DirectFeedChannel::killCaches(), DirectFeedChannel::reset1(), Stimulus2D::setConfigInfo(), Stimulus2D::setFrameNumber(), V4L2grabber::start1(), and SingleChannelBeo::waitForOutput().
std::string SimTime::toString | ( | bool | with_suffix = false |
) | const |
Convert to string.
If with_suffix==true, then write a suffix after the number indicating the units (i.e., 's', 'ms', 'us'). If with_suffix==false, the no suffix is written and the number will represent the number of seconds.
Definition at line 51 of file SimTime.C.
References secs(), and sformat().
Referenced by convertToString(), PlotBuffer::SimTimeToSI(), and SimulationViewerEyeMvtNeuro::start1().
double SimTime::usecs | ( | ) | const [inline] |
Return the number of microseconds represented.
Definition at line 132 of file SimTime.H.
Referenced by BobDeinterlacer::readFrame(), and BobDeinterlacer::start2().
static SimTime SimTime::USECS | ( | double | us | ) | [inline, static] |
static SimTime SimTime::ZERO | ( | ) | [inline, static] |
Pseudo-constructor; returns time=0.
Definition at line 79 of file SimTime.H.
References SimTime().
Referenced by AlphaDecoder::AlphaDecoder(), FrameRange::FrameRange(), FrameRange::fromString(), SaccadeController::getDecision(), FrameIstream::getNaturalFrameTime(), SaccadeController::getPreviousDecision(), RawVisualCortex::getVCOutput(), SimUnit::initialize(), Structure< T >::initialize(), WinnerTakeAllStdOptim::integrate(), main(), MonkeyEyeHeadController::MonkeyEyeHeadController(), MonkeySaccadeController::MonkeySaccadeController(), SVEMNPlot::PlotBuf::PlotBuf(), SingleChannel::pyramidTime(), BobDeinterlacer::readFrame(), SVEMNPlot::PlotBuf::reset(), SimulationViewerNerdCam::reset1(), WinnerTakeAllStd::reset1(), WinnerTakeAllTempNote::reset1(), SimulationViewerStd::reset1(), SaliencyMapFast::reset1(), WinnerTakeAllStdOptim::reset1(), DirectFeedChannel::reset1(), ColorbarsInput::setConfigInfo(), and V4Lgrabber::start1().