mc_rtc  2.16.0
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  { delete ptr; } \
40  \
41  GLOBAL_PLUGIN_API mc_control::GlobalPlugin * create(const std::string &) \
42  { return new TYPE(); } \
43  }
44 
45 #else
46 
48 
49 # define EXPORT_MC_RTC_PLUGIN(NAME, TYPE) \
50  namespace \
51  { \
52  static auto registered = []() \
53  { \
54  using fn_t = std::function<TYPE *()>; \
55  mc_control::GlobalPluginLoader::loader().register_object(NAME, fn_t([]() { return new TYPE(); })); \
56  return true; \
57  }(); \
58  }
59 
60 #endif