my_plugin_sum.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. //[plugcpp_my_plugin_sum
  9. #include <boost/config.hpp> // for BOOST_SYMBOL_EXPORT
  10. #include "../tutorial_common/my_plugin_api.hpp"
  11. namespace my_namespace {
  12. class my_plugin_sum : public my_plugin_api {
  13. public:
  14. my_plugin_sum() {
  15. std::cout << "Constructing my_plugin_sum" << std::endl;
  16. }
  17. std::string name() const {
  18. return "sum";
  19. }
  20. float calculate(float x, float y) {
  21. return x + y;
  22. }
  23. ~my_plugin_sum() {
  24. std::cout << "Destructing my_plugin_sum ;o)" << std::endl;
  25. }
  26. };
  27. // Exporting `my_namespace::plugin` variable with alias name `plugin`
  28. // (Has the same effect as `BOOST_DLL_ALIAS(my_namespace::plugin, plugin)`)
  29. extern "C" BOOST_SYMBOL_EXPORT my_plugin_sum plugin;
  30. my_plugin_sum plugin;
  31. } // namespace my_namespace
  32. //]