Improve code
This commit is contained in:
@@ -10,17 +10,22 @@ namespace FileProcessor {
|
||||
};
|
||||
|
||||
struct Configuration;
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&, bool);
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||
|
||||
struct Configuration {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
const uint32_t* data_adr = nullptr;
|
||||
size_t data_size = 0ull;
|
||||
size_t data_word_size = 0ull;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&, bool), const uint32_t* data_adr) {
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
|
||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void processed(size_t words) {
|
||||
this->data_adr += words;
|
||||
this->data_word_size -= words;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -28,15 +33,15 @@ namespace FileProcessor {
|
||||
Reserved reserved;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&, bool)) {
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
|
||||
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
||||
static_assert(sizeof(T) <= sizeof(Reserved));
|
||||
}
|
||||
|
||||
public:
|
||||
bool process(size_t size, bool is_last) {
|
||||
this->config.data_size += size;
|
||||
return (*this->config.process_routine)(this->config, this->reserved, is_last);
|
||||
bool process(size_t word_size) {
|
||||
this->config.data_word_size += word_size;
|
||||
return (*this->config.process_routine)(this->config, this->reserved);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user