From 453c50c5630889cbdd5731004497576fc82f740b Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 7 Sep 2024 22:26:57 -0400 Subject: [PATCH] Big cleanup of rampant using std. --- Makefile | 3 +++ builder.cpp | 17 +++++++---------- builder.hpp | 2 ++ coro.hpp | 1 - corotest.cpp | 4 +++- dbc.hpp | 2 +- game_engine.hpp | 10 ++++------ gui.cpp | 8 ++++---- gui.hpp | 4 +++- jsontest.cpp | 6 +++--- sfmlgui.cpp | 3 ++- sfmlgui.hpp | 8 +++++--- tests/game_engine.cpp | 4 ++-- watcher.cpp | 9 +++++---- watcher.hpp | 8 +++++--- 15 files changed, 49 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 67e7ffe..49fb0fb 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,6 @@ install: build test run: install ./escape_turings_tarpit.exe + +clean: + meson compile --clean -C builddir diff --git a/builder.cpp b/builder.cpp index 2a3c4ec..412c43a 100644 --- a/builder.cpp +++ b/builder.cpp @@ -18,18 +18,17 @@ #include // for EXIT_SUCCESS #include // for operator+, to_string #include -#include #include #include -using namespace std; +using std::string; using namespace fmt; using namespace nlohmann; #define BUF_MAX 1024 Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) { - ifstream infile(".tarpit.json"); + std::ifstream infile(".tarpit.json"); json config = json::parse(infile); config["git_path"].template get_to(git_path); @@ -37,14 +36,14 @@ Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) { } Task Builder::run_build() { - regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"); + std::regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"); char buffer[BUF_MAX]; // BUF_MAX is a define already? - ofstream stats_out; + std::ofstream stats_out; co_await Pass{}; - stats_out.open("stats.csv", ios::out | ios::app); + stats_out.open("stats.csv", std::ios::out | std::ios::app); std::time_t tstamp = std::time(nullptr); dbc::check(stats_out.good(), "Error opening stats.csv file."); @@ -64,10 +63,8 @@ Task Builder::run_build() { co_yield 3; string line(buffer); // yeah, that's probably a problem - cerr << buffer; - - smatch err; - bool match = regex_match(line, err, err_re); + std::smatch err; + bool match = std::regex_match(line, err, err_re); if(match) { string file_name = err[1].str(); diff --git a/builder.hpp b/builder.hpp index 2f4d412..96b0b12 100644 --- a/builder.hpp +++ b/builder.hpp @@ -3,6 +3,8 @@ #include "game_engine.hpp" #include "coro.hpp" +using std::string; + class Builder { GUI gui; GameEngine game; diff --git a/coro.hpp b/coro.hpp index c863d3f..5c77063 100644 --- a/coro.hpp +++ b/coro.hpp @@ -4,7 +4,6 @@ #include #include -using namespace std; enum TaskStates { STARTED, AWAIT, YIELD, diff --git a/corotest.cpp b/corotest.cpp index 6b140a6..c6d7a8a 100644 --- a/corotest.cpp +++ b/corotest.cpp @@ -3,6 +3,8 @@ #include #include +using std::cout, std::endl; + Task task_test() { co_await Pass{}; @@ -16,7 +18,7 @@ Task task_test() int main() { const int task_count = 4; - vector> tasks; + std::vector> tasks; for(int i = 0; i < task_count; i++) { auto t = task_test(); diff --git a/dbc.hpp b/dbc.hpp index a8b675d..cc4d71c 100644 --- a/dbc.hpp +++ b/dbc.hpp @@ -4,7 +4,7 @@ #include #include -using namespace std; +using std::string; namespace dbc { class Error { diff --git a/game_engine.hpp b/game_engine.hpp index 60e9b86..d994c2d 100644 --- a/game_engine.hpp +++ b/game_engine.hpp @@ -2,15 +2,13 @@ #include #include -#include #include #include -using namespace std; - +using std::string; class GameEngine { - map damage_types{ + std::map damage_types{ {"error", 4}, {"warning", 1}, {"note", 0}, @@ -45,8 +43,8 @@ class Brainfucker { public: size_t dp = 0; size_t ip = 0; - ostringstream out; - array data = {}; + std::stringstream out; + std::array data = {}; string code = {}; Brainfucker(); diff --git a/gui.cpp b/gui.cpp index 695fa37..1f35d51 100644 --- a/gui.cpp +++ b/gui.cpp @@ -4,21 +4,21 @@ #include #include // for allocator, shared_ptr #include // for operator+, to_string -#include // for sleep_for #include #include #include #include #include "sfmlgui.hpp" -using namespace std; +using std::string, std::vector; + using namespace fmt; using namespace nlohmann; namespace fs = std::filesystem; void SoundQuip::load(json &data, const char *file_key) { auto audio = data["audio"]; - json::string_t file_name = audio[file_key].template get(); + json::string_t file_name = audio[file_key].template get(); if(!buffer.loadFromFile(file_name)) { println("Failed to load sound: {} with file {}", file_key, file_name); @@ -36,7 +36,7 @@ void SoundQuip::stop() { } GUI::GUI() { - ifstream infile(".tarpit.json"); + std::ifstream infile(".tarpit.json"); json data = json::parse(infile); // json load the config file diff --git a/gui.hpp b/gui.hpp index 2ddeaa3..0582561 100644 --- a/gui.hpp +++ b/gui.hpp @@ -7,6 +7,8 @@ #include #include +using std::string; + class SoundQuip { public: sf::Sound sound; @@ -21,7 +23,7 @@ public: }; class GUI { - vector lines; + std::vector lines; SoundQuip you_died_sound; SoundQuip build_works_sound; diff --git a/jsontest.cpp b/jsontest.cpp index f9497f0..32166ff 100644 --- a/jsontest.cpp +++ b/jsontest.cpp @@ -5,7 +5,7 @@ using json = nlohmann::json; using namespace fmt; -using namespace std; +using std::string, std::cout; int main(int argc, char *argv[]) { if(argc != 2) { @@ -13,10 +13,10 @@ int main(int argc, char *argv[]) { return 0; } - ifstream infile(argv[1]); + std::ifstream infile(argv[1]); json data = json::parse(infile); - json::string_t s2 = data["happy"].template get(); + json::string_t s2 = data["happy"].template get(); for(auto &el : data.items()) { cout << el.key() << "=" << el.value() << "\n"; diff --git a/sfmlgui.cpp b/sfmlgui.cpp index 9a0d383..1337733 100644 --- a/sfmlgui.cpp +++ b/sfmlgui.cpp @@ -12,6 +12,7 @@ #include "sfmlgui.hpp" using namespace ImGui; +using std::string; void SFMLGui::ImGui_setup() { bool res = SFML::Init(window); @@ -139,7 +140,7 @@ SFMLGui::SFMLGui(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's } -void SFMLGui::update_log(vector &lines) { +void SFMLGui::update_log(std::vector &lines) { log.clear(); for(string &line : lines) { log.push_back(line); diff --git a/sfmlgui.hpp b/sfmlgui.hpp index 6b64f99..de19839 100644 --- a/sfmlgui.hpp +++ b/sfmlgui.hpp @@ -6,6 +6,8 @@ #include "game_engine.hpp" #include +using std::string; + constexpr int FPS=30; constexpr int X_DIM = 1920 / 2; constexpr int Y_DIM = 1080 / 2; @@ -25,7 +27,7 @@ class SFMLGui { int hit_points = 50; sf::Font font; GameEngine &game; - vector log; + std::vector log; public: SFMLGui(GameEngine &g); @@ -37,9 +39,9 @@ public: void handle_events(); void update_entities(); - void update_log(vector &lines); + void update_log(std::vector &lines); - void write_text(int x, int y, std::string content); + void write_text(int x, int y, string content); void ImGui_setup(); void ImGui_update(); diff --git a/tests/game_engine.cpp b/tests/game_engine.cpp index 67959aa..044b094 100644 --- a/tests/game_engine.cpp +++ b/tests/game_engine.cpp @@ -7,7 +7,7 @@ using namespace fmt; TEST_CASE("game engine can start and take hit", "[game_engine]") { // test fails on purpose right now GameEngine game{4}; - string err{"error"}; + std::string err{"error"}; game.start_round(); game.hit(err); game.end_round(); @@ -17,7 +17,7 @@ TEST_CASE("game engine can start and take hit", "[game_engine]") { TEST_CASE("", "[game_engine]") { // test fails on purpose right now GameEngine game{100}; - string err{"error"}; + std::string err{"error"}; game.start_round(); game.hit(err); diff --git a/watcher.cpp b/watcher.cpp index 9a86055..0b9203c 100644 --- a/watcher.cpp +++ b/watcher.cpp @@ -1,13 +1,14 @@ #include "watcher.hpp" #include -using namespace std; + +using std::string; namespace fs = std::filesystem; void UpdateListener::handleFileAction(efsw::WatchID watchid, - const std::string& dir, - const std::string& filename, + const string& dir, + const string& filename, efsw::Action action, - std::string oldFilename) + string oldFilename) { // this is some gnarly BS here, probably tons diff --git a/watcher.hpp b/watcher.hpp index 91b8c6e..d7e614c 100644 --- a/watcher.hpp +++ b/watcher.hpp @@ -3,6 +3,8 @@ #include #include // for operator+, to_string +using std::string; + class UpdateListener : public efsw::FileWatchListener { public: bool changes = false; @@ -11,10 +13,10 @@ class UpdateListener : public efsw::FileWatchListener { UpdateListener(git_repository *r) : repo(r) {}; void handleFileAction(efsw::WatchID watchid, - const std::string& dir, - const std::string& filename, + const string& dir, + const string& filename, efsw::Action action, - std::string oldFilename) override; + string oldFilename) override; void reset_state(); };