Browse Source

feat: ShortCode init with mode option

master
Dnomd343 2 years ago
parent
commit
bd576f333e
  1. 6
      src/main.cc
  2. 19
      src/short_code/short_code.h

6
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;
}

19
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;

Loading…
Cancel
Save