| 65 | } |
| 66 | } |
| 67 | void loadAsync(String filename, const std::function<void(T* item)>& handler) { |
| 68 | std::string fullPath = SharedContent.getFullPath(filename); |
| 69 | auto it = _dict.find(fullPath); |
| 70 | if (it != _dict.end()) { |
| 71 | handler(it->second); |
| 72 | } else { |
| 73 | std::string file(filename.toString()); |
| 74 | SharedContent.loadAsyncUnsafe(file, [this, file, handler](uint8_t* data, int64_t size) { |
| 75 | if (data) { |
| 76 | auto parser = prepareParser(file); |
| 77 | SharedAsyncThread.run( |
| 78 | [this, file, parser, data, size]() { |
| 79 | OwnArray<uint8_t> dataOwner = MakeOwnArray(data); |
| 80 | T* result; |
| 81 | try { |
| 82 | parser->parse(r_cast<char*>(data), s_cast<int>(size)); |
| 83 | result = parser->getItem(); |
| 84 | } catch (rapidxml::parse_error error) { |
| 85 | Error("xml parse error: {}, at: {}", error.what(), error.where<char>() - r_cast<const char*>(data)); |
| 86 | } |
| 87 | return Values::alloc(result); |
| 88 | }, |
| 89 | [this, handler, file](Own<Values> values) { |
| 90 | T* item; |
| 91 | values->get(item); |
| 92 | _dict[file] = item; |
| 93 | handler(item); |
| 94 | }); |
| 95 | } else { |
| 96 | handler(nullptr); |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | } |
| 101 | T* update(String name, String content) { |
| 102 | std::string file = SharedContent.getFullPath(name); |
| 103 | std::string data(content.toString()); |
nothing calls this directly
no test coverage detected