From: Christian P. <cp...@us...> - 2004-12-27 05:33:26
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29200/src Modified Files: Date.cpp DateTime.cpp Time.cpp Log Message: Added copy & assign operators Index: DateTime.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/DateTime.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DateTime.cpp 27 Dec 2004 05:21:53 -0000 1.1 +++ DateTime.cpp 27 Dec 2004 05:33:15 -0000 1.2 @@ -32,6 +32,11 @@ { } +DateTime::DateTime(const DateTime& dt) +: Date(dt), Time(dt), _tzname(dt._tzname) +{ +} + DateTime::~DateTime() { } @@ -46,6 +51,14 @@ _tzname = tzname; } +DateTime& DateTime::operator=(const DateTime& dt) +{ + Date::operator=(dt); + Time::operator=(dt); + _tzname = dt._tzname; + return *this; +} + bool DateTime::operator>(const DateTime& dt) const throw() { return (Date::operator>(dt) || (Date::operator==(dt) && Time::operator>(dt))); Index: Time.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Time.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Time.cpp 26 Dec 2004 16:45:48 -0000 1.1 +++ Time.cpp 27 Dec 2004 05:33:15 -0000 1.2 @@ -31,6 +31,11 @@ throw InvalidTime("Invalid time", P_SOURCEINFO); } +Time::Time(const Time& t) throw() +: _hour(t._hour), _minute(t._minute), _second(t._second), _usec(t._usec) +{ +} + Time::~Time() throw() { } @@ -87,6 +92,15 @@ return _usec; } +Time& Time::operator=(const Time& t) throw() +{ + _hour = t._hour; + _minute = t._minute; + _second = t._second; + _usec = t._usec; + return *this; +} + bool Time::operator>(const Time& t) const throw() { return (_hour > t._hour || Index: Date.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Date.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Date.cpp 26 Dec 2004 17:02:54 -0000 1.1 +++ Date.cpp 27 Dec 2004 05:33:15 -0000 1.2 @@ -30,18 +30,23 @@ throw InvalidDate("Invalid date", P_SOURCEINFO); } +Date::Date(const Date& d) throw() +: _year(d._year), _month(d._month), _day(d._day) +{ +} + Date::~Date() throw() { } void Date::setYear(unsigned int year) { - _year = year; + _year = year; } unsigned int Date::year() const throw() { - return _year; + return _year; } void Date::setMonth(unsigned int month) throw(InvalidDate) @@ -53,12 +58,12 @@ unsigned int Date::month() const throw() { - return _month; + return _month; } unsigned int Date::daysInMonth() throw() { - return daysInMonth(_month, _year); + return daysInMonth(_month, _year); } void Date::setDay(unsigned int day) throw(InvalidDate) @@ -69,13 +74,13 @@ _day = day; return; } - + throw InvalidDate("Invalid day in month", P_SOURCEINFO); } unsigned int Date::day() const throw() { - return _day; + return _day; } double Date::julianDayNumber() const throw() @@ -106,12 +111,12 @@ bool Date::isInLeapYear() const throw() { - return isLeapYear(_year); + return isLeapYear(_year); } bool Date::isLeapYear(unsigned int year) throw() { - return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); + return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); } unsigned int Date::daysInMonth(unsigned int month, unsigned int year) @@ -124,40 +129,46 @@ return dim; } +Date& Date::operator=(const Date& d) throw() +{ + _year = d._year; + _month = d._month; + _day = d._day; + return *this; +} + bool Date::operator>(const Date& d) const throw() { - return (_year > d._year || - (_year == d._year && _month > d._month) || - (_month == d._month && _day > d._day)); + return (_year > d._year || + (_year == d._year && _month > d._month) || + (_month == d._month && _day > d._day)); } bool Date::operator<(const Date& d) const throw() { - return (_year < d._year || - (_year == d._year && _month < d._month) || - (_month == d._month && _day < d._day)); + return (_year < d._year || + (_year == d._year && _month < d._month) || + (_month == d._month && _day < d._day)); } bool Date::operator>=(const Date& d) const throw() { - return (operator>(d) || operator==(d)); + return (operator>(d) || operator==(d)); } bool Date::operator<=(const Date& d) const throw() { - return (operator<(d) || operator==(d)); + return (operator<(d) || operator==(d)); } bool Date::operator==(const Date& d) const throw() { - return (_year == d._year && - _month == d._month && - _day == d._day); + return (_year == d._year && _month == d._month && _day == d._day); } bool Date::operator!=(const Date& d) const throw() { - return (!operator==(d)); + return (!operator==(d)); } std::ostream& operator << (std::ostream& os, const Date& d) |