Add operator<< support for TimeMap

This commit is contained in:
Joakim Hove
2020-03-13 12:17:41 +01:00
parent d53826ed28
commit 4d01b85e99
2 changed files with 22 additions and 0 deletions

View File

@@ -27,6 +27,7 @@
#include <ctime>
#include <map>
#include <utility>
#include <iostream>
#include <stddef.h>
@@ -99,6 +100,9 @@ namespace Opm {
bool m_skiprest = false;
std::size_t m_restart_offset = 0;
};
std::ostream& operator<<(std::ostream& stream, const TimeMap& tm);
}

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include <ctime>
#include <stddef.h>
#include <iomanip>
#include <opm/common/utility/TimeService.hpp>
@@ -436,6 +437,23 @@ namespace {
bool TimeMap::skiprest() const {
return this->m_skiprest;
}
std::ostream& operator<<(std::ostream& stream, const TimeMap& tm) {
std::stringstream ss;
ss << "{";
std::size_t index = 0;
for (const auto& tp : tm.timeList()) {
auto ts = TimeStampUTC(tp);
ss << ts.year() << "-" << std::setfill('0') << std::setw(2) << ts.month() << "-" << std::setfill('0') << std::setw(2) << ts.day();
index += 1;
if (index < tm.timeList().size())
ss << ", ";
if (index % 12 == 0)
ss << std::endl;
}
ss << "}";
return stream << ss.str();
}
}