Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mars2 new class loader #66

Draft
wants to merge 2 commits into
base: mars2_new_core
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(COVERAGE "Enable code coverage. run 'make test && make coverage' to generate the coverage report. The report will be in ${CMAKE_BINARY_DIR}/cov" OFF)

find_package(PkgConfig REQUIRED)
pkg_check_modules(PLUGIN_LIBS plugin_manager class_loader)
if(PLUGIN_LIBS_FOUND)
pkg_check_modules(PLUGIN_MANAGER plugin_manager)
if(PLUGIN_MANAGER_FOUND)
#this definition is used in the source to include/exclude the plugin headers
message(STATUS "Plugin system enabled")
add_definitions(-DCMAKE_ENABLE_PLUGINS)
Expand Down
11 changes: 4 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ set(sources items/ItemBase.cpp
util/EnvireManager.cpp)

set(deps_pkg_config base-types boost_serialization)
set(deps Boost::filesystem Boost::serialization Boost::system Boost::thread)

if(PLUGIN_LIBS_FOUND)
if(PLUGIN_MANAGER_FOUND)

set(headers ${headers}
plugin/ClassLoader.hpp
plugin/Plugin.hpp)
set(sources ${sources}
plugin/ClassLoader.cpp)
set(deps_pkg_config ${deps_pkg_config} class_loader plugin_manager)
set(deps_pkg_config ${deps_pkg_config} plugin_manager)

endif()

Expand All @@ -78,11 +79,7 @@ rock_library(envire_core
SOURCES ${sources}
DEPS_CMAKE Glog
DEPS_PKGCONFIG ${deps_pkg_config}
DEPS
Boost::filesystem
Boost::serialization
Boost::system
Boost::thread
DEPS ${deps}
)


Expand Down
4 changes: 2 additions & 2 deletions src/plugin/ClassLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ bool ClassLoader::hasCollisionObject(const std::string& class_name) const
return hasClassOfType(class_name, envire_collision_base_class);
}

bool ClassLoader::createEnvireItem(const std::string& item_name, envire::core::ItemBase::Ptr& base_item)
bool ClassLoader::createEnvireItem(const std::string& item_name, std::shared_ptr<envire::core::ItemBase>& base_item)
{
return createInstance<envire::core::ItemBase>(item_name, base_item);
}

bool ClassLoader::createEnvireItemFor(const std::string& embedded_type, envire::core::ItemBase::Ptr& base_item)
bool ClassLoader::createEnvireItemFor(const std::string& embedded_type, std::shared_ptr<envire::core::ItemBase>& base_item)
{
if(createEnvireItem(std::string(envire_item_class) + "<" + embedded_type + ">", base_item))
return true;
Expand Down
19 changes: 9 additions & 10 deletions src/plugin/ClassLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#pragma once

#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <base-logging/Singleton.hpp>
#include <plugin_manager/PluginLoader.hpp>
Expand Down Expand Up @@ -88,23 +87,23 @@ class ClassLoader : public plugin_manager::PluginLoader
* @throws DownCastException if the cast from envire::core::ItemBase to InheritedClass isn't possible
*/
template<class InheritedClass>
bool createEnvireItem(const std::string& item_name, boost::shared_ptr<InheritedClass>& item);
bool createEnvireItem(const std::string& item_name, std::shared_ptr<InheritedClass>& item);

/**
* @brief Creates an instance of the given class, which has to be inherited from envire::core::ItemBase
* @param class_name the name of the plugin class
* @param base_item pointer to the envire item base class
* @return True if an instance of the class could be created
*/
bool createEnvireItem(const std::string& item_name, envire::core::ItemBase::Ptr& base_item);
bool createEnvireItem(const std::string& item_name, std::shared_ptr<envire::core::ItemBase>& base_item);

/**
* @brief Creates an envire item for the given embedded type
* @param embedded_type The class name of the embedded type
* @param base_item pointer to the envire item base class
* @return True if an instance of the class could be created
*/
bool createEnvireItemFor(const std::string& embedded_type, envire::core::ItemBase::Ptr& base_item);
bool createEnvireItemFor(const std::string& embedded_type, std::shared_ptr<envire::core::ItemBase>& base_item);

/**
* @brief Creates a collision object for the given class.
Expand All @@ -114,7 +113,7 @@ class ClassLoader : public plugin_manager::PluginLoader
* @return True if an instance of the class could be created
*/
template<class BaseClass>
bool createCollisionObjectFor(const std::string& class_name, boost::shared_ptr<BaseClass>& collision_object);
bool createCollisionObjectFor(const std::string& class_name, std::shared_ptr<BaseClass>& collision_object);

/**
* @brief Creates a collision object for the given class.
Expand All @@ -124,7 +123,7 @@ class ClassLoader : public plugin_manager::PluginLoader
* @return True if an instance of the class could be created
*/
template<class BaseClass>
bool createCollisionObjectFor(const envire::core::ItemBase& item, boost::shared_ptr<BaseClass>& collision_object);
bool createCollisionObjectFor(const envire::core::ItemBase& item, std::shared_ptr<BaseClass>& collision_object);

protected:
/**
Expand Down Expand Up @@ -158,13 +157,13 @@ class ClassLoader : public plugin_manager::PluginLoader
};

template<class InheritedClass>
bool ClassLoader::createEnvireItem(const std::string& item_name, boost::shared_ptr<InheritedClass>& item)
bool ClassLoader::createEnvireItem(const std::string& item_name, std::shared_ptr<InheritedClass>& item)
{
return createInstance<InheritedClass, envire::core::ItemBase>(item_name, item);
}

template<class BaseClass>
bool ClassLoader::createCollisionObjectFor(const std::string& class_name, boost::shared_ptr<BaseClass>& collision_object)
bool ClassLoader::createCollisionObjectFor(const std::string& class_name, std::shared_ptr<BaseClass>& collision_object)
{
std::string associated_class;
if(getAssociatedClassOfType(class_name, envire_collision_base_class, associated_class))
Expand All @@ -175,12 +174,12 @@ bool ClassLoader::createCollisionObjectFor(const std::string& class_name, boost:
}

template<class BaseClass>
bool ClassLoader::createCollisionObjectFor(const envire::core::ItemBase& item, boost::shared_ptr<BaseClass>& collision_object)
bool ClassLoader::createCollisionObjectFor(const envire::core::ItemBase& item, std::shared_ptr<BaseClass>& collision_object)
{
std::string class_name;
if (item.getClassName(class_name))
return createCollisionObjectFor<BaseClass>(class_name, collision_object);
return false;
}

}}
}}
4 changes: 2 additions & 2 deletions src/plugin/Plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#pragma once

#include <class_loader/class_loader_register_macro.h>
#include <class_loader/register_macro.hpp>
#include <envire_core/items/ItemMetadata.hpp>
#include <envire_core/items/Item.hpp>
#include <envire_core/serialization/SerializationRegistration.hpp>
Expand Down Expand Up @@ -66,7 +66,7 @@ static envire::core::MetadataInitializer _metadataInit(typeid(_classname), #_dat
*/
#define ENVIRE_PLUGIN_HEADER( _classname ) \
public: \
typedef boost::shared_ptr<_classname> Ptr; \
typedef std::shared_ptr<_classname> Ptr; \
private: \
ENVIRE_SERIALIZATION_HEADER(TemplateType)

Expand Down