diff --git a/src/common_code/common_code.cc b/src/common_code/common_code.cc index 7a8d646..3a3101e 100644 --- a/src/common_code/common_code.cc +++ b/src/common_code/common_code.cc @@ -6,6 +6,10 @@ uint64_t CommonCode::unwrap() const { return code; // raw uint64_t code } +bool CommonCode::valid() const { + return CommonCode::check(code); +} + CommonCode CommonCode::create(uint64_t common_code) { return CommonCode(common_code); // create from uint64_t } @@ -23,6 +27,10 @@ CommonCode::CommonCode(uint64_t common_code) { code = common_code; } +bool CommonCode::operator==(const CommonCode &common_code) const { + return this->code == common_code.code; +} + std::ostream& operator<<(std::ostream &out, const CommonCode &self) { char str[10]; sprintf(str, "%09lX", self.code); diff --git a/src/common_code/common_code.h b/src/common_code/common_code.h index 1f4e502..cbf1d5d 100644 --- a/src/common_code/common_code.h +++ b/src/common_code/common_code.h @@ -11,8 +11,12 @@ class ShortCode; class CommonCode { public: + bool valid() const; static bool check(uint64_t common_code); + + /// Operators of CommonCode explicit operator uint64_t() const { return code; } + bool operator==(const CommonCode &common_code) const; friend std::ostream& operator<<(std::ostream &out, const CommonCode &self); /// Export functions diff --git a/src/short_code/short_code.cc b/src/short_code/short_code.cc index e4c441f..6bdb385 100644 --- a/src/short_code/short_code.cc +++ b/src/short_code/short_code.cc @@ -5,6 +5,10 @@ uint32_t ShortCode::unwrap() const { return code; // raw uint32_t code } +bool ShortCode::valid() const { + return ShortCode::check(code); +} + ShortCode ShortCode::create(uint32_t short_code) { return ShortCode(short_code); } @@ -20,6 +24,10 @@ bool ShortCode::check(uint32_t short_code) { return short_code < SHORT_CODE_LIMIT; // 0 ~ (SHORT_CODE_LIMIT - 1) } +bool ShortCode::operator==(const ShortCode &short_code) const { + return this->code == short_code.code; +} + std::ostream& operator<<(std::ostream &out, const ShortCode &self) { out << self.to_string() << "(" << self.code << ")"; // short code info return out; diff --git a/src/short_code/short_code.h b/src/short_code/short_code.h index 3eea502..01ecde1 100644 --- a/src/short_code/short_code.h +++ b/src/short_code/short_code.h @@ -13,9 +13,13 @@ class ShortCode { public: enum Mode {NORMAL, FAST}; + bool valid() const; static void speed_up(enum Mode mode); static bool check(uint32_t short_code); + + /// Operators of ShortCode explicit operator uint32_t() const { return code; } + bool operator==(const ShortCode &short_code) const; friend std::ostream& operator<<(std::ostream &out, const ShortCode &self); /// Export functions