Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

lfc::TimeSpan Class Reference

represents a period of time, using seconds as basic representation. More...

Inheritance diagram for lfc::TimeSpan::

lfc::Object lfc::_Serializable lfc::_Formatable lfc::_Scanable List of all members.

Public Methods

 TimeSpan () throw ()
 TimeSpan (const TimeSpan &ts) throw ()
 TimeSpan (long seconds)
 creates an object with the period specified in seconds. More...

 TimeSpan (long seconds, long minutes, long hours=0, long days=0)
virtual ~TimeSpan () throw ()
virtual long seconds () const throw ()
 
Returns:
the whole period in seconds.
More...


virtual long minutes () const throw ()
 
Returns:
the whole period in minutes.
More...


virtual long hours () const throw ()
 
Returns:
the whole period in hours.
More...


virtual long days () const throw ()
 
Returns:
the whole period in days.
More...


virtual bool operator== (const TimeSpan &ts) const throw ()
virtual bool operator< (const TimeSpan &ts) const throw ()
virtual const TimeSpan & operator= (const TimeSpan &ts) throw ()
virtual const TimeSpan operator+ (const TimeSpan &ts) const
virtual const TimeSpan operator- (const TimeSpan &ts) const
virtual void writeObject (BinaryOutput &stream) const
 platform independent serialization. More...

virtual void readObject (BinaryInput &stream)
 platform independent deserialization. More...

virtual void formatObject (TextOutput &stream, string format="") const
 formatting based on a certain format. More...

virtual void scanObject (TextInput &stream, string format="")
 scanning based on a certain format. More...


Protected Attributes

long m_span

Detailed Description

represents a period of time, using seconds as basic representation.

    See Time example for a code sample.

Todo:
make this thread safe

See also:
HiResTimeSpan, Time


Constructor & Destructor Documentation

lfc::TimeSpan::TimeSpan   throw () [inline]
 

lfc::TimeSpan::TimeSpan const TimeSpan &    ts throw () [inline]
 

lfc::TimeSpan::TimeSpan long    seconds [inline]
 

creates an object with the period specified in seconds.

lfc::TimeSpan::TimeSpan long    seconds,
long    minutes,
long    hours = 0,
long    days = 0
 

creates an object specifing how many days, hours, minutes and seconds the time span takes, so:

Parameters:
days  must be in (0..24855)
hours  must be in (0..23)
minutes  must be in (0..59)
seconds  must be in (0..59)
Not respecting this intervals will result in throwing a TimeSpanException.

virtual lfc::TimeSpan::~TimeSpan   throw () [inline, virtual]
 


Member Function Documentation

virtual long lfc::TimeSpan::seconds   const throw () [inline, virtual]
 

Returns:
the whole period in seconds.

virtual long lfc::TimeSpan::minutes   const throw () [inline, virtual]
 

Returns:
the whole period in minutes.

virtual long lfc::TimeSpan::hours   const throw () [inline, virtual]
 

Returns:
the whole period in hours.

virtual long lfc::TimeSpan::days   const throw () [inline, virtual]
 

Returns:
the whole period in days.

virtual bool lfc::TimeSpan::operator== const TimeSpan &    ts const throw () [inline, virtual]
 

virtual bool lfc::TimeSpan::operator< const TimeSpan &    ts const throw () [inline, virtual]
 

virtual const TimeSpan& lfc::TimeSpan::operator= const TimeSpan &    ts throw () [inline, virtual]
 

virtual const TimeSpan lfc::TimeSpan::operator+ const TimeSpan &    ts const [inline, virtual]
 

virtual const TimeSpan lfc::TimeSpan::operator- const TimeSpan &    ts const [inline, virtual]
 

void lfc::TimeSpan::writeObject BinaryOutput   stream const [virtual]
 

platform independent serialization.

Reimplemented from lfc::_Serializable.

void lfc::TimeSpan::readObject BinaryInput   stream [virtual]
 

platform independent deserialization.

Reimplemented from lfc::_Serializable.

void lfc::TimeSpan::formatObject TextOutput   stream,
string    format = ""
const [virtual]
 

formatting based on a certain format.

The format must be as follows:

    Symbol      Meaning              Presentation       Example
    ------      -------              ------------       -------
    D           in days              Number             2.5
    d           floor(days)          Number             2
    H           in hours             Number             15.25
    h           floor(hours)         Number             15
    M           in minutes           Number             37.9
    m           floor(minutes)       Number             37
    s           in seconds           Number             125
    -d          days(0..24855)       Number             2
    -h          hours(0..23)         Number             12
    -m          minutes(0..59)       Number             50
    -s          seconds(0..59)       Number             43
    '           escape for text      Text               'seconds'
    ''          single quote         Text               '
    

Any characters in the pattern that are not in this formatting list will be treated as quoted text. For instance, characters like ':', ',', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.

Examples:

    Format Pattern                                Result
    --------------                                ------
    "M 'minutes; ' s 'seconds'"             ->>   "12.5 minutes; 750 seconds"
    "-h 'hours', -m 'mins' and -s 'secs'"   ->>   "2 hours, 12 mins and 58 secs"
    

Reimplemented from lfc::_Formatable.

void lfc::TimeSpan::scanObject TextInput   stream,
string    format = ""
[virtual]
 

scanning based on a certain format.

The format used for scanning is identical to that used for formatting and if the format or the data coming from the stream are invalid, an TimeSpanException will be thrown.
However, take under consideration the following rules/observations:

  • the format's symbols are split in two logic categories:
    • Category 1: D, d, H, h, M, m, s
    • Category 2: -d, -h, -m, -s
  • the two catogories are mutually exclusive;
  • the symbols in the 2nd category must be used only once, so they should not be repetead; if any of the 2nd category symbols are missing, their contribution to the final result will be 0;
  • any of the uppercase symbols D, H and M will be rounded down if a fully conversion to seconds is not possible, so be careful.

Reimplemented from lfc::_Scanable.


Member Data Documentation

long lfc::TimeSpan::m_span [protected]
 


The documentation for this class was generated from the following files:
Generated on Fri Jan 25 03:14:09 2002 for LFC2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001