
#include <Util/SimTime.H>
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.
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. | |
|
|
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(). |
|
||||||||||||
|
Return a delta-t close to timestep for traversing the given interval.
Definition at line 100 of file SimTime.H. References nseconds, and SimTime(). Referenced by FrictionSaccadeController::doEvolve(), StructureModule::evolve(), NeuralSimModule::evolve(), SimulationViewerStd::getTraj(), VirtualVoxelSalMap< T >::inputNewImage(), WinnerTakeAllStdOptim::integrate(), WinnerTakeAllTempNote::integrate(), WinnerTakeAllGreedy::integrate(), WinnerTakeAllStd::integrate(), LeakyIntFireAdp::integrate(), LeakyIntFire::integrate(), and LeakyIntegrator::integrate(). |
|
||||||||||||
|
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 57 of file SimTime.C. References LFATAL, rutz::max(), MAX(), rutz::min(), and NSECS(). Referenced by convertFromString(), EyeTrace::EyeTrace(), FrameRange::fromString(), getMetadataFromAuxFiles(), main(), and ColorbarsInput::setConfigInfo(). |
|
|
Return the rate (inverse seconds) represented.
Definition at line 140 of file SimTime.H. Referenced by EyeTrace::EyeTrace(), getMetadataFromAuxFiles(), UcbMpegOutputStream::makeEncoder(), Stimulus2D::peekFrameSpec(), BobDeinterlacer::start2(), and EyeSFile::start2(). |
|
|
Pseudo-constructor; returns time=1/hz seconds.
Definition at line 97 of file SimTime.H. References SECS(). Referenced by XCgrabberFlex::getNaturalFrameTime(), XCgrabber::getNaturalFrameTime(), RTSPGrabber::getNaturalFrameTime(), IEEE1394grabber::getNaturalFrameTime(), DC1394Grabber2::getNaturalFrameTime(), main(), V4Lgrabber::start1(), and submain(). |
|
|
Pseudo-constructor; builds the largest representable time.
Definition at line 82 of file SimTime.H. References rutz::max(), and SimTime(). Referenced by fromString(). |
|
|
|
Pseudo-constructor; returns time=ms milliseconds.
Definition at line 88 of file SimTime.H. References SimTime(). Referenced by BiasImageForm::evolveBrain(), evolveBrain(), ObjRecSalBayes::evolveBrain(), FrameRange::fromString(), RawVisualCortex::getVCOutput(), ObjRecSPM::predict(), and ObjRecSPM::train(). |
|
|
Return true if the time represented is non-zero.
|
|
|
Return the number of nanoseconds represented.
Definition at line 136 of file SimTime.H. Referenced by tcl::aux_convert_from(), and TigsInputFrame::toGhostString(). |
|
|
Pseudo-constructor; returns time=ns nanoseconds.
Definition at line 94 of file SimTime.H. References SimTime(). Referenced by tcl::aux_convert_to(), TigsInputFrame::fromGhostString(), and fromString(). |
|
|
result=time*factor
Definition at line 169 of file SimTime.H. References SimTime(). |
|
|
result=time*factor
Definition at line 165 of file SimTime.H. References SimTime(). |
|
|
result=time*factor
Definition at line 161 of file SimTime.H. References SimTime(). |
|
|
compare time1!=time2
Definition at line 194 of file SimTime.H. References nseconds. |
|
|
result=time1+time2
|
|
|
Plus-equals.
Definition at line 148 of file SimTime.H. References nseconds. |
|
|
result=time1-time2
|
|
|
compare time1<time2
Definition at line 174 of file SimTime.H. References nseconds. |
|
|
compare time1<=time2
Definition at line 178 of file SimTime.H. References nseconds. |
|
|
compare time1==time2
Definition at line 190 of file SimTime.H. References nseconds. |
|
|
compare time1>time2
Definition at line 182 of file SimTime.H. References nseconds. |
|
|
compare time1>=time2
Definition at line 186 of file SimTime.H. References nseconds. |
|
|
|
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(), main(), DirectFeedChannel::reset1(), Stimulus2D::setConfigInfo(), Stimulus2D::setFrameNumber(), and SingleChannelBeo::waitForOutput(). |
|
|
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 48 of file SimTime.C. References sformat(). Referenced by convertToString(), SimEventQueue::post(), and SimEventQueue::request(). |
|
|
Return the number of microseconds represented.
Definition at line 132 of file SimTime.H. Referenced by BobDeinterlacer::readFrame(), and BobDeinterlacer::start2(). |
|
|
Pseudo-constructor; returns time=us microseconds.
Definition at line 91 of file SimTime.H. References SimTime(). |
|
1.4.4