Browse Source

feat: more RawCode and CommonCode convert interface

master
Dnomd343 2 years ago
parent
commit
362b4842b3
  1. 12
      src/common_code/common_code.cc
  2. 6
      src/common_code/common_code.h
  3. 2
      src/main.cc
  4. 3
      src/raw_code/raw_code.h

12
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) {

6
src/common_code/common_code.h

@ -2,8 +2,10 @@
#include <string>
#include <cstdint>
#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);

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

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

Loading…
Cancel
Save