-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfdt-parser.hpp
54 lines (42 loc) · 1.34 KB
/
fdt-parser.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <fdt/fdt-header.hpp>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include <QByteArray>
#include <QString>
struct fdt_property {
QString name;
QByteArray data;
auto clear() noexcept {
name.clear();
data.clear();
}
};
struct iface_fdt_generator {
virtual void begin_node(const QString &name) noexcept = 0;
virtual void end_node() noexcept = 0;
virtual void insert_property(const fdt_property &property) noexcept = 0;
};
using fdt_property_callback = std::function<void(const fdt_property &property, iface_fdt_generator &generator)>;
struct fdt_handle_special_property {
QString name;
fdt_property_callback callback;
};
class fdt_parser {
public:
fdt_parser(const char *data, u64 size, iface_fdt_generator &generator,
const QString &default_root_node = {},
const std::vector<fdt_handle_special_property> &handle_special_properties = {});
constexpr bool is_valid() noexcept { return m_header.has_value(); }
private:
void parse(const fdt_header header, iface_fdt_generator &generator);
private:
std::optional<fdt_header> m_header;
const QString m_default_root_node;
const std::vector<fdt_handle_special_property> &m_handle_special_properties;
const char *const m_data;
const u64 m_size;
};