mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 weeks ago
11 changed files with 48 additions and 79 deletions
@ -1,35 +0,0 @@ |
|||||
#pragma once |
|
||||
|
|
||||
#include <exception> |
|
||||
|
|
||||
namespace klotski::ffi { |
|
||||
|
|
||||
//class PyCodecExp final : std::exception {
|
|
||||
//public:
|
|
||||
// explicit PyCodecExp(const std::string_view &msg) : msg_(msg) {}
|
|
||||
//
|
|
||||
// ~PyCodecExp() override = default;
|
|
||||
//
|
|
||||
// [[nodiscard]] const char* what() const noexcept override {
|
|
||||
// return msg_.c_str();
|
|
||||
// }
|
|
||||
//
|
|
||||
//private:
|
|
||||
// std::string msg_;
|
|
||||
//};
|
|
||||
|
|
||||
class PyGroupExp final : std::exception { |
|
||||
public: |
|
||||
explicit PyGroupExp(const std::string_view &msg) : msg_(msg) {} |
|
||||
|
|
||||
~PyGroupExp() override = default; |
|
||||
|
|
||||
[[nodiscard]] const char* what() const noexcept override { |
|
||||
return msg_.c_str(); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
std::string msg_; |
|
||||
}; |
|
||||
|
|
||||
} // namespace klotski::ffi
|
|
@ -1,26 +1,26 @@ |
|||||
#include "include/py_group.h" |
#include "include/py_group.h" |
||||
|
|
||||
#include "include/py_exps.h" |
#include "include/py_exception.h" |
||||
|
|
||||
using klotski::ffi::PyGroupExp; |
using klotski::ffi::PyExc_GroupError; |
||||
|
|
||||
using klotski::ffi::PyGroupUnion; |
using klotski::ffi::PyGroupUnion; |
||||
|
|
||||
static klotski::cases::GroupUnion convert(uint8_t type_id) { |
static klotski::group::GroupUnion convert(uint8_t type_id) { |
||||
auto group_union = klotski::cases::GroupUnion::create(type_id); |
auto group_union = klotski::group::GroupUnion::create(type_id); |
||||
if (!group_union.has_value()) { |
if (!group_union.has_value()) { |
||||
throw PyGroupExp(std::format("invalid type id -> {}", type_id)); |
throw PyExc_GroupError(std::format("invalid type id -> {}", type_id)); |
||||
} |
} |
||||
return group_union.value(); |
return group_union.value(); |
||||
} |
} |
||||
|
|
||||
PyGroupUnion::PyGroupUnion(uint8_t type_id) : |
PyGroupUnion::PyGroupUnion(const uint8_t type_id) : |
||||
group_union_(convert(type_id)) {} |
group_union_(convert(type_id)) {} |
||||
|
|
||||
PyGroupUnion::PyGroupUnion(PyShortCode short_code) : |
PyGroupUnion::PyGroupUnion(const PyShortCode short_code) : |
||||
group_union_(GroupUnion::from_short_code(std::bit_cast<ShortCode>(short_code))) {} |
group_union_(GroupUnion::from_short_code(std::bit_cast<ShortCode>(short_code))) {} |
||||
|
|
||||
PyGroupUnion::PyGroupUnion(PyCommonCode common_code) : |
PyGroupUnion::PyGroupUnion(const PyCommonCode common_code) : |
||||
group_union_(GroupUnion::from_common_code(std::bit_cast<CommonCode>(common_code))) {} |
group_union_(GroupUnion::from_common_code(std::bit_cast<CommonCode>(common_code))) {} |
||||
|
|
||||
uint32_t PyGroupUnion::value() const { |
uint32_t PyGroupUnion::value() const { |
Loading…
Reference in new issue