mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-10 10:29:43 +00:00
33 lines
724 B
C
33 lines
724 B
C
|
#pragma once
|
||
|
|
||
|
#include <cstdint>
|
||
|
#include <fstream>
|
||
|
#include <string>
|
||
|
#include <map>
|
||
|
#include <optional>
|
||
|
#include <vector>
|
||
|
#include <utility>
|
||
|
|
||
|
namespace EightBit {
|
||
|
class IntelHexFile {
|
||
|
public:
|
||
|
IntelHexFile(std::string path);
|
||
|
|
||
|
[[nodiscard]] std::map<uint16_t, std::vector<uint8_t>> parse();
|
||
|
|
||
|
private:
|
||
|
[[nodiscard]] std::optional<std::pair<uint16_t, std::vector<uint8_t>>> parse(std::string line);
|
||
|
[[nodiscard]] std::vector<uint8_t> parseDataRecord(std::string line, uint8_t count);
|
||
|
|
||
|
template <class T> T fromHex(std::string input) {
|
||
|
std::istringstream converter(input);
|
||
|
unsigned output;
|
||
|
converter >> std::hex >> output;
|
||
|
return static_cast<T>(output);
|
||
|
}
|
||
|
|
||
|
std::ifstream m_file;
|
||
|
bool m_eof;
|
||
|
};
|
||
|
}
|