From: Christian P. <cp...@us...> - 2004-12-26 16:45:58
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27931/include/pclasses Added Files: Time.h TimeSpan.h Log Message: Added TimeSpan and Time class. --- NEW FILE: TimeSpan.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_TimeSpan_h #define P_TimeSpan_h #include <pclasses/Exception.h> namespace P { //! Timespan class /*! This class is used to add or subtract a timespan from a Date, Time or DateTime object. */ class TimeSpan { public: TimeSpan(unsigned int days = 0, unsigned int hours = 0, unsigned int minutes = 0, unsigned int seconds = 0, unsigned int usecs = 0) throw(OverflowError); ~TimeSpan() throw(); void setDays(unsigned int days) throw(OverflowError); unsigned int days() const throw(); void setHours(unsigned int hours) throw(OverflowError); unsigned int hours() const throw(); void setMinutes(unsigned int minutes) throw(OverflowError); unsigned int minutes() const throw(); void setSeconds(unsigned int seconds) throw(OverflowError); unsigned int seconds() const throw(); void setUsecs(unsigned int usec) throw(OverflowError); unsigned int usecs() const throw(); //! Normalize the timespan void normalize() throw(OverflowError); bool operator>(const TimeSpan& sp) const throw(); bool operator<(const TimeSpan& sp) const throw(); bool operator>=(const TimeSpan& sp) const throw(); bool operator<=(const TimeSpan& sp) const throw(); bool operator==(const TimeSpan& sp) const throw(); bool operator!=(const TimeSpan& sp) const throw(); TimeSpan& operator+=(const TimeSpan& sp) throw(OverflowError); TimeSpan& operator-=(const TimeSpan& sp) throw(); friend TimeSpan operator+(const TimeSpan& sp1, const TimeSpan& sp2) throw(OverflowError); friend TimeSpan operator-(const TimeSpan& sp1, const TimeSpan& sp2) throw(); private: unsigned int _days; unsigned int _hours; unsigned int _minutes; unsigned int _seconds; unsigned int _usecs; }; } // !namespace P #endif --- NEW FILE: Time.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Time_h #define P_Time_h #include <pclasses/Exception.h> #include <iostream> namespace P { //! Invalid time error class InvalidTime: public RuntimeError { public: InvalidTime(const char* _what, const SourceInfo& si) : RuntimeError(_what, si) {} }; //! Time class class Time { public: Time(unsigned int hour = 0, unsigned int minute = 0, unsigned int second = 0, unsigned int usec = 0) throw(InvalidTime); ~Time() throw(); void setHour(unsigned int hour) throw(InvalidTime); unsigned int hour() const throw(); void setMinute(unsigned int minute) throw(InvalidTime); unsigned int minute() const throw(); void setSecond(unsigned int second) throw(InvalidTime); unsigned int second() const throw(); void setUsec(unsigned int usec) throw(InvalidTime); unsigned int usec() const throw(); bool operator>(const Time& t) const throw(); bool operator<(const Time& t) const throw(); bool operator>=(const Time& t) const throw(); bool operator<=(const Time& t) const throw(); bool operator==(const Time& t) const throw(); bool operator!=(const Time& t) const throw(); friend std::ostream& operator << (std::ostream& os, const Time& t); private: unsigned char _hour; unsigned char _minute; unsigned char _second; unsigned int _usec; }; } // !namespace P #endif |