OpenWalker Project
Documentation of the ROS Packages
Macros
class_export.h File Reference

Contains the macros for classes to load them on runtime. More...

Go to the source code of this file.

Macros

#define OW_PLUGIN_CLASS_CREATE(Class)
 A macro that creates the create factory function for the Class. More...
 
#define OW_PLUGIN_CLASS_DESTROY(Class)
 A macro that creates the destroy factory function for the Class. More...
 
#define OW_PLUGIN_CLASS(Class)
 A macro that creates the create and destroy factory functions for the Class. More...
 

Detailed Description

Contains the macros for classes to load them on runtime.

Author
Emmanuel Dean-Leon
Florian Bergner
J. Rogelio Guadarrama-Olvera
Simon Armleder
Gordon Cheng
Version
0.1
Date
14.02.2020

Licence

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Acknowledgment

This project has received funding from the European Unionā€˜s Horizon 2020 research and innovation programme under grant agreement No 732287.

This macros have to be added to the .cpp file of the class that will be loaded at runtime. Make sure that you have only one loadable class with this macros per .so file.

Macro Definition Documentation

#define OW_PLUGIN_CLASS (   Class)
Value:
#define OW_PLUGIN_CLASS_CREATE(Class)
A macro that creates the create factory function for the Class.
Definition: class_export.h:60

A macro that creates the create and destroy factory functions for the Class.

NOTE: Use this macro only once per .so file!

#define OW_PLUGIN_CLASS_CREATE (   Class)
Value:
extern "C" \
{ \
void* create() \
{ \
Class* ptr = new Class; \
return static_cast<ow_core::IGenericClass*>(ptr); \
} \
}
The IGenericClass class.
Definition: i_generic_class.h:54

A macro that creates the create factory function for the Class.

NOTE: the static_cast from 'Class*' to 'IGenericClass*' is essential. The void* is casted back with reinterpret_cast to 'IGenericClass*'. This fails with seg fault when not previously using static_cast.

NOTE: the upcasting from 'IGenericClass*' to 'Class*' must be again done with static_cast!

NOTE: Use this macro only once per .so file!

#define OW_PLUGIN_CLASS_DESTROY (   Class)
Value:
extern "C" \
{ \
void destroy(void* ptr) \
{ \
ow_core::IGenericClass* g = reinterpret_cast<ow_core::IGenericClass*>(ptr); \
Class* c = static_cast<Class*>(g); \
delete c; \
} \
}
The IGenericClass class.
Definition: i_generic_class.h:54

A macro that creates the destroy factory function for the Class.

NOTE: The destruction should run from top to down (should be less error prone than down to top).

NOTE: Since classes should be created by the factory they should also be deleted by the factory to avoid memory corruptions when the .so file has been compiled with a different compiler (version) then the loader of the .so file.

NOTE: Use this macro only once per .so file!