MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / LoadFromPath

Method LoadFromPath

src/PluginSegmentation.cpp:434–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432 }
433
434 static std::shared_ptr<PluginLibrary> LoadFromPath(const std::string& path,
435 const std::string& type) {
436 std::shared_ptr<SharedLibrary> library(new SharedLibrary(path));
437 typedef const opencc_segmentation_plugin_v2* (*EntryPoint)(void);
438 EntryPoint entryPoint = reinterpret_cast<EntryPoint>(
439 library->FindSymbol("opencc_get_segmentation_plugin_v2"));
440 const opencc_segmentation_plugin_v2* descriptor = entryPoint();
441 if (descriptor == nullptr) {
442 throw Exception("Plugin returned null descriptor.");
443 }
444 if (descriptor->struct_size < RequiredDescriptorSize()) {
445 throw Exception("Plugin descriptor is too small.");
446 }
447 if (descriptor->abi_major != OPENCC_SEGMENTATION_PLUGIN_ABI_MAJOR) {
448 throw Exception("Plugin ABI major version mismatch.");
449 }
450 if (descriptor->abi_minor < OPENCC_SEGMENTATION_PLUGIN_ABI_MINOR) {
451 throw Exception("Plugin ABI minor version is older than required by the host.");
452 }
453 if (descriptor->segmentation_type == nullptr ||
454 type != descriptor->segmentation_type) {
455 throw Exception("Plugin type mismatch.");
456 }
457 std::shared_ptr<PluginLibrary> plugin(new PluginLibrary);
458 plugin->library = library;
459 plugin->descriptor = descriptor;
460 return plugin;
461 }
462
463 std::mutex mutex_;
464 std::unordered_map<std::string, std::shared_ptr<PluginLibrary>> cache_;

Callers

nothing calls this directly

Calls 3

RequiredDescriptorSizeFunction · 0.85
FindSymbolMethod · 0.80
ExceptionFunction · 0.70

Tested by

no test coverage detected