|
@ -17,9 +17,6 @@ std::queue<fast_cal_t*> cache; |
|
|
|
|
|
|
|
|
std::unordered_map<uint64_t, fast_cal_t> cases; |
|
|
std::unordered_map<uint64_t, fast_cal_t> cases; |
|
|
|
|
|
|
|
|
void add_global_demo(uint64_t code) { |
|
|
|
|
|
std::cout << RawCode(code).dump_case() << std::endl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class FastCal; |
|
|
class FastCal; |
|
|
class GlobalCal; |
|
|
class GlobalCal; |
|
@ -27,78 +24,63 @@ class GlobalCal; |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
class CoreDemo { |
|
|
class CoreDemo { |
|
|
public: |
|
|
public: |
|
|
int code{0}; |
|
|
|
|
|
|
|
|
|
|
|
typedef void (T::*release_t)(uint64_t); |
|
|
typedef void (T::*release_t)(uint64_t); |
|
|
|
|
|
|
|
|
// void next(release_t release_func) {
|
|
|
void next(uint64_t code, T *f, release_t release_func) { |
|
|
// release_func(1);
|
|
|
std::cout << "Core get code = " << code << std::endl; |
|
|
// release_func(2);
|
|
|
std::cout << "Core callback first time" << std::endl; |
|
|
// release_func(3);
|
|
|
(f->*release_func)(++code); |
|
|
// ++code;
|
|
|
std::cout << "Core callback second time" << std::endl; |
|
|
// }
|
|
|
(f->*release_func)(++code); |
|
|
|
|
|
std::cout << "Core function exit" << std::endl; |
|
|
void next(T *f, release_t release_func) { |
|
|
|
|
|
|
|
|
|
|
|
(f->*release_func)(1); |
|
|
|
|
|
|
|
|
|
|
|
// release_func(2);
|
|
|
|
|
|
// release_func(3);
|
|
|
|
|
|
++code; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FastCal { |
|
|
class FastCal { |
|
|
public: |
|
|
public: |
|
|
int dat; |
|
|
uint64_t data; |
|
|
|
|
|
|
|
|
void add(uint64_t code) { |
|
|
explicit FastCal(uint64_t dat) : data(dat) {} |
|
|
std::cout << RawCode(code).dump_case() << std::endl; |
|
|
|
|
|
++dat; |
|
|
void callback(uint64_t code) { |
|
|
|
|
|
std::cout << "FastCal get callback " << code << std::endl; |
|
|
|
|
|
data = code; |
|
|
|
|
|
std::cout << "FastCal set data " << data << std::endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void run() { |
|
|
void run() { |
|
|
auto cd = CoreDemo<FastCal>(); |
|
|
auto cd = CoreDemo<FastCal>(); |
|
|
|
|
|
|
|
|
// cd.next(add_global_demo);
|
|
|
std::cout << "FastCal data = " << data << std::endl; |
|
|
// cd.next(this->*add);
|
|
|
|
|
|
|
|
|
|
|
|
cd.next(this, &FastCal::add); |
|
|
|
|
|
|
|
|
|
|
|
++dat; |
|
|
cd.next(data, this, &FastCal::callback); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GlobalCal { |
|
|
class GlobalCal { |
|
|
public: |
|
|
public: |
|
|
int dat; |
|
|
uint64_t data; |
|
|
|
|
|
|
|
|
|
|
|
explicit GlobalCal(uint64_t dat) : data(dat) {} |
|
|
|
|
|
|
|
|
void add(uint64_t code) { |
|
|
void callback(uint64_t code) { |
|
|
std::cout << RawCode(code).dump_case() << std::endl; |
|
|
std::cout << "GlobalCal get callback " << code << std::endl; |
|
|
++dat; |
|
|
data = code; |
|
|
|
|
|
std::cout << "GlobalCal set data " << data << std::endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void run() { |
|
|
void run() { |
|
|
auto cd = CoreDemo<GlobalCal>(); |
|
|
auto cd = CoreDemo<GlobalCal>(); |
|
|
|
|
|
|
|
|
cd.next(this, &GlobalCal::add); |
|
|
std::cout << "GlobalCal data = " << data << std::endl; |
|
|
|
|
|
|
|
|
++dat; |
|
|
cd.next(data, this, &GlobalCal::callback); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
//void (FastCal::*ptrStaticFun)(uint64_t) = &FastCal::add;
|
|
|
|
|
|
//release_t ptrFun = &FastCal::add;
|
|
|
|
|
|
|
|
|
|
|
|
//void demo() {
|
|
|
|
|
|
// auto f = new FastCal();
|
|
|
|
|
|
// (f->*ptrFun)(1);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
void add_new_case(uint64_t code, uint64_t mask) { |
|
|
void add_new_case(uint64_t code, uint64_t mask) { |
|
|
|
|
|
|
|
@ -129,12 +111,18 @@ void add_new_case(uint64_t code, uint64_t mask) { |
|
|
|
|
|
|
|
|
uint32_t fast_cal(uint64_t code) { |
|
|
uint32_t fast_cal(uint64_t code) { |
|
|
|
|
|
|
|
|
auto f = FastCal(); |
|
|
auto f1 = FastCal(1000); |
|
|
f.run(); |
|
|
auto f2 = FastCal(2000); |
|
|
|
|
|
auto g = GlobalCal(3000); |
|
|
|
|
|
|
|
|
auto g = GlobalCal(); |
|
|
f2.run(); |
|
|
|
|
|
f1.run(); |
|
|
|
|
|
f1.run(); |
|
|
g.run(); |
|
|
g.run(); |
|
|
|
|
|
|
|
|
|
|
|
// auto g = GlobalCal();
|
|
|
|
|
|
// g.run();
|
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|