SimTime Class Reference

Encapsulated representation of simulation time. More...

#include <Util/SimTime.H>

Collaboration diagram for SimTime:
Collaboration graph
[legend]

List of all members.

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.
SimTimeoperator+= (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 &timestep)
 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.

Detailed Description

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.


Constructor & Destructor Documentation

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().


Member Function Documentation

static SimTime SimTime::computeDeltaT ( const SimTime interval,
const SimTime timestep 
) [inline, static]
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]
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]
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]

Return true if the time represented is non-zero.

Definition at line 148 of file SimTime.H.

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().

static SimTime SimTime::NSECS ( int64  ns  )  [inline, static]

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]

compare time1!=time2

Definition at line 198 of file SimTime.H.

SimTime SimTime::operator* ( const int64  x  )  const [inline]

result=time*factor

Definition at line 173 of file SimTime.H.

References SimTime().

SimTime SimTime::operator* ( const int  x  )  const [inline]

result=time*factor

Definition at line 169 of file SimTime.H.

References SimTime().

SimTime SimTime::operator* ( const double  x  )  const [inline]

result=time*factor

Definition at line 165 of file SimTime.H.

References SimTime().

SimTime SimTime::operator+ ( const SimTime that  )  const [inline]

result=time1+time2

Definition at line 156 of file SimTime.H.

References SimTime().

SimTime& SimTime::operator+= ( const SimTime step  )  [inline]

Plus-equals.

Definition at line 152 of file SimTime.H.

SimTime SimTime::operator- ( const SimTime that  )  const [inline]

result=time1-time2

Definition at line 160 of file SimTime.H.

References SimTime().

bool SimTime::operator< ( const SimTime that  )  const [inline]

compare time1<time2

Definition at line 178 of file SimTime.H.

bool SimTime::operator<= ( const SimTime that  )  const [inline]

compare time1<=time2

Definition at line 182 of file SimTime.H.

bool SimTime::operator== ( const SimTime that  )  const [inline]

compare time1==time2

Definition at line 194 of file SimTime.H.

bool SimTime::operator> ( const SimTime that  )  const [inline]

compare time1>time2

Definition at line 186 of file SimTime.H.

bool SimTime::operator>= ( const SimTime that  )  const [inline]

compare time1>=time2

Definition at line 190 of file SimTime.H.

double SimTime::secs (  )  const [inline]
static SimTime SimTime::SECS ( double  s  )  [inline, static]
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]

Pseudo-constructor; returns time=us microseconds.

Definition at line 91 of file SimTime.H.

References SimTime().

static SimTime SimTime::ZERO (  )  [inline, static]

The documentation for this class was generated from the following files:
Generated on Sun May 8 08:43:49 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3