Gazebo Common

API Reference

4.7.0
gz/common/PluginMacros.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 
19 #ifndef IGNITION_COMMON_REGISTERMACROS_HH_
20 #define IGNITION_COMMON_REGISTERMACROS_HH_
21 
22 #include <gz/common/config.hh>
23 #include "gz/common/detail/PluginMacros.hh"
24 
25 // --------------- Specialize a plugin interface (optional) -------------------
26 
53 #define IGN_COMMON_SPECIALIZE_INTERFACE(interfaceName)\
54  DETAIL_IGN_COMMON_SPECIALIZE_INTERFACE(interfaceName)
55 
56 
57 // ------------- Add a set of plugins or a set of interfaces ------------------
58 
59 // The following three macros can be used to produce multiple plugins and/or
60 // multiple interfaces from your shared library.
61 
62 /* Usage example for multiple plugins and one interface:
63  *
64  * IGN_COMMON_BEGIN_ADDING_PLUGINS
65  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass1, mylibrary::ns::SomeInterface)
66  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass2, mylibrary::ns::SomeInterface)
67  * IGN_COMMON_FINISH_ADDING_PLUGINS
68  *
69  *
70  * Usage example for one plugin and multiple interfaces:
71  *
72  * IGN_COMMON_BEGIN_ADDING_PLUGINS
73  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::Interface1)
74  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::Interface2)
75  * IGN_COMMON_FINISH_ADDING_PLUGINS
76  *
77  *
78  * Usage example for multiple plugins and multiple interfaces:
79  *
80  * IGN_COMMON_BEGIN_ADDING_PLUGINS
81  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::FooInterface)
82  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::BarInterface)
83  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::SomeInterface)
84  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::FooInterface)
85  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::SomeInterface)
86  * IGN_COMMON_FINISH_ADDING_PLUGINS
87  */
88 
89 // Note that the order in which (Plugin, Interface) pairs are added does not
90 // matter. Multiple plugins are allowed to provide the same interface. There is
91 // no inherent limit on the number of interfaces or plugins that are allowed.
92 //
93 // These macros MUST be called in the global namespace in a source file of your
94 // library's codebase. A single library is only allowed to have ONE block of
95 // these macros (i.e. if you find yourself invoking
96 // IGN_COMMON_BEGIN_ADDING_PLUGINS more than once in your library, then you are
97 // doing something that is not permitted). Recommended practice is to have a
98 // single source file (e.g. plugins.cpp) in your library's codebase that is
99 // dedicated to hosting these macros.
100 
101 
110 #define IGN_COMMON_BEGIN_ADDING_PLUGINS\
111  DETAIL_IGN_COMMON_BEGIN_ADDING_PLUGINS
112 
113 
121 #define IGN_COMMON_ADD_PLUGIN(plugin, interface)\
122  DETAIL_IGN_COMMON_ADD_PLUGIN(plugin, interface)
123 
124 
127 #define IGN_COMMON_FINISH_ADDING_PLUGINS\
128  DETAIL_IGN_COMMON_FINISH_ADDING_PLUGINS
129 
130 
131 // -------------- Add a single plugin with a single interface -----------------
132 
138 #define IGN_COMMON_REGISTER_SINGLE_PLUGIN(plugin, interface) \
139  IGN_COMMON_BEGIN_ADDING_PLUGINS\
140  IGN_COMMON_ADD_PLUGIN(plugin, interface)\
141  IGN_COMMON_FINISH_ADDING_PLUGINS
142 
143 #endif