TimeStep Class Reference

#include <orsa_units.h>

List of all members.

Public Member Functions

 TimeStep ()
 TimeStep (const unsigned int days, const unsigned int day_fraction, const int sign)
 TimeStep (const double t)
 TimeStep (const TimeStep &)
double GetDouble () const
TimeStepoperator+= (const TimeStep &)
TimeStepoperator-= (const TimeStep &)
TimeStep operator+ (const TimeStep &) const
TimeStep operator- (const TimeStep &) const
TimeStepoperator *= (const int)
TimeStepoperator *= (const double)
void AddDays (const unsigned int, const int)
void AddDayFractions (const unsigned int, const int)
TimeStep operator+ () const
TimeStep operator- () const
bool operator== (const TimeStep &) const
bool operator!= (const TimeStep &) const
bool operator> (const TimeStep &) const
bool operator< (const TimeStep &) const
bool operator>= (const TimeStep &ts) const
bool operator<= (const TimeStep &ts) const
TimeStep absolute () const
bool IsZero () const
unsigned int days () const
unsigned int day_fraction () const
int sign () const

Static Public Member Functions

static unsigned int max_day_fraction ()


Constructor & Destructor Documentation

TimeStep  ) 
 

Definition at line 909 of file orsa_units.cc.

Referenced by TimeStep::absolute(), TimeStep::operator+(), and TimeStep::operator-().

00909                      : _days(0), _day_fraction(0), _sign(+1) { 
00910     internal_check();
00911   }

TimeStep const unsigned int  days,
const unsigned int  day_fraction,
const int  sign
 

Definition at line 913 of file orsa_units.cc.

References ORSA_ERROR.

00913                                                                                              : _days(days), _day_fraction(day_fraction), _sign(sign) {
00914     if (_sign == 0) {
00915       ORSA_ERROR("Hmmm, sign equal to zero...");
00916     }   else {
00917       _sign = _sign / abs(_sign);
00918     }
00919     internal_check();
00920   }

TimeStep const double  t  ) 
 

Definition at line 922 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), and TimeStep::max_day_fraction().

00922                                    {
00923     if (t < 0) {
00924       _sign = -1;
00925     } else {
00926       _sign = +1;
00927     }   
00928     
00929     const double t_in_days = FromUnits(fabs(t),DAY,-1);
00930     _days         = (unsigned int)(floor(t_in_days));
00931     _day_fraction = (unsigned int)rint((t_in_days - _days)*max_day_fraction());
00932     
00933     internal_check();
00934   }

Here is the call graph for this function:

TimeStep const TimeStep  ) 
 

Definition at line 936 of file orsa_units.cc.

00936                                         : _days(ts._days), _day_fraction(ts._day_fraction), _sign(ts._sign) {
00937     internal_check();
00938   }


Member Function Documentation

TimeStep absolute  )  const
 

Definition at line 1269 of file orsa_units.cc.

References TimeStep::TimeStep().

Referenced by UniverseTypeAwareTimeStep::absolute().

01269 { return TimeStep(_days,_day_fraction,+1); }

Here is the call graph for this function:

void AddDayFractions const unsigned  int,
const   int
 

Definition at line 963 of file orsa_units.cc.

References TimeStep::max_day_fraction().

Referenced by TimeStep::operator+=(), and TimeStep::operator-=().

00963                                                                       {
00964     if (sign == _sign) {
00965       _day_fraction += df;
00966       if (_day_fraction >= max_day_fraction()) {
00967         ++_days;
00968         _day_fraction -= max_day_fraction();
00969       }
00970     } else {
00971       if (_day_fraction >= df) {
00972         _day_fraction -= df;
00973       } else {
00974         if (_days > 0) {
00975           --_days;
00976           _day_fraction += max_day_fraction();
00977           _day_fraction -= df;
00978         } else {
00979           _sign = -_sign;
00980           _day_fraction = df - _day_fraction;
00981         }
00982       }
00983     }
00984     internal_check();
00985   }

Here is the call graph for this function:

void AddDays const unsigned  int,
const   int
 

Definition at line 944 of file orsa_units.cc.

References TimeStep::max_day_fraction().

Referenced by TimeStep::operator+=(), and TimeStep::operator-=().

00944                                                              {
00945     if (sign == _sign) {
00946       _days += d;
00947     } else {
00948       if (d > _days) {
00949         _sign = -_sign;
00950         _days = d - _days - 1;
00951         _day_fraction = max_day_fraction() - _day_fraction;
00952         if (_day_fraction >= max_day_fraction()) {
00953           ++_days;
00954           _day_fraction -= max_day_fraction();
00955         }
00956       } else {
00957         _days -= d;
00958       }
00959     }
00960     internal_check();
00961   }

Here is the call graph for this function:

unsigned int day_fraction  )  const [inline]
 

Definition at line 343 of file orsa_units.h.

00343 { return _day_fraction; }

unsigned int days  )  const [inline]
 

Definition at line 342 of file orsa_units.h.

00342 { return _days;         }       

double GetDouble  )  const
 

Definition at line 1252 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), and TimeStep::max_day_fraction().

Referenced by UniverseTypeAwareTimeStep::GetDouble(), and TimeStep::operator *=().

01252                                    {
01253     return (FromUnits(_sign*(_days+(_day_fraction*1.0)/max_day_fraction()),DAY));
01254   }

Here is the call graph for this function:

bool IsZero  )  const
 

Definition at line 1271 of file orsa_units.cc.

Referenced by UniverseTypeAwareTimeStep::IsZero().

01271 { return ((_days == 0) && (_day_fraction == 0)); }

static unsigned int max_day_fraction  )  [inline, static]
 

Definition at line 334 of file orsa_units.h.

