Skip to content

Commit

Permalink
Use std::time_t instead of plain C time_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed May 13, 2018
1 parent e16373b commit ccbb736
Show file tree
Hide file tree
Showing 44 changed files with 123 additions and 121 deletions.
4 changes: 2 additions & 2 deletions src/addon/info.hpp
Expand Up @@ -54,8 +54,8 @@ struct addon_info

std::string feedback_url;

time_t updated;
time_t created;
std::time_t updated;
std::time_t created;

// Artificial upload order index used to preserve add-ons upload order
// until we have actual first-upload timestamps implemented. This index
Expand Down
8 changes: 4 additions & 4 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -576,7 +576,7 @@ void server::handle_request_campaign_list(const server::request& req)
{
LOG_CS << "sending campaign list to " << req.addr << " using gzip\n";

time_t epoch = time(nullptr);
std::time_t epoch = time(nullptr);
config campaign_list;

campaign_list["timestamp"] = epoch;
Expand All @@ -585,14 +585,14 @@ void server::handle_request_campaign_list(const server::request& req)
}

bool before_flag = false;
time_t before = epoch;
std::time_t before = epoch;
try {
before += req.cfg["before"].to_time_t();
before_flag = true;
} catch(const bad_lexical_cast&) {}

bool after_flag = false;
time_t after = epoch;
std::time_t after = epoch;
try {
after += req.cfg["after"].to_time_t();
after_flag = true;
Expand Down Expand Up @@ -825,7 +825,7 @@ void server::handle_upload(const server::request& req)
LOG_CS << "Upload denied - hidden add-on.\n";
send_error("Add-on upload denied. Please contact the server administration for assistance.", req.sock);
} else {
const time_t upload_ts = time(nullptr);
const std::time_t upload_ts = time(nullptr);

LOG_CS << "Upload is owner upload.\n";

Expand Down
2 changes: 1 addition & 1 deletion src/chat_events.hpp
Expand Up @@ -36,7 +36,7 @@ class chat_handler
void do_speak(const std::string& message, bool allies_only=false);

//called from do_speak
virtual void add_chat_message(const time_t& time,
virtual void add_chat_message(const std::time_t& time,
const std::string& speaker, int side, const std::string& message,
MESSAGE_TYPE type=MESSAGE_PRIVATE) = 0;
virtual void send_chat_message(const std::string& message, bool allies_only=false) = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/config_attribute_value.cpp
Expand Up @@ -296,9 +296,9 @@ std::size_t config_attribute_value::to_size_t(std::size_t def) const
return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
}

time_t config_attribute_value::to_time_t(time_t def) const
std::time_t config_attribute_value::to_time_t(std::time_t def) const
{
return apply_visitor(attribute_numeric_visitor<time_t>(def));
return apply_visitor(attribute_numeric_visitor<std::time_t>(def));
}

double config_attribute_value::to_double(double def) const
Expand Down
2 changes: 1 addition & 1 deletion src/config_attribute_value.hpp
Expand Up @@ -153,7 +153,7 @@ class config_attribute_value
long long to_long_long(long long def = 0) const;
unsigned to_unsigned(unsigned def = 0) const;
std::size_t to_size_t(std::size_t def = 0) const;
time_t to_time_t(time_t def = 0) const;
std::time_t to_time_t(std::time_t def = 0) const;
double to_double(double def = 0.) const;
std::string str(const std::string& fallback = "") const;
t_string t_str() const;
Expand Down
2 changes: 1 addition & 1 deletion src/display_chat_manager.cpp
Expand Up @@ -43,7 +43,7 @@ display_chat_manager::chat_message::chat_message(int speaker, int h)
{}


void display_chat_manager::add_chat_message(const time_t& time, const std::string& speaker,
void display_chat_manager::add_chat_message(const std::time_t& time, const std::string& speaker,
int side, const std::string& message, events::chat_handler::MESSAGE_TYPE type,
bool bell)
{
Expand Down
2 changes: 1 addition & 1 deletion src/display_chat_manager.hpp
Expand Up @@ -36,7 +36,7 @@ class display_chat_manager {
void remove_whisperer(const std::string& nick) { whisperers_.erase(nick); }
const std::set<std::string>& whisperers() const { return whisperers_; }

void add_chat_message(const time_t& time, const std::string& speaker,
void add_chat_message(const std::time_t& time, const std::string& speaker,
int side, const std::string& msg, events::chat_handler::MESSAGE_TYPE type, bool bell);
void clear_chat_messages() { prune_chat_messages(true); }

Expand Down
2 changes: 1 addition & 1 deletion src/filesystem.cpp
Expand Up @@ -991,7 +991,7 @@ bool file_exists(const std::string& name)
return file_exists(fs::path(name));
}

time_t file_modified_time(const std::string& fname)
std::time_t file_modified_time(const std::string& fname)
{
error_code ec;
auto mtime = fs::last_write_time(fs::path(fname), ec);
Expand Down
4 changes: 2 additions & 2 deletions src/filesystem.hpp
Expand Up @@ -219,7 +219,7 @@ bool is_directory(const std::string& fname);
bool file_exists(const std::string& name);

/** Get the modification time of a file. */
time_t file_modified_time(const std::string& fname);
std::time_t file_modified_time(const std::string& fname);

/** Returns true if the file ends with '.gz'. */
bool is_gzip_file(const std::string& filename);
Expand All @@ -239,7 +239,7 @@ struct file_tree_checksum
void reset() {nfiles = 0;modified = 0;sum_size=0;}
// @todo make variables private!
std::size_t nfiles, sum_size;
time_t modified;
std::time_t modified;
bool operator==(const file_tree_checksum &rhs) const;
bool operator!=(const file_tree_checksum &rhs) const
{ return !operator==(rhs); }
Expand Down
4 changes: 2 additions & 2 deletions src/format_time_summary.cpp
Expand Up @@ -20,8 +20,8 @@

namespace utils {

std::string format_time_summary(time_t t) {
time_t curtime = time(nullptr);
std::string format_time_summary(std::time_t t) {
std::time_t curtime = time(nullptr);
const struct tm* timeptr = localtime(&curtime);
if(timeptr == nullptr) {
return "";
Expand Down
2 changes: 1 addition & 1 deletion src/format_time_summary.hpp
Expand Up @@ -18,5 +18,5 @@
#include <string>

namespace utils {
std::string format_time_summary(time_t t);
std::string format_time_summary(std::time_t t);
}
4 changes: 2 additions & 2 deletions src/game_initialization/lobby_data.cpp
Expand Up @@ -46,7 +46,7 @@ static lg::log_domain log_lobby("lobby");

namespace mp {

chat_message::chat_message(const time_t& timestamp,
chat_message::chat_message(const std::time_t& timestamp,
const std::string& user,
const std::string& message)
: timestamp(timestamp), user(user), message(message)
Expand All @@ -57,7 +57,7 @@ chat_session::chat_session() : history_()
{
}

void chat_session::add_message(const time_t& timestamp,
void chat_session::add_message(const std::time_t& timestamp,
const std::string& user,
const std::string& message)
{
Expand Down
7 changes: 4 additions & 3 deletions src/game_initialization/lobby_data.hpp
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <ctime>
#include <set>
#include <deque>
#include <functional>
Expand All @@ -28,11 +29,11 @@ namespace mp {
struct chat_message
{
/** Create a chat message */
chat_message(const time_t& timestamp,
chat_message(const std::time_t& timestamp,
const std::string& user,
const std::string& message);

time_t timestamp;
std::time_t timestamp;
std::string user;
std::string message;
};
Expand All @@ -43,7 +44,7 @@ class chat_session
public:
chat_session();

void add_message(const time_t& timestamp,
void add_message(const std::time_t& timestamp,
const std::string& user,
const std::string& message);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/addon/manager.cpp
Expand Up @@ -831,7 +831,7 @@ void addon_manager::copy_url_callback(text_box& url_box)
desktop::clipboard::copy_to_clipboard(url_box.get_value(), false);
}

static std::string format_addon_time(time_t time)
static std::string format_addon_time(std::time_t time)
{
if(time) {
std::ostringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/debug_clock.cpp
Expand Up @@ -173,7 +173,7 @@ debug_clock::time::time() : hour(0), minute(0), second(0), millisecond(0)

void debug_clock::time::set_current_time()
{
time_t now = ::time(nullptr);
std::time_t now = ::time(nullptr);
tm* stamp = localtime(&now);

hour = stamp->tm_hour;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/chatbox.cpp
Expand Up @@ -256,7 +256,7 @@ void chatbox::user_relation_changed(const std::string& /*name*/)
}
}

void chatbox::add_chat_message(const time_t& /*time*/,
void chatbox::add_chat_message(const std::time_t& /*time*/,
const std::string& speaker,
int /*side*/,
const std::string& message,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/chatbox.hpp
Expand Up @@ -107,7 +107,7 @@ class chatbox : public container_base, public events::chat_handler
virtual void user_relation_changed(const std::string& name) override;

/** Inherited form @ref chat_handler */
virtual void add_chat_message(const time_t& time,
virtual void add_chat_message(const std::time_t& time,
const std::string& speaker,
int side,
const std::string& message,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/debug.cpp
Expand Up @@ -84,7 +84,7 @@ std::string get_base_filename()
{
std::ostringstream ss;

time_t t = time(nullptr);
std::time_t t = time(nullptr);
ss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");

static unsigned counter = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/log.cpp
Expand Up @@ -172,18 +172,18 @@ bool broke_strict() {
return strict_threw_;
}

std::string get_timestamp(const time_t& t, const std::string& format) {
std::string get_timestamp(const std::time_t& t, const std::string& format) {
std::ostringstream ss;

ss << std::put_time(std::localtime(&t), format.c_str());

return ss.str();
}
std::string get_timespan(const time_t& t) {
std::string get_timespan(const std::time_t& t) {
std::ostringstream sout;
// There doesn't seem to be any library function for this
const time_t minutes = t / 60;
const time_t days = minutes / 60 / 24;
const std::time_t minutes = t / 60;
const std::time_t days = minutes / 60 / 24;
if(t <= 0) {
sout << "expired";
} else if(minutes == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/log.hpp
Expand Up @@ -138,8 +138,8 @@ class logger {

void timestamps(bool);
void precise_timestamps(bool);
std::string get_timestamp(const time_t& t, const std::string& format="%Y%m%d %H:%M:%S ");
std::string get_timespan(const time_t& t);
std::string get_timestamp(const std::time_t& t, const std::string& format="%Y%m%d %H:%M:%S ");
std::string get_timespan(const std::time_t& t);

logger &err(), &warn(), &info(), &debug();
log_domain& general();
Expand Down
2 changes: 1 addition & 1 deletion src/log_windows.cpp
Expand Up @@ -109,7 +109,7 @@ std::string unique_log_filename()

o << log_file_prefix;

const time_t cur = time(nullptr);
const std::time_t cur = time(nullptr);
o << std::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");

o << GetCurrentProcessId() << log_file_suffix;
Expand Down
4 changes: 2 additions & 2 deletions src/menu_events.cpp
Expand Up @@ -1012,7 +1012,7 @@ void menu_handler::do_speak(const std::string& message)
chat_handler::do_speak(message, false);
}

void menu_handler::add_chat_message(const time_t& time,
void menu_handler::add_chat_message(const std::time_t& time,
const std::string& speaker,
int side,
const std::string& message,
Expand Down Expand Up @@ -1273,7 +1273,7 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
config cfg;
cfg["id"] = preferences::login();
cfg["message"] = message;
const time_t time = ::time(nullptr);
const std::time_t time = ::time(nullptr);
std::stringstream ss;
ss << time;
cfg["time"] = ss.str();
Expand Down
2 changes: 1 addition & 1 deletion src/menu_events.hpp
Expand Up @@ -123,7 +123,7 @@ class menu_handler : private chat_handler
const gamemap& map() const;

protected:
void add_chat_message(const time_t& time,
void add_chat_message(const std::time_t& time,
const std::string& speaker,
int side,
const std::string& message,
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/game.cpp
Expand Up @@ -890,7 +890,7 @@ compression::format save_compression_format()
return compression::GZIP;
}

std::string get_chat_timestamp(const time_t& t) {
std::string get_chat_timestamp(const std::time_t& t) {
if (chat_timestamping()) {
if(preferences::use_twelve_hour_clock_format() == false) {
return lg::get_timestamp(t, _("[%H:%M]")) + " ";
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/game.hpp
Expand Up @@ -199,7 +199,7 @@ class acquaintance;


// Multiplayer functions
std::string get_chat_timestamp(const time_t& t);
std::string get_chat_timestamp(const std::time_t& t);
bool chat_timestamping();
void set_chat_timestamping(bool value);

Expand Down
4 changes: 2 additions & 2 deletions src/replay.cpp
Expand Up @@ -124,9 +124,9 @@ static void verify(const unit_map& units, const config& cfg) {
LOG_REPLAY << "verification passed\n";
}

static time_t get_time(const config &speak)
static std::time_t get_time(const config &speak)
{
time_t time;
std::time_t time;
if (!speak["time"].empty())
{
std::stringstream ss(speak["time"].str());
Expand Down
5 changes: 3 additions & 2 deletions src/replay.hpp
Expand Up @@ -21,6 +21,7 @@

#include "map/location.hpp"

#include <ctime>
#include <deque>
#include <iterator>
#include <map>
Expand All @@ -35,14 +36,14 @@ class chat_msg {
const std::string &text() const { return text_; }
const std::string &nick() const { return nick_; }
const std::string &color() const { return color_; }
const time_t &time() const { return time_; }
const std::time_t &time() const { return time_; }
chat_msg(const config &cfg);
virtual ~chat_msg();
private:
std::string color_;
std::string nick_;
std::string text_;
time_t time_;
std::time_t time_;
};

class replay
Expand Down
2 changes: 1 addition & 1 deletion src/reports.cpp
Expand Up @@ -1534,7 +1534,7 @@ REPORT_GENERATOR(report_clock, /*rc*/)
? "%I:%M %p"
: "%H:%M";

time_t t = std::time(nullptr);
std::time_t t = std::time(nullptr);
ss << std::put_time(std::localtime(&t), format);

return text_report(ss.str(), _("Clock"));
Expand Down

0 comments on commit ccbb736

Please sign in to comment.