From 5376efe7e63ef3c848a971ea845a16c7e030d153 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 1 Nov 2024 17:38:33 +0100 Subject: move Exception to backend --- backend/CMakeLists.txt | 1 + backend/Exception.cpp | 22 ++++++++++++++++++++++ backend/Exception.h | 14 ++++++++++++++ frontend/CMakeLists.txt | 1 - frontend/DB.cpp | 3 ++- frontend/Exception.cpp | 22 ---------------------- frontend/Exception.h | 15 --------------- frontend/GameController.cpp | 2 +- frontend/cmd/equip.cpp | 2 +- frontend/cmd/get.cpp | 2 +- frontend/cmd/go.cpp | 2 +- frontend/cmd/hit.cpp | 2 +- frontend/cmd/put.cpp | 2 +- frontend/cmd/view.cpp | 2 +- frontend/generate_dungeon.cpp | 2 +- frontend/load_dungeon.cpp | 2 +- frontend/main.cpp | 2 +- 17 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 backend/Exception.cpp create mode 100644 backend/Exception.h delete mode 100644 frontend/Exception.cpp delete mode 100644 frontend/Exception.h diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index e0c377b..b7e8996 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -15,5 +15,6 @@ target_sources(main PUBLIC String.cpp print.cpp Player.cpp + Exception.cpp ) diff --git a/backend/Exception.cpp b/backend/Exception.cpp new file mode 100644 index 0000000..4044d6a --- /dev/null +++ b/backend/Exception.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include "backend/String.h" + +#include "Exception.h" + +using namespace std; + +const char * Exception::what() { + return this->error.c_str(); +} + +Exception::Exception(const char * fmt, ...) { + va_list args; + va_start(args, fmt); + this->error = String::va_fmt(args, fmt); + va_end(args); +} + diff --git a/backend/Exception.h b/backend/Exception.h new file mode 100644 index 0000000..bc65aa0 --- /dev/null +++ b/backend/Exception.h @@ -0,0 +1,14 @@ +#pragma once + +#include "backend/String.h" + +class Exception { +public: + Exception(const char * fmt, ...); + const char * what(); + +protected: + Exception() = default; + String error; +}; + diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt index 4248eb5..8f086d3 100644 --- a/frontend/CMakeLists.txt +++ b/frontend/CMakeLists.txt @@ -5,7 +5,6 @@ target_sources(main PUBLIC GameController.cpp load_dungeon.cpp generate_dungeon.cpp - Exception.cpp DB.cpp GameData.cpp ) diff --git a/frontend/DB.cpp b/frontend/DB.cpp index d51315b..f40a9fd 100644 --- a/frontend/DB.cpp +++ b/frontend/DB.cpp @@ -1,5 +1,6 @@ +#include "backend/Exception.h" + #include "DB.h" -#include "Exception.h" using namespace std; diff --git a/frontend/Exception.cpp b/frontend/Exception.cpp deleted file mode 100644 index c852f0a..0000000 --- a/frontend/Exception.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include - -#include "backend/String.h" - -#include "Exception.h" - -using namespace std; - -const char * Exception::what() { - return this->error.get(); -} - -Exception::Exception(const char * fmt, ...) { - va_list args; - va_start(args, fmt); - this->error = unique_ptr(strdup(String::va_fmt(args, fmt).c_str())); - va_end(args); -} - diff --git a/frontend/Exception.h b/frontend/Exception.h deleted file mode 100644 index 3bbced2..0000000 --- a/frontend/Exception.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -class Exception : public std::exception { -public: - Exception(const char * fmt, ...); - const char * what(); - -protected: - Exception() = default; - std::unique_ptr error; -}; - diff --git a/frontend/GameController.cpp b/frontend/GameController.cpp index bbdd0c1..f160006 100644 --- a/frontend/GameController.cpp +++ b/frontend/GameController.cpp @@ -4,8 +4,8 @@ #include "GameData.h" #include "strings.h" #include "GameController.h" -#include "Exception.h" +#include "backend/Exception.h" #include "backend/print.h" #include "backend/WeaponObject.h" #include "backend/Dungeon.h" diff --git a/frontend/cmd/equip.cpp b/frontend/cmd/equip.cpp index 578db0e..238d287 100644 --- a/frontend/cmd/equip.cpp +++ b/frontend/cmd/equip.cpp @@ -1,9 +1,9 @@ #include "backend/ListIterator.h" #include "backend/Dungeon.h" +#include "backend/Exception.h" #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" using namespace std; diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp index 358bf1f..dd098d1 100644 --- a/frontend/cmd/get.cpp +++ b/frontend/cmd/get.cpp @@ -2,8 +2,8 @@ #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" +#include "backend/Exception.h" #include "backend/print.h" #include "backend/GoldObject.h" #include "backend/Location.h" diff --git a/frontend/cmd/go.cpp b/frontend/cmd/go.cpp index 5fd7c93..185d727 100644 --- a/frontend/cmd/go.cpp +++ b/frontend/cmd/go.cpp @@ -1,10 +1,10 @@ #include "backend/Location.h" #include "backend/print.h" #include "backend/Dungeon.h" +#include "backend/Exception.h" #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" using namespace std; diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp index 677bf4e..8491758 100644 --- a/frontend/cmd/hit.cpp +++ b/frontend/cmd/hit.cpp @@ -3,10 +3,10 @@ #include "backend/RNG.h" #include "backend/print.h" #include "backend/Dungeon.h" +#include "backend/Exception.h" #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" using namespace std; diff --git a/frontend/cmd/put.cpp b/frontend/cmd/put.cpp index 35de352..be3bcca 100644 --- a/frontend/cmd/put.cpp +++ b/frontend/cmd/put.cpp @@ -1,7 +1,7 @@ #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" +#include "backend/Exception.h" #include "backend/print.h" #include "backend/Location.h" #include "backend/Dungeon.h" diff --git a/frontend/cmd/view.cpp b/frontend/cmd/view.cpp index 0f4f3d1..bd9e99b 100644 --- a/frontend/cmd/view.cpp +++ b/frontend/cmd/view.cpp @@ -1,7 +1,7 @@ #include "../GameController.h" #include "../strings.h" -#include "../Exception.h" +#include "backend/Exception.h" #include "backend/print.h" #include "backend/Location.h" #include "backend/Dungeon.h" diff --git a/frontend/generate_dungeon.cpp b/frontend/generate_dungeon.cpp index 868fe43..6e34673 100644 --- a/frontend/generate_dungeon.cpp +++ b/frontend/generate_dungeon.cpp @@ -2,11 +2,11 @@ #include "backend/Dungeon.h" #include "backend/print.h" +#include "backend/Exception.h" #include "rl.h" #include "generate_dungeon.h" #include "GameData.h" -#include "Exception.h" using namespace std; diff --git a/frontend/load_dungeon.cpp b/frontend/load_dungeon.cpp index c671fe7..0388387 100644 --- a/frontend/load_dungeon.cpp +++ b/frontend/load_dungeon.cpp @@ -6,10 +6,10 @@ #include "backend/Location.h" #include "backend/LocationFactory.h" +#include "backend/Exception.h" #include "backend/Dungeon.h" #include "load_dungeon.h" -#include "Exception.h" #include "GameData.h" #include "backend/Object.h" #include "strings.h" diff --git a/frontend/main.cpp b/frontend/main.cpp index 64b4474..94e60c3 100644 --- a/frontend/main.cpp +++ b/frontend/main.cpp @@ -1,7 +1,7 @@ #include "backend/print.h" +#include "backend/Exception.h" #include "GameController.h" -#include "Exception.h" using namespace std; -- cgit v1.2.3