LCOV - code coverage report
Current view: top level - lunchbox - plugin.h (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 3 3 100.0 %
Date: 2015-07-07 14:54:45 Functions: 6 6 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2013-2015, 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 <servus/uint128_t.h> // member
      26             : #include <boost/function.hpp> // Plugin functions
      27             : #include <boost/function_equal.hpp> // operator ==
      28             : 
      29             : namespace lunchbox
      30             : {
      31             : /**
      32             :  * Manages a class deriving from a PluginT interface.
      33             :  *
      34             :  * Plugin classes deriving from PluginT must implement the following
      35             :  * prototype for their constructor:
      36             :  * @code
      37             :  * DerivedPluginClass( const InitDataT& initData );
      38             :  * @endcode
      39             :  *
      40             :  * PluginT must also implement the following method to be registered:
      41             :  * @code
      42             :  * static bool handles( const InitDataT& initData );
      43             :  * @endcode
      44             :  *
      45             :  * @version 1.11.0
      46             :  */
      47          28 : template< class PluginT, class InitDataT = servus::URI > class Plugin
      48             : {
      49             : public:
      50             :     /**
      51             :      * The constructor method / concrete factory for Plugin objects.
      52             :      * @version 1.11.0
      53             :      */
      54             :     typedef boost::function< PluginT* ( const InitDataT& ) > Constructor;
      55             : 
      56             :     /**
      57             :      * The method to check if the plugin can handle a given initData.
      58             :      * @version 1.11.0
      59             :      */
      60             :     typedef boost::function< bool ( const InitDataT& ) > HandlesFunc;
      61             : 
      62             :     /**
      63             :      * Construct a new Plugin.
      64             :      * @param constructor_ The constructor method for Plugin objects.
      65             :      * @param handles_ The method to check if the plugin can handle the
      66             :      * initData.
      67             :      * @version 1.11.0
      68             :      */
      69           8 :     Plugin( const Constructor& constructor_, const HandlesFunc& handles_ )
      70             :         : constructor( constructor_ ), handles( handles_ )
      71           8 :         , tag( servus::make_UUID( )) {}
      72             : 
      73             :     /** @return true if the plugins wrap the same plugin. @version 1.11.0 */
      74             :     bool operator == ( const Plugin& rhs ) const
      75             :         { return tag == rhs.tag; }
      76             : 
      77             :     /** @return false if the plugins do wrap the same plugin. @version 1.11.0 */
      78             :     bool operator != ( const Plugin& rhs ) const { return !(*this == rhs); }
      79             : 
      80             : private:
      81             :     friend class PluginFactory< PluginT, InitDataT >;
      82             :     Constructor constructor;
      83             :     HandlesFunc handles;
      84             : 
      85             :     // Makes Plugin comparable. See http://stackoverflow.com/questions/18665515
      86             :     servus::uint128_t tag;
      87             : };
      88             : 
      89             : }
      90             : 
      91             : #endif

Generated by: LCOV version 1.11