MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / replaceDefinitions

Method replaceDefinitions

Libraries/Plugin/Plugin.cpp:885–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

883}
884
885SC::Result SC::PluginRegistry::replaceDefinitions(Span<PluginDefinition>&& definitions)
886{
887 FixedVector<PluginIdentifier, 16> librariesToUnload;
888 // Unload libraries that have no match in the definitions
889 for (PluginDynamicLibrary& item : libraries)
890 {
891 StringSpan libraryId = item.definition.identity.identifier.view();
892
893 bool found = false;
894 for (auto& it : definitions)
895 {
896 if (it.identity.identifier.view() == libraryId)
897 {
898 found = true;
899 break;
900 }
901 }
902 if (not found)
903 {
904 SC_TRY(librariesToUnload.push_back(item.definition.identity.identifier));
905 }
906 }
907
908 for (auto& identifier : librariesToUnload)
909 {
910 SC_TRY(unloadPlugin(identifier.view()));
911 PluginDynamicLibrary* plugin = findPlugin(identifier.view());
912 if (plugin)
913 {
914 if (libraries.empty())
915 {
916 *plugin = {};
917 }
918 else
919 {
920 *plugin = move(libraries[libraries.sizeInElements() - 1]);
921 libraries = {libraries.data(), libraries.sizeInElements() - 1};
922 }
923 }
924 }
925
926 for (PluginDefinition& definition : definitions)
927 {
928 PluginDynamicLibrary pdl;
929 pdl.definition = move(definition);
930 PluginDynamicLibrary* plugin = findPlugin(pdl.definition.identity.identifier.view());
931 if (plugin == nullptr)
932 {
933 SC_TRY_MSG(libraries.sizeInElements() < storage.sizeInElements(),
934 "Exceeded number of Plugins storage space");
935 libraries = {storage.data(), libraries.sizeInElements() + 1};
936
937 libraries[libraries.sizeInElements() - 1] = move(pdl);
938 }
939 }
940 definitions = {};
941 return Result(true);
942}

Callers 3

PluginTestMethod · 0.80
syncRegistryMethod · 0.80
syncRegistryMethod · 0.80

Calls 4

ResultClass · 0.50
viewMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by 2

PluginTestMethod · 0.64
syncRegistryMethod · 0.64