Gazebo Common

API Reference

3.17.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 GZ_COMMON_REGISTERMACROS_HH_
20 #define GZ_COMMON_REGISTERMACROS_HH_
21 
22 #include "gz/common/detail/PluginMacros.hh"
23 
24 // --------------- Specialize a plugin interface (optional) -------------------
25 
52 #define IGN_COMMON_SPECIALIZE_INTERFACE(interfaceName)\
53  DETAIL_IGN_COMMON_SPECIALIZE_INTERFACE(interfaceName)
54 
55 
56 // ------------- Add a set of plugins or a set of interfaces ------------------
57 
58 // The following three macros can be used to produce multiple plugins and/or
59 // multiple interfaces from your shared library.
60 
61 /* Usage example for multiple plugins and one interface:
62  *
63  * IGN_COMMON_BEGIN_ADDING_PLUGINS
64  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass1, mylibrary::ns::SomeInterface)
65  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass2, mylibrary::ns::SomeInterface)
66  * IGN_COMMON_FINISH_ADDING_PLUGINS
67  *
68  *
69  * Usage example for one plugin and multiple interfaces:
70  *
71  * IGN_COMMON_BEGIN_ADDING_PLUGINS
72  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::Interface1)
73  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::Interface2)
74  * IGN_COMMON_FINISH_ADDING_PLUGINS
75  *
76  *
77  * Usage example for multiple plugins and multiple interfaces:
78  *
79  * IGN_COMMON_BEGIN_ADDING_PLUGINS
80  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::FooInterface)
81  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::BarInterface)
82  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeClass, mylibrary::ns::SomeInterface)
83  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::FooInterface)
84  * IGN_COMMON_ADD_PLUGIN(mylibrary::ns::SomeOtherClass, mylibrary::ns::SomeInterface)
85  * IGN_COMMON_FINISH_ADDING_PLUGINS
86  */
87 
88 // Note that the order in which (Plugin, Interface) pairs are added does not
89 // matter. Multiple plugins are allowed to provide the same interface. There is
90 // no inherent limit on the number of interfaces or plugins that are allowed.
91 //
92 // These macros MUST be called in the global namespace in a source file of your
93 // library's codebase. A single library is only allowed to have ONE block of
94 // these macros (i.e. if you find yourself invoking
95 // IGN_COMMON_BEGIN_ADDING_PLUGINS more than once in your library, then you are
96 // doing something that is not permitted). Recommended practice is to have a
97 // single source file (e.g. plugins.cpp) in your library's codebase that is
98 // dedicated to hosting these macros.
99 
100 
109 #define IGN_COMMON_BEGIN_ADDING_PLUGINS\
110  DETAIL_IGN_COMMON_BEGIN_ADDING_PLUGINS
111 
112 
120 #define IGN_COMMON_ADD_PLUGIN(plugin, interface)\
121  DETAIL_IGN_COMMON_ADD_PLUGIN(plugin, interface)
122 
123 
126 #define IGN_COMMON_FINISH_ADDING_PLUGINS\
127  DETAIL_IGN_COMMON_FINISH_ADDING_PLUGINS
128 
129 
130 // -------------- Add a single plugin with a single interface -----------------
131 
137 #define IGN_COMMON_REGISTER_SINGLE_PLUGIN(plugin, interface) \
138  IGN_COMMON_BEGIN_ADDING_PLUGINS\
139  IGN_COMMON_ADD_PLUGIN(plugin, interface)\
140  IGN_COMMON_FINISH_ADDING_PLUGINS
141 
142 #endif