|
1
|
1 #pragma once
|
|
|
2
|
|
|
3 #pragma once
|
|
|
4 #include <mutex>
|
|
|
5 #include <vector>
|
|
|
6 #include <SDK/metadb_callbacks.h>
|
|
|
7
|
|
|
8 class metadb_io_callback_v2_data_impl : public metadb_io_callback_v2_data {
|
|
|
9 metadb_handle_list_cref m_items;
|
|
|
10 pfc::array_t< metadb_v2_rec_t> m_data;
|
|
|
11 std::once_flag m_once;
|
|
|
12 public:
|
|
|
13 metadb_io_callback_v2_data_impl(metadb_handle_list_cref items) : m_items(items) {}
|
|
|
14 metadb_v2_rec_t get(size_t idxInList) override {
|
|
|
15 // Late init, don't hammer metadb if nobody cares
|
|
|
16 // Maybe this should be offthread somehow?? Kick off early, stall till done once asked?
|
|
|
17 std::call_once(m_once, [&] { m_data = metadb_v2::get()->queryMultiSimple(m_items); });
|
|
|
18 PFC_ASSERT(m_data.size() == m_items.get_size());
|
|
|
19 PFC_ASSERT(idxInList < m_data.size());
|
|
|
20 return m_data[idxInList];
|
|
|
21 }
|
|
|
22 };
|
|
|
23
|
|
|
24 class metadb_io_callback_v2_data_wrap : public metadb_io_callback_v2_data {
|
|
|
25 public:
|
|
|
26 metadb_io_callback_v2_data_wrap(metadb_io_callback_v2_data& chain) : m_chain(chain) {}
|
|
|
27 metadb_io_callback_v2_data& m_chain;
|
|
|
28 std::vector<size_t> m_mapping;
|
|
|
29
|
|
|
30 metadb_v2_rec_t get(size_t idxInList) override {
|
|
|
31 PFC_ASSERT(idxInList < m_mapping.size());
|
|
|
32 return m_chain[m_mapping[idxInList]];
|
|
|
33 }
|
|
|
34 };
|
|
|
35
|
|
|
36 class metadb_io_callback_v2_data_mirror : public metadb_io_callback_v2_data {
|
|
|
37 public:
|
|
|
38 metadb_v2_rec_t get(size_t idxInList) override {return m_data[idxInList];}
|
|
|
39
|
|
|
40 metadb_io_callback_v2_data_mirror() {}
|
|
|
41 metadb_io_callback_v2_data_mirror(metadb_io_callback_v2_data& source, size_t size) {
|
|
|
42 init(source, size);
|
|
|
43 }
|
|
|
44 void init(metadb_io_callback_v2_data& source, size_t size) {
|
|
|
45 m_data.set_size_discard(size);
|
|
|
46 for (size_t w = 0; w < size; ++w) m_data[w] = source[w];
|
|
|
47 }
|
|
|
48 private:
|
|
|
49 pfc::array_t< metadb_v2_rec_t> m_data;
|
|
|
50 }; |