From cd386caf6140dc41825e5341a84ba3d41073fca1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Aug 2017 21:03:04 +0100 Subject: Internalise and tidy common helpers --- p2pvr/ice/commonHelpers.cpp | 32 ++++++++++++++++++++++++++++++++ p2pvr/ice/commonHelpers.h | 28 ++++++---------------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/p2pvr/ice/commonHelpers.cpp b/p2pvr/ice/commonHelpers.cpp index 81d6b2a..8f5519a 100644 --- a/p2pvr/ice/commonHelpers.cpp +++ b/p2pvr/ice/commonHelpers.cpp @@ -1,7 +1,39 @@ #include "commonHelpers.h" +#include #include +#include + +namespace AdHoc { + template + struct StreamWriter : + public StreamWriterBase { + template + static void write(stream & s, const P & p, const Pn & ... pn) + { + s << std::setw(size) << std::setfill(pad) << p; + StreamWriter::next(s, pn...); + } + }; +} namespace Common { + AdHocFormatter(DateTimeFormat, "%\x40p-%\x20p-%\x20pT%\x20p:%\x20p"); + std::ostream & + operator<<(std::ostream & o, const Common::DateTime & dt) + { + return DateTimeFormat::write(o, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute); + } + + std::ostream & + operator<<(std::ostream & o, const Common::Duration & d) + { + if (d.Hours) { + o << d.Hours << "hrs "; + } + o << d.Minutes << "min"; + return o; + } + boost::posix_time::ptime operator*(const Common::DateTime & dt) { return boost::posix_time::ptime( diff --git a/p2pvr/ice/commonHelpers.h b/p2pvr/ice/commonHelpers.h index 67e861c..fb7826d 100644 --- a/p2pvr/ice/commonHelpers.h +++ b/p2pvr/ice/commonHelpers.h @@ -3,33 +3,17 @@ #include #include -#include #include #include namespace Common { - template - std::basic_ostream & - operator<<(std::basic_ostream & o, const Common::DateTime & dt) - { - o << std::setw(4) << std::setfill('0') << dt.Year - << "-" << std::setw(2) << std::setfill('0') << dt.Month - << "-" << std::setw(2) << std::setfill('0') << dt.Day - << "T" << std::setw(2) << std::setfill('0') << dt.Hour - << ":" << std::setw(2) << std::setfill('0') << dt.Minute; - return o; - } + DLL_PUBLIC + std::ostream & + operator<<(std::ostream & o, const Common::DateTime & dt); - template - std::basic_ostream & - operator<<(std::basic_ostream & o, const Common::Duration & d) - { - if (d.Hours) { - o << d.Hours << "hrs "; - } - o << d.Minutes << "min"; - return o; - } + DLL_PUBLIC + std::ostream & + operator<<(std::ostream & o, const Common::Duration & d); DLL_PUBLIC boost::posix_time::ptime operator*(const Common::DateTime &); DLL_PUBLIC boost::posix_time::time_duration operator*(const Common::Duration &); -- cgit v1.2.3