From 03bac5721d1f53957291acd6f0189a5562c1853e Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 26 May 2012 22:38:18 +0000 Subject: [PATCH] added: 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 --- date/date.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ date/date.h | 54 +++++++++++------------------------ 2 files changed, 94 insertions(+), 38 deletions(-) diff --git a/date/date.cpp b/date/date.cpp index 2346426..e1277bc 100644 --- a/date/date.cpp +++ b/date/date.cpp @@ -62,12 +62,44 @@ Date::Date(time_t t) FromTime(t); } + + Date::Date(const tm & 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) { year = d.year; @@ -89,6 +121,8 @@ return *this; } + + Date & Date::operator=(const tm & 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 { 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 t0 = ToTime(); diff --git a/date/date.h b/date/date.h index 9304877..fd896b0 100644 --- a/date/date.h +++ b/date/date.h @@ -39,6 +39,7 @@ #define headerfile_picotools_mainparser_mainparser #include +#include @@ -86,14 +87,19 @@ public: Date(const Date & d); Date(time_t t); Date(const tm & t); - template Date(const CStringType * str); - template Date(const StringType & str); + Date(const char * str); + Date(const wchar_t * str); + Date(const std::string & str); + Date(const std::wstring & str); Date & operator=(const Date & d); Date & operator=(time_t t); Date & operator=(const tm & t); - template Date & operator=(const CStringType * str); - template Date & operator=(const StringType & str); + Date & operator=(const char * 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); + /* + swapping the contents of *this with date + */ + void Swap(Date & date); + + /* converts time_t in seconds (from the Unix Epoch) to this object */ @@ -456,40 +468,6 @@ private: -template -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 -Date::Date(const StringType & str) -{ - Clear(); - Parse(str); -} - - -template -Date & Date::operator=(const CStringType * str) -{ - Parse(str); - -return *this; -} - - -template -Date & Date::operator=(const StringType & str) -{ - Parse(str); - -return *this; -}