From bd576f333e68009445d02f5fb8a20a797e311079 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 8 Jan 2023 21:27:42 +0800 Subject: [PATCH] feat: ShortCode init with mode option --- src/main.cc | 6 ++++-- src/short_code/short_code.h | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main.cc b/src/main.cc index ca0b360..d71133f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -98,10 +98,12 @@ int main() { auto s = ShortCode(14323231); +// auto s = ShortCode(14323231, ShortCode::NORMAL); +// auto s = ShortCode(14323231, ShortCode::FAST); std::cout << s.unwrap() << std::endl; std::cout << s.to_string() << std::endl; - std::cout << ShortCode("EP4HZ").unwrap() << std::endl; - std::cout << ShortCode("eP4hZ").to_string() << std::endl; + std::cout << ShortCode("EP4HZ", ShortCode::NORMAL).unwrap() << std::endl; + std::cout << ShortCode("eP4hZ", ShortCode::FAST).to_string() << std::endl; return 0; } diff --git a/src/short_code/short_code.h b/src/short_code/short_code.h index 9c70989..60b9822 100644 --- a/src/short_code/short_code.h +++ b/src/short_code/short_code.h @@ -10,23 +10,24 @@ public: enum Mode { NORMAL, FAST }; - static enum Mode check_mode(); - static void speed_up(enum Mode mode); - - static bool check(uint32_t short_code); - uint32_t unwrap() const; - std::string to_string() const; + static bool check(uint32_t short_code); + + static enum Mode check_mode(); + static void speed_up(enum Mode mode); explicit ShortCode(uint32_t short_code); explicit ShortCode(const std::string &short_code_str); - - + ShortCode(uint32_t short_code, enum Mode mode) : ShortCode(short_code) { + speed_up(mode); + } + ShortCode(const std::string &short_code_str, enum Mode mode) : ShortCode(short_code_str) { + speed_up(mode); + } private: uint32_t code; - static std::mutex map_building; static bool fast_mode_available; static bool normal_mode_available;