Skip to content

Commit

Permalink
Replace the final use of boost::posix_time with std::chrono.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentarctagon committed Oct 19, 2020
1 parent d757ee2 commit 055fbf7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/filesystem_sdl.cpp
Expand Up @@ -18,6 +18,7 @@
#include "log.hpp"

#include <algorithm>
#include <cassert>

static lg::log_domain log_filesystem("filesystem");
#define ERR_FS LOG_STREAM(err, log_filesystem)
Expand Down
1 change: 1 addition & 0 deletions src/gui/auxiliary/iterator/policy_order.hpp
Expand Up @@ -20,6 +20,7 @@
#include "gui/widgets/widget.hpp"

#include <iostream>
#include <cassert>

namespace gui2
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/dialogs/outro.cpp
Expand Up @@ -25,6 +25,8 @@
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"

#include <cmath>

namespace gui2
{
namespace dialogs
Expand Down
1 change: 1 addition & 0 deletions src/gui/widgets/generator.cpp
Expand Up @@ -20,6 +20,7 @@
#include "wml_exception.hpp"

#include <numeric>
#include <cmath>

namespace gui2
{
Expand Down
18 changes: 9 additions & 9 deletions src/log.cpp
Expand Up @@ -47,7 +47,6 @@ static bool timestamp = true;
static bool precise_timestamp = false;
static std::mutex log_mutex;

static boost::posix_time::time_facet facet("%Y%m%d %H:%M:%S%F ");
static std::ostream *output_stream = nullptr;

static std::ostream& output()
Expand Down Expand Up @@ -198,14 +197,15 @@ std::string get_timespan(const std::time_t& t) {
return sout.str();
}

static void print_precise_timestamp(std::ostream & out) noexcept
static void print_precise_timestamp(std::ostream& out) noexcept
{
try {
facet.put(
std::ostreambuf_iterator<char>(out),
out,
' ',
boost::posix_time::microsec_clock::local_time());
int64_t micros = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
std::time_t seconds = micros/1'000'000;
int fractional = micros-(seconds*1'000'000);
char c = out.fill('0');
out << std::put_time(std::localtime(&seconds), "%Y%m%d %H:%M:%S") << "." << std::setw(6) << fractional;
out.fill(c);
} catch(...) {}
}

Expand Down Expand Up @@ -269,7 +269,7 @@ void scope_logger::do_log_entry(const std::string& str) noexcept
{
str_ = str;
try {
ticks_ = boost::posix_time::microsec_clock::local_time();
ticks_ = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
} catch(...) {}
debug()(domain_, false, true) | formatter() << "{ BEGIN: " << str_ << "\n";
++indent;
Expand All @@ -279,7 +279,7 @@ void scope_logger::do_log_exit() noexcept
{
long ticks = 0;
try {
ticks = (boost::posix_time::microsec_clock::local_time() - ticks_).total_milliseconds();
ticks = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count() - ticks_;
} catch(...) {}
--indent;
auto output = debug()(domain_, false, true);
Expand Down
6 changes: 2 additions & 4 deletions src/log.hpp
Expand Up @@ -56,12 +56,10 @@
#include <sstream> // as above. iostream (actually, iosfwd) declares stringstream as an incomplete type, but does not define it
#include <string>
#include <utility>
#include <ctime>

#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "formatter.hpp"

using boost::posix_time::ptime;

namespace lg {

/**
Expand Down Expand Up @@ -167,7 +165,7 @@ log_domain& general();

class scope_logger
{
ptime ticks_;
int64_t ticks_;
const log_domain& domain_;
std::string str_;
public:
Expand Down

0 comments on commit 055fbf7

Please sign in to comment.