Improves return types with Progress type
This commit is contained in:
@@ -1,7 +1,32 @@
|
||||
#ifndef __JABYENGINE_LZ4_DECOMPRESSOR_HPP__
|
||||
#define __JABYENGINE_LZ4_DECOMPRESSOR_HPP__
|
||||
#include "../../stddef.h"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
class LZ4Decompressor {
|
||||
public:
|
||||
enum struct Result {
|
||||
InProgress = 0,
|
||||
Done,
|
||||
Error
|
||||
};
|
||||
|
||||
private:
|
||||
struct State {};
|
||||
|
||||
private:
|
||||
uint8_t* dst_adr = nullptr;
|
||||
State state;
|
||||
|
||||
public:
|
||||
LZ4Decompressor() = default;
|
||||
|
||||
void setup(uint8_t* dst_adr);
|
||||
void reset();
|
||||
|
||||
Progress process(const uint8_t* data, size_t size);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_LZ4_DECOMPRESSOR_HPP__
|
12
include/PSX/Auxiliary/types.hpp
Normal file
12
include/PSX/Auxiliary/types.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __JABYENGINE_TYPES_HPP__
|
||||
#define __JABYENGINE_TYPES_HPP__
|
||||
|
||||
namespace JabyEngine {
|
||||
enum struct Progress {
|
||||
InProgress = 0,
|
||||
Done,
|
||||
Error
|
||||
};
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_TYPES_HPP__
|
@@ -1,5 +1,6 @@
|
||||
#ifndef __JABYENGINE_FILE_PROCESSOR_HPP__
|
||||
#define __JABYENGINE_FILE_PROCESSOR_HPP__
|
||||
#include "../../Auxiliary/types.hpp"
|
||||
#include "../file_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
@@ -11,7 +12,11 @@ namespace JabyEngine {
|
||||
};
|
||||
|
||||
struct Configuration;
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||
|
||||
template<typename T>
|
||||
using GenericProcessRoutine = Progress (*)(Configuration&, T&);
|
||||
|
||||
typedef GenericProcessRoutine<Reserved> ProcessRoutine;
|
||||
|
||||
struct Configuration {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
@@ -19,7 +24,7 @@ namespace JabyEngine {
|
||||
size_t data_word_size = 0ull;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
|
||||
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint32_t* data_adr) {
|
||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||
}
|
||||
|
||||
@@ -34,13 +39,13 @@ namespace JabyEngine {
|
||||
Reserved reserved;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, GenericProcessRoutine<T> process_routine) {
|
||||
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
||||
static_assert(sizeof(T) <= sizeof(Reserved));
|
||||
}
|
||||
|
||||
public:
|
||||
bool process(size_t word_size) {
|
||||
Progress 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