Skip to content

Commit

Permalink
Fixed consteval error in Error.h
Browse files Browse the repository at this point in the history
  • Loading branch information
BhavyeMathur committed Feb 18, 2024
1 parent bb1c2c9 commit 2269ee4
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 29 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_library(goopylib SHARED ${WINDOWS_SOURCES}
src/goopylib/core/BufferLayout.cpp

src/goopylib/debug/Log.cpp
src/goopylib/debug/Error.cpp

src/goopylib/maths/gpmath.cpp
src/goopylib/maths/Easing.cpp
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/color/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ColorCMYK.h"
#include "ColorHSL.h"
#include "ColorHSV.h"
#include "src/goopylib/debug/Error.h"


// Color Base Class
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/color/ColorCMYK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ColorCMYK.h"
#include "ColorRGB.h"
#include "src/goopylib/debug/Error.h"


// Color CMYK Class
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/color/ColorHSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ColorHSL.h"
#include "ColorHSV.h"
#include "ColorRGB.h"
#include "src/goopylib/debug/Error.h"


namespace gp {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/color/ColorHSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ColorHSV.h"
#include "ColorHSL.h"
#include "ColorRGB.h"
#include "src/goopylib/debug/Error.h"


namespace gp {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/color/ColorHex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ColorHex.h"
#include "ColorRGB.h"
#include "src/goopylib/debug/Error.h"

namespace gp {
int ColorHex::_digitToInt(char digit) {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/core/BufferLayout.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "BufferLayout.h"
#include "src/goopylib/debug/Error.h"


namespace gp {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Core.h"
#include "src/goopylib/core/Window.h"
#include "src/goopylib/debug/Error.h"

#if GP_USING_GLAD
#include <glad/glad.h>
Expand Down
3 changes: 2 additions & 1 deletion src/goopylib/core/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#define GP_LOGGING_LEVEL 3

#include "src/goopylib/core/Window.h"

#include "src/platform/events/MouseCodes.h"

#include "src/goopylib/debug/Error.h"

// TODO check_key should return an int. 0 is released, 1 is pressed, 2 is repeat. (v2.0.x)
// This would involve maintaining an unordered map of key codes to the key state
// Inside GLFW's key callback, this map would be updated
Expand Down
20 changes: 20 additions & 0 deletions src/goopylib/debug/Error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Error.h"

#include "src/goopylib/core/Core.h"

namespace gp {
void setError(ErrorType type, const std::string& message) {
if (isInitialized()) {
GP_CORE_CRITICAL(message);
}

switch (type) {
case ErrorType::ValueError:
throw std::invalid_argument(message);
case ErrorType::RuntimeError:
case ErrorType::FileNotFoundError:
default:
throw std::runtime_error(message);
}
}
}
26 changes: 5 additions & 21 deletions src/goopylib/debug/Error.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
#pragma once

#include "gp.h"
#include "Log.h"

namespace gp {
bool isInitialized();

enum class ErrorType {
RuntimeError,
ValueError,
FileNotFoundError,
};

template<typename... Args>
void setError(ErrorType type, const char *message, Args &&... args) {
if (isInitialized()) {
GP_CORE_CRITICAL(message, std::forward<Args>(args)...);
}

switch (type) {
case ErrorType::ValueError:
throw std::invalid_argument(message);
case ErrorType::RuntimeError:
throw std::runtime_error(message);
case ErrorType::FileNotFoundError:
// Because C++98 (needed for the Python extension) does not have std::filestyle::filestyle_error
throw std::runtime_error(message);
}
}
GPAPI void setError(ErrorType type, const std::string& message);
}

#define GP_RUNTIME_ERROR(...) gp::setError(gp::ErrorType::RuntimeError, __VA_ARGS__)
#define GP_VALUE_ERROR(...) gp::setError(gp::ErrorType::ValueError, __VA_ARGS__)
#define GP_FILENOTFOUND_ERROR(...) gp::setError(gp::ErrorType::FileNotFoundError, __VA_ARGS__)
#define GP_RUNTIME_ERROR(msg, ...) gp::setError(gp::ErrorType::RuntimeError, gp::strformat(msg, __VA_ARGS__))
#define GP_VALUE_ERROR(msg, ...) gp::setError(gp::ErrorType::ValueError, gp::strformat(msg, __VA_ARGS__))
#define GP_FILENOTFOUND_ERROR(msg, ...) gp::setError(gp::ErrorType::FileNotFoundError, strformat(msg, __VA_ARGS__))

#if GP_VALUE_CHECKING
#define GP_CHECK_EQUALS(variable, val, error) if ((variable) != (val)) { GP_VALUE_ERROR(error); }
Expand Down
2 changes: 0 additions & 2 deletions src/goopylib/debug/Log.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "gp.h"

#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
#include <spdlog/sinks/stdout_color_sinks.h>
Expand Down
2 changes: 1 addition & 1 deletion src/goopylib/debug/LogMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
#define GP_TRACE_ALL(...) nullptr
#endif

#include "Error.h"
#include "Log.h"
1 change: 1 addition & 0 deletions src/goopylib/maths/Easing.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define GP_LOGGING_LEVEL 3
#include "Easing.h"
#include "src/goopylib/debug/Error.h"

#define EASE_IN(func, ...) func(t, ##__VA_ARGS__)
#define EASE_OUT(func, ...) (1 - func(1 - t, ##__VA_ARGS__))
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/maths/packing/Shelf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEl 3

#include "Shelf.h"
#include "src/goopylib/debug/Error.h"

#include <cfloat>
#include <utility>
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/objects/Ellipse.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "Ellipse.h"
#include "src/goopylib/debug/Error.h"

// Core Methods
namespace gp {
Expand Down
5 changes: 3 additions & 2 deletions src/goopylib/objects/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#include "Image.h"
#include "src/goopylib/texture/Bitmap.h"
#include <stb/stb_image.h>

#include <utility>
#include "src/goopylib/debug/Error.h"

#include <stb/stb_image.h>


// Core Methods
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/objects/Line.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "Line.h"
#include "src/goopylib/debug/Error.h"

namespace {
Point getLineQuadDeltas(Point p1, Point p2, float thickness) {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/objects/Quad.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "Quad.h"
#include "src/goopylib/debug/Error.h"

// Core Methods
namespace gp {
Expand Down
1 change: 1 addition & 0 deletions src/goopylib/objects/Renderable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "Renderable.h"
#include "src/goopylib/debug/Error.h"

namespace gp {
Renderable::Renderable(Point position, std::initializer_list<Point> points)
Expand Down
2 changes: 2 additions & 0 deletions src/goopylib/scene/RenderingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "src/goopylib/objects/Line.h"
#include "src/goopylib/objects/Image.h"

#include "src/goopylib/debug/Error.h"

namespace gp {
RenderingManager::RenderingManager(const Window &window, int width, int height, const char *title) :
m_Width(width),
Expand Down
2 changes: 2 additions & 0 deletions src/goopylib/texture/Bitmap.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#define GP_LOGGING_LEVEL 3
#include "Bitmap.h"

#include "src/goopylib/debug/Error.h"

#include <stb/stb_image.h>
#include <stb/stb_image_write.h>

Expand Down
1 change: 1 addition & 0 deletions src/platform/GLFW/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define GP_LOGGING_LEVEL 3

#include "src/goopylib/core/Window.h"
#include "src/goopylib/debug/Error.h"

namespace gp {
Window::Window(int width, int height, const char *title)
Expand Down
6 changes: 4 additions & 2 deletions src/platform/OpenGL/Texture2D.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define GP_LOGGING_LEVEL 3

#include "src/goopylib/texture/Texture2D.h"
#include "src/goopylib/texture/Bitmap.h"

#if GP_USING_OPENGL
#include "src/goopylib/debug/Error.h"

#include "src/goopylib/texture/Bitmap.h"
#if GP_USING_OPENGL

#if __APPLE__

Expand Down

0 comments on commit 2269ee4

Please sign in to comment.