// timesec.h
// Version 3
// Glenn G. Chappell
// 14 Sep 2009
//
// For CS 311 Fall 2009
// Header for class TimeSec

#ifndef TIMESEC_H
#define TIMESEC_H

#include <iostream>  // for std::ostream


// ************************************************************************
// class TimeSec - Class definition
// ************************************************************************


// Invariants:
//     0 <= secs_ < 24*60*60
class TimeSec {

// ***** TimeSec: friend declarations *****

    friend bool operator==(const TimeSec & a,
                           const TimeSec & b);

// ***** TimeSec: ctors, dctor, op= *****
public:

    // Default ctor
    // Pre: None.
    // Post:
    //     secs_ == 0.
    TimeSec()
        :secs_(0)
    {}

    // Ctor from h,m,s
    // Pre:
    //     0 <= hh < 24;
    //     0 <= mm < 60;
    //     0 <= ss < 60.
    // Post:
    //     secs_ == hh*60*60 + mm*60 + ss.
    TimeSec(int hh,
            int mm,
            int ss)
    { setTime(hh, mm, ss); }
    
    // Use compiler-gen'd copy ctor, copy =, dctor

// ***** TimeSec: general public functions *****
public:

    // setTime
    // Pre:
    //     0 <= hh < 24;
    //     0 <= mm < 60;
    //     0 <= ss < 60.
    // Post:
    //     secs_ == hh*60*60 + mm*60 + ss.
    void setTime(int hh,
                 int mm,
                 int ss);

    // getTime
    // Pre: None.
    // Post:
    //     secs_ is unchanged;
    //     0 <= hh < 24;
    //     0 <= mm < 60;
    //     0 <= ss < 60;
    //     secs_ == hh*60*60 + mm*60 + ss.
    void getTime(int & hh,
                 int & mm,
                 int & ss) const;
    
// ***** TimeSec: general public operators *****
public:

    // op++ (pre)
    // Pre: None.
    // Post:
    //     secs_ represents a time 1 sec later than originally.
    //     Return is current object.
    TimeSec & operator++()
    {
        ++secs_;
        if (secs_ >= 24*60*60)
            secs_ = 0;
    	return *this;
    }
    
    // op++ (post)
    // Pre: None.
    // Post:
    //     secs_ represents a time 1 sec later than originally.
    //     Return is previous value of current object.
    TimeSec operator++(int dummy)
    {
        TimeSec saved = *this;
        ++*this;
        return saved;
    }

    // op-- (pre)
    // Pre: None.
    // Post:
    //     secs_ represents a time 1 sec earlier than originally.
    //     Return is current object.
    TimeSec & operator--()
    {
        if (secs_ == 0)
            secs_ = 24*60*60-1;
        else
            --secs_;
        return *this;
    }
    
    // op-- (post)
    // Pre: None.
    // Post:
    //     secs_ represents a time 1 sec earlier than originally.
    //     Return is previous value of current object.
    TimeSec operator--(int dummy)
    {
        TimeSec saved = *this;
        --*this;
        return saved;
    }

// ***** TimeSec: data members *****
private:

    int secs_;  // Seconds past midnight, in range [0, 24*60*60).
    
};  // end class TimeSec


// ************************************************************************
// class TimeSec - Declarations of Associated Global Operators
// ************************************************************************


// op== (TimeSec, TimeSec)
// Friend of class TimeSec
// Pre: None.
// Post:
//     Return is true iff a.secs_ == b.secs_.
bool operator==(const TimeSec & a,
                const TimeSec & b);

// op!= (TimeSec, TimeSec)
// Pre: None.
// Post:
//     Return is false iff a.secs_ == b.secs_.
bool operator!=(const TimeSec & a,
                const TimeSec & b);

// op<< (stream insertion for TimeSec)
// Pre: None.
// Post:
//     Values obtained from getTime have been printed to the given stream,
//     as follows:
//     - hh as 2 chars, padded on the left with blanks
//     - ":"
//     - mm as 2 chars, padded on the left with zeroes
//     - ":"
//     - ss as 2 chars, padded on the left with zeroes
std::ostream & operator<<(std::ostream & theStream,
                          const TimeSec & printMe);

#endif // #ifndef TIMESEC_H

