Browse Source

feat: ostream support for CommonCode

legacy
Dnomd343 2 years ago
parent
commit
3150b865ff
  1. 7
      src/common_code/common_code.cc
  2. 3
      src/common_code/common_code.h
  3. 1
      src/main.cc

7
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; 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 bool CommonCode::check(uint64_t common_code) { // whether common code is valid
/// M_1x1 M_1x2 M_2x1 M_2x2 /// M_1x1 M_1x2 M_2x1 M_2x2
/// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 /// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0

3
src/common_code/common_code.h

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <cstdint> #include <cstdint>
#include <ostream>
#include "raw_code.h" #include "raw_code.h"
#include "short_code.h" #include "short_code.h"
@ -16,7 +17,7 @@ public:
std::string to_string(bool shorten = false) const; std::string to_string(bool shorten = false) const;
static bool check(uint64_t common_code); 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(uint64_t common_code);
explicit CommonCode(const RawCode &raw_code); explicit CommonCode(const RawCode &raw_code);

1
src/main.cc

@ -360,6 +360,7 @@ int main() {
// std::cout << CommonCode(0x4FEA13400).to_string() << std::endl; // std::cout << CommonCode(0x4FEA13400).to_string() << std::endl;
printf("%09lX\n", CommonCode::from_string("1a9bf0c").unwrap()); 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) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;

Loading…
Cancel
Save