59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#ifndef __JABYENGINE_FILE_PROCESSOR_HPP__
|
|
#define __JABYENGINE_FILE_PROCESSOR_HPP__
|
|
#include "../../Auxiliary/types.hpp"
|
|
#include "../file_types.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace FileProcessor {
|
|
class State {
|
|
private:
|
|
struct Reserved {
|
|
uint32_t reserved[4];
|
|
};
|
|
|
|
struct Configuration;
|
|
|
|
template<typename T>
|
|
using GenericProcessRoutine = Progress (*)(Configuration&, T&);
|
|
|
|
typedef GenericProcessRoutine<Reserved> ProcessRoutine;
|
|
|
|
struct Configuration {
|
|
ProcessRoutine process_routine = nullptr;
|
|
const uint8_t* data_adr = nullptr;
|
|
size_t data_bytes = 0ull;
|
|
|
|
template<typename T>
|
|
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) {
|
|
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
|
}
|
|
|
|
constexpr void processed(size_t bytes) {
|
|
this->data_adr += bytes;
|
|
this->data_bytes -= bytes;
|
|
}
|
|
};
|
|
|
|
private:
|
|
Configuration config;
|
|
Reserved reserved;
|
|
|
|
template<typename T>
|
|
static __always_inline State from(const T& reserved, const uint8_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:
|
|
Progress process(size_t bytes_ready) {
|
|
this->config.data_bytes += bytes_ready;
|
|
return (*this->config.process_routine)(this->config, this->reserved);
|
|
}
|
|
};
|
|
|
|
// The nothing state
|
|
State create(const uint32_t* data_adr, const Nothing& nothing);
|
|
State create(const uint32_t* data_adr, const SimpleTIM& file);
|
|
}
|
|
}
|
|
#endif // !__JABYENGINE_FILE_PROCESSOR_HPP__
|