Referenced by TimeStep::AddDayFractions(), TimeStep::AddDays(), TimeStep::GetDouble(), TimeStep::operator *=(), and TimeStep::TimeStep().

00334                                            {
00335       return 864000000; // 86400 ( = second per day) * 10000 ( = 1.0e-4 seconds resolution)
00336     }

TimeStep & operator *= const   double  ) 
 

Definition at line 1152 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), TimeStep::GetDouble(), and TimeStep::max_day_fraction().

01152                                                   {
01153     const double t = GetDouble()*x;
01154     // same code in constructor from double
01155     if (t < 0) {
01156       _sign = -1;
01157     } else {
01158       _sign = +1;
01159     }   
01160     //    
01161     const double t_in_days = FromUnits(fabs(t),DAY,-1);
01162     _days         = (unsigned int)(floor(t_in_days));
01163     _day_fraction = (unsigned int)rint((t_in_days - _days)*max_day_fraction());
01164     //
01165     internal_check();
01166     //
01167     return * this;
01168   }

Here is the call graph for this function:

TimeStep & operator *= const   int  ) 
 

Definition at line 1134 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), TimeStep::GetDouble(), and TimeStep::max_day_fraction().

01134                                                {
01135     const double t = GetDouble()*p;
01136     // same code in constructor from double
01137     if (t < 0) {
01138       _sign = -1;
01139     } else {
01140       _sign = +1;
01141     }   
01142     //    
01143     const double t_in_days = FromUnits(fabs(t),DAY,-1);
01144     _days         = (unsigned int)(floor(t_in_days));
01145     _day_fraction = (unsigned int)rint((t_in_days - _days)*max_day_fraction());
01146     //
01147     internal_check();
01148     //
01149     return * this;
01150   }     

Here is the call graph for this function:

bool operator!= const TimeStep  )  const
 

Definition at line 1265 of file orsa_units.cc.

01265                                                        {
01266     return (!((*this) == ts));
01267   }

TimeStep operator+  )  const
 

Definition at line 1221 of file orsa_units.cc.

References TimeStep::TimeStep().

01221 { return TimeStep(*this); }

Here is the call graph for this function:

TimeStep operator+ const TimeStep  )  const
 

Definition at line 1094 of file orsa_units.cc.

01094                                                           {
01095     TimeStep _ts(*this);
01096     _ts += ts;
01097     return _ts;
01098   }

TimeStep & operator+= const TimeStep  ) 
 

Definition at line 1046 of file orsa_units.cc.

References TimeStep::AddDayFractions(), and TimeStep::AddDays().

01046                                                        { 
01047     AddDays(ts._days,ts._sign);
01048     AddDayFractions(ts._day_fraction,ts._sign);
01049     return * this;
01050   }

Here is the call graph for this function:

TimeStep operator-  )  const
 

Definition at line 1223 of file orsa_units.cc.

References TimeStep::TimeStep().

01223 { return TimeStep(_days,_day_fraction,-_sign); }

Here is the call graph for this function:

TimeStep operator- const TimeStep  )  const
 

Definition at line 1100 of file orsa_units.cc.

01100                                                           {
01101     TimeStep _ts(*this);
01102     _ts -= ts;
01103     return _ts;
01104   }

TimeStep & operator-= const TimeStep  ) 
 

Definition at line 1052 of file orsa_units.cc.

References TimeStep::AddDayFractions(), and TimeStep::AddDays().

01052                                                        { 
01053     AddDays(ts._days,-ts._sign);
01054     AddDayFractions(ts._day_fraction,-ts._sign);
01055     return * this;
01056   }

Here is the call graph for this function:

bool operator< const TimeStep  )  const
 

Definition at line 1225 of file orsa_units.cc.

01225                                                       {
01226     
01227     if (*this == ts) return false; // they are equal!
01228     
01229     if (_sign == ts._sign) {
01230       if (_sign == -1) {
01231         if (_days > ts._days) return true;
01232         if ( (_days == ts._days) &&
01233              (_day_fraction > ts._day_fraction) ) return true;
01234       } else {
01235         if (_days < ts._days) return true;
01236         if ( (_days == ts._days) &&
01237              (_day_fraction < ts._day_fraction) ) return true;
01238       }
01239     } else {
01240       if (_sign == -1) {
01241         return true;
01242       }
01243     }
01244     return false;
01245   }

bool operator<= const TimeStep ts  )  const [inline]
 

Definition at line 324 of file orsa_units.h.

00324                                                         {
00325       if ((*this) == ts) return true;
00326       if ((*this) <  ts) return true;
00327       return false;      
00328     }

bool operator== const TimeStep  )  const
 

Definition at line 1256 of file orsa_units.cc.

01256                                                        {
01257     
01258     // if (ts.IsZero() && IsZero()) return true; // this check is 'probably' not needed since we use the internal_check() call every time we change the object
01259     if (ts._days != _days) return false;
01260     if (ts._day_fraction != _day_fraction) return false;
01261     if (ts._sign != _sign) return false;
01262     return true;
01263   }

bool operator> const TimeStep  )  const
 

Definition at line 1247 of file orsa_units.cc.

01247                                                       {
01248     if (*this == ts) return false; // they are equal!
01249     return (!((*this) < ts));
01250   }

bool operator>= const TimeStep ts  )  const [inline]
 

Definition at line 318 of file orsa_units.h.

00318                                                         {
00319       if ((*this) == ts) return true;
00320       if ((*this) >  ts) return true;
00321       return false;
00322     }

int sign  )  const [inline]
 

Definition at line 344 of file orsa_units.h.

00344 { return _sign;         }


The documentation for this class was generated from the following files:
Generated on Tue Jan 11 15:29:49 2005 for liborsa by  doxygen 1.4.0