my_plugin_aggregator.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <iostream>
  8. #include <boost/make_shared.hpp>
  9. // MinGW related workaround
  10. #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
  11. //[plugcpp_my_plugin_aggregator
  12. #include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
  13. #include "../tutorial_common/my_plugin_api.hpp"
  14. namespace my_namespace {
  15. class my_plugin_aggregator : public my_plugin_api {
  16. float aggr_;
  17. my_plugin_aggregator() : aggr_(0) {}
  18. public:
  19. std::string name() const {
  20. return "aggregator";
  21. }
  22. float calculate(float x, float y) {
  23. aggr_ += x + y;
  24. return aggr_;
  25. }
  26. // Factory method
  27. static boost::shared_ptr<my_plugin_aggregator> create() {
  28. return boost::shared_ptr<my_plugin_aggregator>(
  29. new my_plugin_aggregator()
  30. );
  31. }
  32. };
  33. BOOST_DLL_ALIAS(
  34. my_namespace::my_plugin_aggregator::create, // <-- this function is exported with...
  35. create_plugin // <-- ...this alias name
  36. )
  37. } // namespace my_namespace
  38. //]