diff --git a/src/common_code/common_code.cc b/src/common_code/common_code.cc index 709bdfe..6cef632 100644 --- a/src/common_code/common_code.cc +++ b/src/common_code/common_code.cc @@ -12,6 +12,10 @@ uint64_t CommonCode::unwrap() const { // get raw uint64_t code return code; } +RawCode CommonCode::to_raw_code() const { // convert to raw code + return RawCode(*this); +} + ShortCode CommonCode::to_short_code() const { // convert to short code return ShortCode(*this); } @@ -29,8 +33,12 @@ CommonCode::CommonCode(uint64_t common_code) { code = common_code; } -CommonCode::CommonCode(const ShortCode &short_code) { - code = short_code.to_common_code().unwrap(); // init from short code +CommonCode::CommonCode(const RawCode &raw_code) { // init from raw code + code = raw_code.to_common_code().code; +} + +CommonCode::CommonCode(const ShortCode &short_code) { // init from short code + code = short_code.to_common_code().code; } CommonCode::CommonCode(const std::string &common_code_str) { diff --git a/src/common_code/common_code.h b/src/common_code/common_code.h index 928bb50..0f5cf6c 100644 --- a/src/common_code/common_code.h +++ b/src/common_code/common_code.h @@ -2,8 +2,10 @@ #include #include +#include "raw_code.h" #include "short_code.h" +class RawCode; class ShortCode; class CommonCode { @@ -12,12 +14,12 @@ public: static bool check(uint64_t common_code); static CommonCode unsafe_create(uint64_t code); - // TODO: to raw code function + RawCode to_raw_code() const; ShortCode to_short_code() const; std::string to_string(bool shorten = false) const; explicit CommonCode(uint64_t common_code); - // TODO: init with const RawCode& + explicit CommonCode(const RawCode &raw_code); explicit CommonCode(const ShortCode &short_code); explicit CommonCode(const std::string &common_code_str); diff --git a/src/main.cc b/src/main.cc index 54dd94b..e5e098c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -142,5 +142,7 @@ int main() { next_step(0x0E58FC85FFEBC4DB, 0); // mask unset + std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl; + return 0; } diff --git a/src/raw_code/raw_code.h b/src/raw_code/raw_code.h index 5320ab5..d6c8037 100644 --- a/src/raw_code/raw_code.h +++ b/src/raw_code/raw_code.h @@ -20,6 +20,8 @@ #define F_2x1 (uint64_t)0x7007 // 111 000 000 000 111 #define F_2x2 (uint64_t)0x3F03F // 111 111 000 000 111 111 +class CommonCode; + class RawCode { public: uint64_t unwrap() const; @@ -31,5 +33,4 @@ public: private: uint64_t code; - };