FREE_IMAGE_FORMAT PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, const char *description, const char *extension, const char *regexpr) { if (init_proc != NULL) { PluginNode *node = new(std::nothrow) PluginNode; Plugin *plugin = new(std::nothrow) Plugin; if(!node || !plugin) { if(node) delete node; if(plugin) delete plugin; FreeImage_OutputMessageProc(FIF_UNKNOWN, FI_MSG_ERROR_MEMORY); return FIF_UNKNOWN; } memset(plugin, 0, sizeof(Plugin)); // fill-in the plugin structure // note we have memset to 0, so all unset pointers should be NULL) init_proc(plugin, (int)m_plugin_map.size()); // get the format string (two possible ways) const char *the_format = NULL; if (format != NULL) { the_format = format; } else if (plugin->format_proc != NULL) { the_format = plugin->format_proc(); } // add the node if it wasn't there already if (the_format != NULL) { node->m_id = (int)m_plugin_map.size(); node->m_instance = instance; node->m_plugin = plugin; node->m_format = format; node->m_description = description; node->m_extension = extension; node->m_regexpr = regexpr; node->m_enabled = TRUE; m_plugin_map[(const int)m_plugin_map.size()] = node; return (FREE_IMAGE_FORMAT)node->m_id; } // something went wrong while allocating the plugin... cleanup delete plugin; delete node; } return FIF_UNKNOWN; }
FREE_IMAGE_FORMAT PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, const char *description, const char *extension, const char *regexpr) { if (init_proc != NULL) { PluginNode *node = new PluginNode; Plugin *plugin = new Plugin; memset(plugin, 0, sizeof(Plugin)); // fill-in the plugin structure init_proc(plugin, m_plugin_map.size()); // get the format string (two possible ways) const char *the_format = NULL; if (format != NULL) the_format = format; else if (plugin->format_proc != NULL) the_format = plugin->format_proc(); // add the node if it wasn't there already if (the_format != NULL) { if (FindNodeFromFormat(the_format) == NULL) { node->m_id = m_plugin_map.size(); node->m_instance = instance; node->m_plugin = plugin; node->m_format = format; node->m_description = description; node->m_extension = extension; node->m_regexpr = regexpr; node->m_next = NULL; node->m_enabled = TRUE; m_plugin_map[m_plugin_map.size()] = node; return (FREE_IMAGE_FORMAT)node->m_id; } } // something went wrong while allocating the plugin... cleanup delete plugin; delete node; } return FIF_UNKNOWN; }