summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/ice/commonHelpers.cpp32
-rw-r--r--p2pvr/ice/commonHelpers.h28
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 <iomanip>
#include <boost/numeric/conversion/cast.hpp>
+#include <compileTimeFormatter.h>
+
+namespace AdHoc {
+ template<const char * const & S, int start, typename stream, char size, char pad, char ... sn>
+ struct StreamWriter<S, start, stream, '%', size, pad, sn...> :
+ public StreamWriterBase<S, start, BOOST_PP_VARIADIC_SIZE(C) + 1, stream, sn...> {
+ template<typename P, typename ... Pn>
+ 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 <common.h>
#include <ostream>
-#include <iomanip>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <visibility.h>
namespace Common {
- template<typename C, typename T>
- std::basic_ostream<C, T> &
- operator<<(std::basic_ostream<C, T> & 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<typename C, typename T>
- std::basic_ostream<C, T> &
- operator<<(std::basic_ostream<C, T> & 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 &);