|
| 1 | +/****************************************************************************** |
| 2 | +* SOFA, Simulation Open-Framework Architecture * |
| 3 | +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * |
| 4 | +* * |
| 5 | +* This program is free software; you can redistribute it and/or modify it * |
| 6 | +* under the terms of the GNU Lesser General Public License as published by * |
| 7 | +* the Free Software Foundation; either version 2.1 of the License, or (at * |
| 8 | +* your option) any later version. * |
| 9 | +* * |
| 10 | +* This program is distributed in the hope that it will be useful, but WITHOUT * |
| 11 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * |
| 12 | +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * |
| 13 | +* for more details. * |
| 14 | +* * |
| 15 | +* You should have received a copy of the GNU Lesser General Public License * |
| 16 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | +******************************************************************************* |
| 18 | +* Authors: The SOFA Team and external contributors (see Authors.txt) * |
| 19 | +* * |
| 20 | +* Contact information: contact@sofa-framework.org * |
| 21 | +******************************************************************************/ |
| 22 | +#pragma once |
| 23 | +#include <sofa/testing/config.h> |
| 24 | +#include <sofa/helper/system/PluginManager.h> |
| 25 | + |
| 26 | +namespace sofa::testing |
| 27 | +{ |
| 28 | + |
| 29 | +struct SOFA_TESTING_API ScopedPlugin |
| 30 | +{ |
| 31 | + ScopedPlugin() = delete; |
| 32 | + ScopedPlugin(const ScopedPlugin&) = delete; |
| 33 | + void operator=(const ScopedPlugin&) = delete; |
| 34 | + |
| 35 | + explicit ScopedPlugin( |
| 36 | + const std::string& pluginName, |
| 37 | + helper::system::PluginManager* pluginManager = &helper::system::PluginManager::getInstance()); |
| 38 | + |
| 39 | + template<class InputIt> |
| 40 | + ScopedPlugin( |
| 41 | + InputIt first, InputIt last, |
| 42 | + helper::system::PluginManager* pluginManager = &helper::system::PluginManager::getInstance()) |
| 43 | + : m_pluginManager(pluginManager) |
| 44 | + { |
| 45 | + while (first != last) |
| 46 | + { |
| 47 | + addPlugin(*first++); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + ~ScopedPlugin(); |
| 52 | + |
| 53 | +private: |
| 54 | + helper::system::PluginManager* m_pluginManager { nullptr }; |
| 55 | + |
| 56 | + std::set<std::string> m_loadedPlugins; |
| 57 | + |
| 58 | + void addPlugin(const std::string& pluginName); |
| 59 | +}; |
| 60 | + |
| 61 | + |
| 62 | +inline std::unique_ptr<ScopedPlugin> makeScopedPlugin(const std::initializer_list<std::string>& pluginNames) |
| 63 | +{ |
| 64 | + return std::make_unique<ScopedPlugin>(pluginNames.begin(), pluginNames.end()); |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +} |
0 commit comments