From 0cabf92b00b1996c4ef055340c51b1e47032b57b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 14 Apr 2023 20:34:28 +0800 Subject: [PATCH] update: using Exp instead of Exception --- src/klotski_core/common_code/common_code.cc | 2 +- src/klotski_core/common_code/common_code.h | 8 ++++---- src/klotski_core/common_code/serialize.cc | 8 ++++---- src/klotski_core/raw_code/convert.cc | 2 +- src/klotski_core/raw_code/raw_code.cc | 2 +- src/klotski_core/raw_code/raw_code.h | 8 ++++---- src/klotski_core/short_code/serialize.cc | 10 +++++----- src/klotski_core/short_code/short_code.cc | 2 +- src/klotski_core/short_code/short_code.h | 8 ++++---- test/codec/common_code.cc | 2 +- test/codec/short_code.cc | 2 +- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/klotski_core/common_code/common_code.cc b/src/klotski_core/common_code/common_code.cc index 57ceeb6..4736822 100644 --- a/src/klotski_core/common_code/common_code.cc +++ b/src/klotski_core/common_code/common_code.cc @@ -21,7 +21,7 @@ CommonCode CommonCode::unsafe_create(uint64_t common_code) noexcept { // create CommonCode::CommonCode(uint64_t common_code) { if (!CommonCode::check(common_code)) { // check input common code - throw klotski::CommonCodeException("common code invalid"); + throw klotski::CommonCodeExp("common code invalid"); } code_ = common_code; } diff --git a/src/klotski_core/common_code/common_code.h b/src/klotski_core/common_code/common_code.h index 4f7ad87..09da66f 100644 --- a/src/klotski_core/common_code/common_code.h +++ b/src/klotski_core/common_code/common_code.h @@ -63,11 +63,11 @@ namespace klotski { class RawCode; class ShortCode; -class CommonCodeException : public std::runtime_error { +class CommonCodeExp : public std::runtime_error { public: - CommonCodeException() : std::runtime_error("invalid common code") {} - explicit CommonCodeException(const std::string &msg) : std::runtime_error(msg) {} - ~CommonCodeException() noexcept override = default; + CommonCodeExp() : std::runtime_error("invalid common code") {} + explicit CommonCodeExp(const std::string &msg) : std::runtime_error(msg) {} + ~CommonCodeExp() noexcept override = default; }; class CommonCode { diff --git a/src/klotski_core/common_code/serialize.cc b/src/klotski_core/common_code/serialize.cc index 7e92dcf..fbfadb3 100644 --- a/src/klotski_core/common_code/serialize.cc +++ b/src/klotski_core/common_code/serialize.cc @@ -1,7 +1,7 @@ #include "common_code.h" using klotski::CommonCode; -using klotski::CommonCodeException; +using klotski::CommonCodeExp; /// -------------------------- CommonCode to String --------------------------- @@ -60,7 +60,7 @@ std::string CommonCode::string_encode(uint64_t common_code, bool shorten) noexce uint64_t CommonCode::string_decode(const std::string &common_code) { // convert from (1 ~ 9)-bit string /// check string length if (common_code.length() > 9 || common_code.empty()) { // check string length - throw CommonCodeException("common code should length 1 ~ 9"); + throw CommonCodeExp("common code should length 1 ~ 9"); } /// check every characters @@ -74,14 +74,14 @@ uint64_t CommonCode::string_decode(const std::string &common_code) { // convert } else if (bit >= 'a' && bit <= 'f') { // a ~ f result |= (bit - 87); } else { - throw CommonCodeException("common code with invalid character"); // unknown character + throw CommonCodeExp("common code with invalid character"); // unknown character } } result <<= (9 - common_code.length()) * 4; // low-bits fill with zero /// check whether common code is valid if (!CommonCode::check(result)) { // check converted common code - throw CommonCodeException("common code invalid"); + throw CommonCodeExp("common code invalid"); } return result; } diff --git a/src/klotski_core/raw_code/convert.cc b/src/klotski_core/raw_code/convert.cc index 20f3d89..9bdc2b2 100644 --- a/src/klotski_core/raw_code/convert.cc +++ b/src/klotski_core/raw_code/convert.cc @@ -3,7 +3,7 @@ using klotski::RawCode; using klotski::CommonCode; -using klotski::RawCodeException; +using klotski::RawCodeExp; /// -------------------------- RawCode to CommonCode -------------------------- diff --git a/src/klotski_core/raw_code/raw_code.cc b/src/klotski_core/raw_code/raw_code.cc index 2c87a1c..14d596c 100644 --- a/src/klotski_core/raw_code/raw_code.cc +++ b/src/klotski_core/raw_code/raw_code.cc @@ -19,7 +19,7 @@ RawCode RawCode::unsafe_create(uint64_t raw_code) noexcept { // create without c RawCode::RawCode(uint64_t raw_code) { if (!RawCode::check(raw_code)) { // check input raw code - throw klotski::RawCodeException("raw code invalid"); + throw klotski::RawCodeExp("raw code invalid"); } code_ = raw_code; } diff --git a/src/klotski_core/raw_code/raw_code.h b/src/klotski_core/raw_code/raw_code.h index 605a912..bd88e5c 100644 --- a/src/klotski_core/raw_code/raw_code.h +++ b/src/klotski_core/raw_code/raw_code.h @@ -47,11 +47,11 @@ namespace klotski { class CommonCode; -class RawCodeException : public std::runtime_error { +class RawCodeExp : public std::runtime_error { public: - RawCodeException() : std::runtime_error("invalid raw code") {} - explicit RawCodeException(const std::string &msg) : std::runtime_error(msg) {} - ~RawCodeException() noexcept override = default; + RawCodeExp() : std::runtime_error("invalid raw code") {} + explicit RawCodeExp(const std::string &msg) : std::runtime_error(msg) {} + ~RawCodeExp() noexcept override = default; }; class RawCode { diff --git a/src/klotski_core/short_code/serialize.cc b/src/klotski_core/short_code/serialize.cc index e502f15..dacaca9 100644 --- a/src/klotski_core/short_code/serialize.cc +++ b/src/klotski_core/short_code/serialize.cc @@ -2,7 +2,7 @@ #include "serialize_chars.h" using klotski::ShortCode; -using klotski::ShortCodeException; +using klotski::ShortCodeExp; /// --------------------------- ShortCode to String --------------------------- @@ -42,7 +42,7 @@ std::string ShortCode::string_encode(uint32_t short_code) noexcept { // encode a uint32_t ShortCode::string_decode(const std::string &short_code) { // 5-bits string decode if (short_code.length() != 5) { // check string length - throw ShortCodeException("short code should length 5"); + throw ShortCodeExp("short code should length 5"); } uint64_t result = 0; for (auto bit : short_code) { @@ -51,15 +51,15 @@ uint32_t ShortCode::string_decode(const std::string &short_code) { // 5-bits str bit -= 32; // convert to uppercase } if (bit < '1' || bit > 'Z') { // invalid characters - throw ShortCodeException("short code with invalid character"); + throw ShortCodeExp("short code with invalid character"); } result += (bit = SHORT_CODE_TABLE_REV[bit - 49]); // table convert if (bit == -1) { // invalid character - throw ShortCodeException("short code with invalid character"); + throw ShortCodeExp("short code with invalid character"); } } if (!ShortCode::check(result)) { // check converted short code - throw ShortCodeException("short code invalid"); + throw ShortCodeExp("short code invalid"); } return result; // apply convert result } diff --git a/src/klotski_core/short_code/short_code.cc b/src/klotski_core/short_code/short_code.cc index 99df07a..b744bc9 100644 --- a/src/klotski_core/short_code/short_code.cc +++ b/src/klotski_core/short_code/short_code.cc @@ -22,7 +22,7 @@ ShortCode ShortCode::unsafe_create(uint32_t short_code) noexcept { // create wit ShortCode::ShortCode(uint32_t short_code) { if (!ShortCode::check(short_code)) { // check input short code - throw klotski::ShortCodeException("short code invalid"); + throw klotski::ShortCodeExp("short code invalid"); } code_ = short_code; } diff --git a/src/klotski_core/short_code/short_code.h b/src/klotski_core/short_code/short_code.h index 9a69e1b..da139be 100644 --- a/src/klotski_core/short_code/short_code.h +++ b/src/klotski_core/short_code/short_code.h @@ -62,11 +62,11 @@ class CommonCode; const uint32_t SHORT_CODE_LIMIT = 29334498; -class ShortCodeException : public std::runtime_error { +class ShortCodeExp : public std::runtime_error { public: - ShortCodeException() : std::runtime_error("invalid short code") {} - explicit ShortCodeException(const std::string &msg) : std::runtime_error(msg) {} - ~ShortCodeException() noexcept override = default; + ShortCodeExp() : std::runtime_error("invalid short code") {} + explicit ShortCodeExp(const std::string &msg) : std::runtime_error(msg) {} + ~ShortCodeExp() noexcept override = default; }; /// For ShortCode, you must choose at least one mode (NORMAL or FAST) to convert, and diff --git a/test/codec/common_code.cc b/test/codec/common_code.cc index 169dec3..31b6476 100644 --- a/test/codec/common_code.cc +++ b/test/codec/common_code.cc @@ -17,7 +17,7 @@ static inline void SHOULD_PANIC(const std::function &func) { bool panic_flag = false; try { func(); - } catch (klotski::CommonCodeException&) { + } catch (klotski::CommonCodeExp &) { panic_flag = true; } EXPECT_EQ(panic_flag, true); diff --git a/test/codec/short_code.cc b/test/codec/short_code.cc index 6f5df8b..a88635d 100644 --- a/test/codec/short_code.cc +++ b/test/codec/short_code.cc @@ -20,7 +20,7 @@ static inline void SHOULD_PANIC(const std::function &func) { bool panic_flag = false; try { func(); - } catch (klotski::ShortCodeException&) { + } catch (klotski::ShortCodeExp &) { panic_flag = true; } EXPECT_EQ(panic_flag, true);