1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin. 2 // Copyright 2015-2019 Antony Polukhin. 3 // 4 // Distributed under the Boost Software License, Version 1.0. 5 // (See accompanying file LICENSE_1_0.txt 6 // or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 #include <iostream> 9 #include <boost/make_shared.hpp> 10 11 // MinGW related workaround 12 #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION 13 14 //[plugcpp_my_plugin_aggregator 15 #include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS 16 #include "../tutorial_common/my_plugin_api.hpp" 17 18 namespace my_namespace { 19 20 class my_plugin_aggregator : public my_plugin_api { 21 float aggr_; my_plugin_aggregator()22 my_plugin_aggregator() : aggr_(0) {} 23 24 public: name() const25 std::string name() const { 26 return "aggregator"; 27 } 28 calculate(float x,float y)29 float calculate(float x, float y) { 30 aggr_ += x + y; 31 return aggr_; 32 } 33 34 // Factory method create()35 static boost::shared_ptr<my_plugin_aggregator> create() { 36 return boost::shared_ptr<my_plugin_aggregator>( 37 new my_plugin_aggregator() 38 ); 39 } 40 }; 41 42 43 BOOST_DLL_ALIAS( 44 my_namespace::my_plugin_aggregator::create, // <-- this function is exported with... 45 create_plugin // <-- ...this alias name 46 ) 47 48 } // namespace my_namespace 49 //] 50 51 52 53