|
17 | 17 |
|
18 | 18 | namespace clp_ffi_js::sfa { |
19 | 19 | using clp_ffi_js::DataArrayTsType; |
| 20 | +using clp_ffi_js::StringArrayTsType; |
20 | 21 |
|
21 | 22 | auto SfaReader::create(DataArrayTsType const& data_array) -> std::unique_ptr<SfaReader> { |
22 | 23 | auto const length{data_array["length"].as<size_t>()}; |
@@ -44,13 +45,41 @@ auto SfaReader::create(DataArrayTsType const& data_array) -> std::unique_ptr<Sfa |
44 | 45 |
|
45 | 46 | return std::unique_ptr<SfaReader>{new SfaReader{std::move(reader_result.value())}}; |
46 | 47 | } |
| 48 | + |
| 49 | +auto SfaReader::get_file_names() const -> StringArrayTsType { |
| 50 | + auto file_names{emscripten::val::array()}; |
| 51 | + for (auto const& file_name : m_reader.get_file_names()) { |
| 52 | + file_names.call<void>("push", emscripten::val(file_name)); |
| 53 | + } |
| 54 | + return StringArrayTsType{file_names}; |
| 55 | +} |
| 56 | + |
| 57 | +auto SfaReader::get_file_infos() const -> FileInfoArrayTsType { |
| 58 | + auto file_infos{emscripten::val::array()}; |
| 59 | + for (auto const& file_info : m_reader.get_file_infos()) { |
| 60 | + auto entry{emscripten::val::object()}; |
| 61 | + entry.set("fileName", emscripten::val(file_info.get_file_name())); |
| 62 | + entry.set("logEventIdxStart", emscripten::val(file_info.get_start_index())); |
| 63 | + entry.set("logEventIdxEnd", emscripten::val(file_info.get_end_index())); |
| 64 | + entry.set("logEventCount", emscripten::val(file_info.get_event_count())); |
| 65 | + file_infos.call<void>("push", entry); |
| 66 | + } |
| 67 | + return FileInfoArrayTsType{file_infos}; |
| 68 | +} |
47 | 69 | } // namespace clp_ffi_js::sfa |
48 | 70 |
|
49 | 71 | EMSCRIPTEN_BINDINGS(SfaReader) { |
| 72 | + emscripten::register_type<clp_ffi_js::sfa::FileInfoArrayTsType>( |
| 73 | + "Array<{fileName: string, logEventIdxStart: bigint, logEventIdxEnd: bigint, " |
| 74 | + "logEventCount: bigint}>" |
| 75 | + ); |
| 76 | + |
50 | 77 | emscripten::class_<clp_ffi_js::sfa::SfaReader>("ClpSfaReader") |
51 | 78 | .constructor( |
52 | 79 | &clp_ffi_js::sfa::SfaReader::create, |
53 | 80 | emscripten::return_value_policy::take_ownership() |
54 | 81 | ) |
55 | | - .function("getEventCount", &clp_ffi_js::sfa::SfaReader::get_event_count); |
| 82 | + .function("getEventCount", &clp_ffi_js::sfa::SfaReader::get_event_count) |
| 83 | + .function("getFileNames", &clp_ffi_js::sfa::SfaReader::get_file_names) |
| 84 | + .function("getFileInfos", &clp_ffi_js::sfa::SfaReader::get_file_infos); |
56 | 85 | } |
0 commit comments