Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
refactor: update return type syntax and add braces for code clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed Jun 27, 2024
1 parent 0a8f81b commit 4b6e0ef
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 82 deletions.
5 changes: 3 additions & 2 deletions src/crc32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cstddef>
#include <cstdint>

constexpr std::array<uint32_t, 256> generate_table() {
constexpr auto generate_table() -> std::array<uint32_t, 256> {
std::array<uint32_t, 256> table;

for (uint32_t i = 0; i < 256; i++) {
Expand All @@ -24,7 +24,8 @@ constexpr std::array<uint32_t, 256> generate_table() {
return table;
}

constexpr uint32_t crc32(uint32_t initial, const void* buf, size_t len) {
constexpr auto
crc32(uint32_t initial, const void* buf, size_t len) -> uint32_t {
constexpr auto table = generate_table();

uint32_t c = initial ^ 0xFFFFFFFF;
Expand Down
26 changes: 14 additions & 12 deletions src/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class Database {
*
* @param path XSB 格式文件路径.
*/
std::vector<Level> import_levels_from_file(const std::filesystem::path& path
) {
auto import_levels_from_file(const std::filesystem::path& path
) -> std::vector<Level> {
const auto levels = Level::load(path);
for (const auto& level : levels)
import_level(level);
Expand All @@ -98,7 +98,7 @@ class Database {
*
* @param level 关卡.
*/
std::optional<int> get_level_id(const Level& level) {
auto get_level_id(const Level& level) -> std::optional<int> {
SQLite::Statement query_id(
database_,
"SELECT id FROM tb_level "
Expand All @@ -115,7 +115,7 @@ class Database {
*
* @param id 关卡 ID.
*/
std::optional<Level> get_level_by_id(int id) {
auto get_level_by_id(int id) -> std::optional<Level> {
SQLite::Statement query_level(
database_,
"SELECT title, author, map, solution FROM tb_level "
Expand Down Expand Up @@ -144,7 +144,8 @@ class Database {
* @param level_id 关卡 ID.
* @param solution 关卡答案.
*/
bool update_level_solution(int level_id, const std::string& solution) {
auto
update_level_solution(int level_id, const std::string& solution) -> bool {
SQLite::Statement update_solution(
database_,
"UPDATE tb_level "
Expand All @@ -165,7 +166,7 @@ class Database {
*
* @param level 已通关的关卡.
*/
bool update_level_solution(const Level& level) {
auto update_level_solution(const Level& level) -> bool {
assert(level.passed());
return update_level_solution(
get_level_id(level).value(),
Expand All @@ -178,7 +179,8 @@ class Database {
*
* @param level_id 关卡 ID.
*/
bool update_session_movement(int level_id, const std::string& movement) {
auto
update_session_movement(int level_id, const std::string& movement) -> bool {
SQLite::Statement update_movements(
database_,
"UPDATE tb_session "
Expand All @@ -195,7 +197,7 @@ class Database {
*
* @param level 关卡.
*/
bool update_session_movement(const Level& level) {
auto update_session_movement(const Level& level) -> bool {
return update_session_movement(
get_level_id(level).value(),
level.movement()
Expand All @@ -207,7 +209,7 @@ class Database {
*
* @param level 关卡.
*/
bool upsert_level_session(const Level& level) {
auto upsert_level_session(const Level& level) -> bool {
return upsert_level_session(get_level_id(level).value());
}

Expand All @@ -216,7 +218,7 @@ class Database {
*
* @param level_id 关卡 ID.
*/
bool upsert_level_session(int level_id) {
auto upsert_level_session(int level_id) -> bool {
SQLite::Statement upsert_history(
database_,
"INSERT OR IGNORE INTO tb_session(level_id, datetime) "
Expand All @@ -230,7 +232,7 @@ class Database {
/**
* @brief 获取历史最新会话关卡 ID.
*/
std::optional<int> get_latest_level_id() {
auto get_latest_level_id() -> std::optional<int> {
SQLite::Statement query_latest_history(
database_,
"SELECT level_id FROM tb_session "
Expand All @@ -247,7 +249,7 @@ class Database {
*
* @param level 关卡.
*/
std::string get_level_session_movements(const Level& level) {
auto get_level_session_movements(const Level& level) -> std::string {
SQLite::Statement query_movements(
database_,
"SELECT movement FROM tb_session "
Expand Down
Loading

0 comments on commit 4b6e0ef

Please sign in to comment.