From 9ca2320b86b23e7409cea7d242f722849a789a4d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 17 Jan 2023 20:38:59 +0800 Subject: [PATCH] feat: ostream for RawCode --- src/main.cc | 2 +- src/raw_code/raw_code.cc | 7 +++++++ src/raw_code/raw_code.h | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index cb2507c..55642db 100644 --- a/src/main.cc +++ b/src/main.cc @@ -425,7 +425,7 @@ int main() { // std::cout << RawCode(RawCode::extract(0x0000FF004)).dump_case() << std::endl; // std::cout << RawCode::extract(0x555a4001) << std::endl; - std::cout << RawCode::create(CommonCode(0x4FEA13400).to_raw_code().unwrap()).dump_case() << std::endl; + std::cout << RawCode::create(CommonCode(0x4FEA13400).to_raw_code().unwrap()) << std::endl; std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl; // std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; diff --git a/src/raw_code/raw_code.cc b/src/raw_code/raw_code.cc index 5481843..96946c4 100644 --- a/src/raw_code/raw_code.cc +++ b/src/raw_code/raw_code.cc @@ -23,6 +23,13 @@ RawCode::RawCode(uint64_t raw_code) { code = raw_code; } +std::ostream& operator<<(std::ostream &out, const RawCode &self) { + char str[16]; + sprintf(str, "%015lX", self.code); + out << str; + return out; +} + std::string RawCode::dump_case() const { // TODO: using stack char * std::string result; diff --git a/src/raw_code/raw_code.h b/src/raw_code/raw_code.h index 7e6d140..1ea6289 100644 --- a/src/raw_code/raw_code.h +++ b/src/raw_code/raw_code.h @@ -14,7 +14,7 @@ public: CommonCode to_common_code() const; static bool check(uint64_t raw_code); -// friend std::ostream& operator<<(std::ostream &out, const RawCode &self); + friend std::ostream& operator<<(std::ostream &out, const RawCode &self); explicit RawCode(uint64_t raw_code); explicit RawCode(const CommonCode &common_code);