LCOV - code coverage report
Current view: top level - lunchbox - plugin.h (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 9 9 100.0 %
Date: 2017-08-03 05:21:41 Functions: 6 6 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2013-2016, EPFL/Blue Brain Project
       3             :  *                          Raphael Dumusc <raphael.dumusc@epfl.ch>
       4             :  *                          Stefan.Eilemann@epfl.ch
       5             :  *
       6             :  * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
       7             :  *
       8             :  * This library is free software; you can redistribute it and/or modify it under
       9             :  * the terms of the GNU Lesser General Public License version 2.1 as published
      10             :  * by the Free Software Foundation.
      11             :  *
      12             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      13             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      14             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      15             :  * details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public License
      18             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      19             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      20             :  */
      21             : 
      22             : #ifndef LUNCHBOX_PLUGIN_H
      23             : #define LUNCHBOX_PLUGIN_H
      24             : 
      25             : #include <functional>
      26             : #include <servus/uint128_t.h> // member
      27             : 
      28             : namespace lunchbox
      29             : {
      30             : /** @internal */
      31             : template <class T>
      32          14 : class Plugin
      33             : {
      34             : public:
      35             :     /** The constructor method for Plugin objects.  @version 1.11.0 */
      36             :     using Constructor = std::function<T*(const typename T::InitDataT&)>;
      37             : 
      38             :     /**
      39             :      * The method to check if the plugin can handle a given initData.
      40             :      * @version 1.11.0
      41             :      */
      42             :     using HandlesFunc = std::function<bool(const typename T::InitDataT&)>;
      43             : 
      44             :     /** The method to get the plugin's description. @version 1.16 */
      45             :     using DescriptionFunc = std::function<std::string()>;
      46             : 
      47             :     /**
      48             :      * Construct a new Plugin.
      49             :      * @param constructor The constructor method for Plugin objects.
      50             :      * @param handles_ The method to check if the plugin can handle the
      51             :      * initData.
      52             :      * @param description method to get the the help for the plugin
      53             :      * @version 1.11.0
      54             :      */
      55           4 :     Plugin(const Constructor& constructor, const HandlesFunc& handles_,
      56             :            const DescriptionFunc& description)
      57             :         : _constructor(constructor)
      58             :         , _handles(handles_)
      59           4 :         , _description(description)
      60             :     {
      61           4 :     }
      62             : 
      63             :     /** Construct a new plugin instance. @version 1.14 */
      64           2 :     T* construct(const typename T::InitDataT& data) const
      65             :     {
      66           2 :         return _constructor(data);
      67             :     }
      68             : 
      69             :     /** @return true if this plugin handles the given request. @version 1.14 */
      70           4 :     bool handles(const typename T::InitDataT& data) const
      71             :     {
      72           4 :         return _handles(data);
      73             :     }
      74             : 
      75             :     /** @return the plugin's description. @version 1.17 */
      76           3 :     std::string getDescription() const { return _description(); }
      77             : private:
      78             :     Constructor _constructor;
      79             :     HandlesFunc _handles;
      80             :     DescriptionFunc _description;
      81             : 
      82             :     bool operator==(const Plugin& rhs) const = delete;
      83             :     bool operator!=(const Plugin& rhs) const = delete;
      84             : };
      85             : }
      86             : 
      87             : #endif

Generated by: LCOV version 1.11