Date(const char * str);
       Date(const wchar_t * str);
       Date(const std::string & str);
       Date(const std::wstring & str);
 
       Date & operator=(const char * str);
       Date & operator=(const wchar_t * str);
       Date & operator=(const std::string & str);
       Date & operator=(const std::wstring & str);

       void Swap(Date&);
removed:
       templates cctors and operators=
       it is better to have directly char*, wchar_t and string, wstring



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@414 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-05-26 22:38:18 +00:00
parent 27cde22774
commit 03bac5721d
2 changed files with 94 additions and 38 deletions

View File

@ -62,12 +62,44 @@ Date::Date(time_t t)
FromTime(t); FromTime(t);
} }
Date::Date(const tm & t) Date::Date(const tm & t)
{ {
FromTm(t); FromTm(t);
} }
Date::Date(const char * str)
{
// parsing can be break in the middle of the string (if errors)
// and some values would not be initialized
Clear();
Parse(str);
}
Date::Date(const wchar_t * str)
{
Clear();
Parse(str);
}
Date::Date(const std::string & str)
{
Clear();
Parse(str);
}
Date::Date(const std::wstring & str)
{
Clear();
Parse(str);
}
Date & Date::operator=(const Date & d) Date & Date::operator=(const Date & d)
{ {
year = d.year; year = d.year;
@ -89,6 +121,8 @@ return *this;
} }
Date & Date::operator=(const tm & t) Date & Date::operator=(const tm & t)
{ {
FromTm(t); FromTm(t);
@ -97,6 +131,41 @@ return *this;
} }
Date & Date::operator=(const char * str)
{
Parse(str);
return *this;
}
Date & Date::operator=(const wchar_t * str)
{
Parse(str);
return *this;
}
Date & Date::operator=(const std::string & str)
{
Parse(str);
return *this;
}
Date & Date::operator=(const std::wstring & str)
{
Parse(str);
return *this;
}
Date Date::operator+(time_t t) const Date Date::operator+(time_t t) const
{ {
time_t t0 = ToTime(); time_t t0 = ToTime();
@ -133,6 +202,15 @@ return *this;
} }
void Date::Swap(Date & date)
{
Date temp(*this);
*this = date;
date = temp;
}
time_t Date::operator-(const Date & d) const time_t Date::operator-(const Date & d) const
{ {
time_t t0 = ToTime(); time_t t0 = ToTime();

View File

@ -39,6 +39,7 @@
#define headerfile_picotools_mainparser_mainparser #define headerfile_picotools_mainparser_mainparser
#include <ctime> #include <ctime>
#include <string>
@ -86,14 +87,19 @@ public:
Date(const Date & d); Date(const Date & d);
Date(time_t t); Date(time_t t);
Date(const tm & t); Date(const tm & t);
template<class CStringType> Date(const CStringType * str); Date(const char * str);
template<class StringType> Date(const StringType & str); Date(const wchar_t * str);
Date(const std::string & str);
Date(const std::wstring & str);
Date & operator=(const Date & d); Date & operator=(const Date & d);
Date & operator=(time_t t); Date & operator=(time_t t);
Date & operator=(const tm & t); Date & operator=(const tm & t);
template<class CStringType> Date & operator=(const CStringType * str); Date & operator=(const char * str);
template<class StringType> Date & operator=(const StringType & str); Date & operator=(const wchar_t * str);
Date & operator=(const std::string & str);
Date & operator=(const std::wstring & str);
/* /*
@ -105,6 +111,12 @@ public:
Date & operator-=(time_t t); Date & operator-=(time_t t);
/*
swapping the contents of *this with date
*/
void Swap(Date & date);
/* /*
converts time_t in seconds (from the Unix Epoch) to this object converts time_t in seconds (from the Unix Epoch) to this object
*/ */
@ -456,40 +468,6 @@ private:
template<class CStringType>
Date::Date(const CStringType * str)
{
// parsing can be break in the middle of the string (if errors)
// and some values would not be initialized
Clear();
Parse(str);
}
template<class StringType>
Date::Date(const StringType & str)
{
Clear();
Parse(str);
}
template<class CStringType>
Date & Date::operator=(const CStringType * str)
{
Parse(str);
return *this;
}
template<class StringType>
Date & Date::operator=(const StringType & str)
{
Parse(str);
return *this;
}