From 3150b865ffd9847bb3a279d5a96a1adcf90873e0 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 17 Jan 2023 02:40:40 +0800 Subject: [PATCH] feat: ostream support for CommonCode --- src/common_code/common_code.cc | 7 +++++++ src/common_code/common_code.h | 3 ++- src/main.cc | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common_code/common_code.cc b/src/common_code/common_code.cc index 237a10c..2a3f273 100644 --- a/src/common_code/common_code.cc +++ b/src/common_code/common_code.cc @@ -47,6 +47,13 @@ CommonCode::CommonCode(const ShortCode &short_code) { // load from short code code = short_code.to_common_code().code; } +std::ostream& operator<<(std::ostream &out, const CommonCode &self) { + char str[10]; + sprintf(str, "%09lX", self.code); + out << str; + return out; +} + bool CommonCode::check(uint64_t common_code) { // whether common code is valid /// M_1x1 M_1x2 M_2x1 M_2x2 /// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 diff --git a/src/common_code/common_code.h b/src/common_code/common_code.h index 65f1cdc..abfab35 100644 --- a/src/common_code/common_code.h +++ b/src/common_code/common_code.h @@ -2,6 +2,7 @@ #include #include +#include #include "raw_code.h" #include "short_code.h" @@ -16,7 +17,7 @@ public: std::string to_string(bool shorten = false) const; static bool check(uint64_t common_code); - // TODO: std::cout << CommonCode(...) + friend std::ostream& operator<<(std::ostream &out, const CommonCode &self); explicit CommonCode(uint64_t common_code); explicit CommonCode(const RawCode &raw_code); diff --git a/src/main.cc b/src/main.cc index 21f44bc..61454ec 100644 --- a/src/main.cc +++ b/src/main.cc @@ -360,6 +360,7 @@ int main() { // std::cout << CommonCode(0x4FEA13400).to_string() << std::endl; printf("%09lX\n", CommonCode::from_string("1a9bf0c").unwrap()); + std::cout << CommonCode("4feA134") << std::endl; // std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;