GlobalPluginMacros.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 
9 #include <mc_rtc/version.h>
10 
11 /* Set of macros to assist with the writing of a GlobalPlugin */
12 
19 #define MC_RTC_GLOBAL_PLUGIN_CHECK_VERSION(NAME) \
20  if(mc_rtc::MC_RTC_VERSION != mc_rtc::version()) \
21  { \
22  mc_rtc::log::error("{} was compiled with {} but mc_rtc is currently at version {}, you might experience subtle " \
23  "issues and should recompile your code", \
24  NAME, mc_rtc::MC_RTC_VERSION, mc_rtc::version()); \
25  }
26 
27 #ifndef MC_RTC_BUILD_STATIC
28 
29 # define EXPORT_MC_RTC_PLUGIN(NAME, TYPE) \
30  extern "C" \
31  { \
32  GLOBAL_PLUGIN_API void MC_RTC_GLOBAL_PLUGIN(std::vector<std::string> & names) \
33  { \
34  MC_RTC_GLOBAL_PLUGIN_CHECK_VERSION(NAME) \
35  names = {NAME}; \
36  } \
37  \
38  GLOBAL_PLUGIN_API void destroy(mc_control::GlobalPlugin * ptr) \
39  { \
40  delete ptr; \
41  } \
42  \
43  GLOBAL_PLUGIN_API mc_control::GlobalPlugin * create(const std::string &) \
44  { \
45  return new TYPE(); \
46  } \
47  }
48 
49 #else
50 
52 
53 # define EXPORT_MC_RTC_PLUGIN(NAME, TYPE) \
54  namespace \
55  { \
56  static auto registered = []() \
57  { \
58  using fn_t = std::function<TYPE *()>; \
59  mc_control::GlobalPluginLoader::loader().register_object(NAME, fn_t([]() { return new TYPE(); })); \
60  return true; \
61  }(); \
62  }
63 
64 #endif
GlobalPluginLoader.h
GlobalPlugin.h