-
Notifications
You must be signed in to change notification settings - Fork 1
[BALDE-87] Implement error handling system. #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BIGbadEL
wants to merge
14
commits into
master
Choose a base branch
from
BALDE_87_Implement_error_handling_system
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f3a8db
Created expected abstraction.
BIGbadEL f58c3e9
refactor to code to use expected.
BIGbadEL 38585d7
fixed event system
BIGbadEL 43ab01d
reformat and error handling
BIGbadEL 879ce55
added error handling in shaders
BIGbadEL 8b7f5bf
added bald_asserts to ensure correct use of expected class
BIGbadEL e4f5e9f
Merge branch 'master' into BALDE_87_Implement_error_handling_system
BIGbadEL fca8464
deleted error
BIGbadEL a58b3d1
Update file_manager.cpp
BIGbadEL 5948005
attempt to use our texture class
BIGbadEL 710ae2e
Merge remote-tracking branch 'origin/BALDE_87_Implement_error_handlin…
BIGbadEL 655df37
added system that prevents accessing result of expected without calli…
BIGbadEL 6bf57ab
Merge branch 'master' into BALDE_87_Implement_error_handling_system
BIGbadEL e1e23d0
added apple macro in file_manager.cpp
BIGbadEL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #version 330 | ||
|
|
||
| void main() { | ||
| gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #version 330 | ||
|
|
||
| layout (location = 0) in vec3 in_Position; | ||
|
|
||
| void main() { | ||
| gl_Position = vec4(in_Position, 1.0); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // | ||
| // Created by grzegorz on 18.09.19. | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <utility> | ||
| #include "unexpected.h" | ||
| #include "bald_assert.h" | ||
|
|
||
|
|
||
| namespace Bald { | ||
| template<typename E, typename U> | ||
| class expected { | ||
| public: | ||
| constexpr expected() { new(&m_Valid) E(); } | ||
|
|
||
| constexpr expected(const E& rhs) { new(&m_Valid) E(rhs); } | ||
|
|
||
| constexpr expected(const unexpected<U>& rhs) : | ||
| _isOk(false) { new(&m_Invalid) U(rhs.value); } | ||
|
|
||
| constexpr expected(E&& rhs) { new(&m_Valid) E(std::move(rhs)); } | ||
|
|
||
| constexpr expected(unexpected<U>&& rhs) : | ||
| _isOk(false) { new(&m_Invalid) U(std::move(rhs.m_Value)); } | ||
|
|
||
| constexpr expected(const expected<E, U>& rhs) : | ||
| _isOk(rhs._isOk) { | ||
| if (_isOk) new(&m_Valid) E(rhs.m_Valid); | ||
| else new(&m_Invalid) U(rhs.m_Invalid); | ||
| } | ||
|
|
||
| constexpr expected(expected<E, U>&& rhs) noexcept : | ||
| _isOk(rhs._isOk) { | ||
| if (_isOk) new(&m_Valid) E(std::move(rhs.m_Valid)); | ||
| else new(&m_Invalid) U(std::move(rhs.m_Invalid)); | ||
| } | ||
|
|
||
| constexpr expected<E, U>& operator=(const expected<E, U>& rhs) { | ||
| if(this == &rhs) return *this; | ||
| dtor(); | ||
| _isOk = rhs._isOk; | ||
| if (_isOk) new(&m_Valid) E(rhs.m_Valid); | ||
| else new(&m_Invalid) U(rhs.m_Invalid); | ||
| return *this; | ||
| } | ||
|
|
||
| constexpr expected<E, U>& operator=(expected<E, U>&& rhs) noexcept { | ||
| if(this == &rhs) return *this; | ||
| dtor(); | ||
| _isOk = rhs._isOk; | ||
| if (_isOk) new(&m_Valid) E(std::move(rhs.m_Valid)); | ||
| else new(&m_Invalid) U(std::move(rhs.m_Invalid)); | ||
| return *this; | ||
| } | ||
|
|
||
| ~expected() { | ||
| dtor(); | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr bool isValid() const noexcept { | ||
| #ifdef DEBUG | ||
| m_WasChecked = true; | ||
| #endif | ||
| return _isOk; | ||
| } | ||
|
|
||
| constexpr operator bool() const noexcept { | ||
| #ifdef DEBUG | ||
| m_WasChecked = true; | ||
| #endif | ||
| return _isOk; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr U& error() const& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(!_isOk, "expected", "attempt to access invalid value after success", _isOk); | ||
| return m_Invalid; | ||
| } | ||
|
|
||
| [[nodiscard]] U& error()& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(!_isOk, "expected", "attempt to access invalid value after success", _isOk); | ||
| return m_Invalid; | ||
| } | ||
|
|
||
| [[nodiscard]] U&& error()&& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(!_isOk, "expected", "attempt to access invalid value after success", _isOk); | ||
| return std::move(m_Invalid); | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr E& value() const& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(_isOk, "expected", "attempt to access valid value after failure", _isOk); | ||
| return m_Valid; | ||
| } | ||
|
|
||
| [[nodiscard]] E& value()& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(_isOk, "expected", "attempt to access valid value after failure", _isOk); | ||
| return m_Valid; | ||
| } | ||
|
|
||
| [[nodiscard]] E&& value()&& { | ||
| BALD_ASSERT(m_WasChecked, "expected", "attempt to access value without calling isValid method", m_WasChecked); | ||
| BALD_ASSERT(_isOk, "expected", "attempt to access valid value after failure", _isOk); | ||
| return std::move(m_Valid); | ||
| } | ||
|
|
||
| private: | ||
| void dtor() const noexcept { | ||
| if (_isOk) m_Valid.~E(); | ||
| else m_Invalid.~U(); | ||
| } | ||
|
|
||
| private: | ||
| union { | ||
| E m_Valid; | ||
| U m_Invalid; | ||
| }; | ||
| #ifdef DEBUG | ||
| mutable bool m_WasChecked = false; | ||
| #endif | ||
| bool _isOk = true; | ||
| }; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // | ||
| // Created by grzegorz on 18.09.19. | ||
| // | ||
| #pragma once | ||
|
|
||
| namespace Bald { | ||
| template <typename T> | ||
| struct unexpected { | ||
| constexpr explicit unexpected(const T& val): m_Value(val) { } | ||
| constexpr operator T() const noexcept { return m_Value; } | ||
| T m_Value; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.