Skip to content

Commit

Permalink
Style overhaul (#64)
Browse files Browse the repository at this point in the history
* header guards and namespaces

* [cpplint] whitespaces

* includes

* line length

* no globl std::string

* add some missing copyrights

* ignore explicit cpplint violation and add todo to address them on melodic branch

* uncrustify

* unused variables warnings

* litterals on left side of operator

* spurious temp file
  • Loading branch information
mikaelarguedas authored Nov 14, 2017
1 parent 9a3cc66 commit 9e30d57
Show file tree
Hide file tree
Showing 16 changed files with 1,505 additions and 1,210 deletions.
438 changes: 231 additions & 207 deletions include/class_loader/class_loader.h

Large diffs are not rendered by default.

212 changes: 130 additions & 82 deletions include/class_loader/class_loader_core.h

Large diffs are not rendered by default.

44 changes: 28 additions & 16 deletions include/class_loader/class_loader_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CLASS_LOADER__CLASS_LOADER_EXCEPTIONS_H_
#define CLASS_LOADER__CLASS_LOADER_EXCEPTIONS_H_

#include <exception>
#include <string>

// TODO(mikaelarguedas) : replace no lints with the explicit keyword in an ABI breaking release

namespace class_loader
{
Expand All @@ -36,50 +42,56 @@ namespace class_loader
* @class ClassLoader sException
* @brief A base class for all class_loader exceptions that inherits from std::runtime_exception
*/
class ClassLoaderException: public std::runtime_error
class ClassLoaderException : public std::runtime_error
{
public:
ClassLoaderException(const std::string error_desc) : std::runtime_error(error_desc) {}
public:
ClassLoaderException(const std::string error_desc) // NOLINT(runtime/explicit)
: std::runtime_error(error_desc) {}
};

/**
* @class LibraryLoadException
* @brief An exception class thrown when class_loader is unable to load a runtime library
*/
class LibraryLoadException: public ClassLoaderException
class LibraryLoadException : public ClassLoaderException
{
public:
LibraryLoadException(const std::string error_desc) : ClassLoaderException(error_desc) {}
public:
LibraryLoadException(const std::string error_desc) // NOLINT(runtime/explicit)
: ClassLoaderException(error_desc) {}
};

/**
* @class LibraryUnloadException
* @brief An exception class thrown when class_loader is unable to unload a runtime library
*/
class LibraryUnloadException: public ClassLoaderException
class LibraryUnloadException : public ClassLoaderException
{
public:
LibraryUnloadException(const std::string error_desc) : ClassLoaderException(error_desc) {}
public:
LibraryUnloadException(const std::string error_desc) // NOLINT(runtime/explicit)
: ClassLoaderException(error_desc) {}
};

/**
* @class CreateClassException
* @brief An exception class thrown when class_loader is unable to create a plugin
*/
class CreateClassException: public ClassLoaderException
class CreateClassException : public ClassLoaderException
{
public:
CreateClassException(const std::string error_desc) : ClassLoaderException(error_desc) {}
public:
CreateClassException(const std::string error_desc) // NOLINT(runtime/explicit)
: ClassLoaderException(error_desc) {}
};

/**
* @class NoClassLoaderExistsException
* @brief An exception class thrown when a multilibrary class loader does not have a ClassLoader bound to it
*/
class NoClassLoaderExistsException: public ClassLoaderException
class NoClassLoaderExistsException : public ClassLoaderException
{
public:
NoClassLoaderExistsException(const std::string error_desc) : ClassLoaderException(error_desc) {}
public:
NoClassLoaderExistsException(const std::string error_desc) // NOLINT(runtime/explicit)
: ClassLoaderException(error_desc) {}
};

}
} // namespace class_loader
#endif // CLASS_LOADER__CLASS_LOADER_EXCEPTIONS_H_
46 changes: 25 additions & 21 deletions include/class_loader/class_loader_register_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,48 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CLASS_LOADER_REGISTER_MACRO_H_DEFINED
#define CLASS_LOADER_REGISTER_MACRO_H_DEFINED
#ifndef CLASS_LOADER__CLASS_LOADER_REGISTER_MACRO_H_
#define CLASS_LOADER__CLASS_LOADER_REGISTER_MACRO_H_

#include "class_loader_core.h"
#include <console_bridge/console.h>
#include <string>

#include "class_loader/class_loader_core.h"
#include "class_loader/console_bridge_compatibility.h"

#include "console_bridge/console.h"

#define CLASS_LOADER_REGISTER_CLASS_INTERNAL_WITH_MESSAGE(Derived, Base, UniqueID, Message) \
namespace \
{\
struct ProxyExec##UniqueID \
{\
namespace \
{ \
struct ProxyExec ## UniqueID \
{ \
typedef Derived _derived; \
typedef Base _base; \
ProxyExec##UniqueID() \
typedef Base _base; \
ProxyExec ## UniqueID() \
{ \
if(std::string(Message)!="")\
CONSOLE_BRIDGE_logInform("%s", Message);\
if (std::string(Message) != "") { \
CONSOLE_BRIDGE_logInform("%s", Message);} \
class_loader::class_loader_private::registerPlugin<_derived, _base>(#Derived, #Base); \
}\
};\
static ProxyExec##UniqueID g_register_plugin_##UniqueID;\
}
} \
}; \
static ProxyExec ## UniqueID g_register_plugin_ ## UniqueID; \
} // namespace

#define CLASS_LOADER_REGISTER_CLASS_INTERNAL_HOP1_WITH_MESSAGE(Derived, Base, UniqueID, Message) CLASS_LOADER_REGISTER_CLASS_INTERNAL_WITH_MESSAGE(Derived, Base, UniqueID, Message)
#define CLASS_LOADER_REGISTER_CLASS_INTERNAL_HOP1_WITH_MESSAGE(Derived, Base, UniqueID, Message) \
CLASS_LOADER_REGISTER_CLASS_INTERNAL_WITH_MESSAGE(Derived, Base, UniqueID, Message)

/**
* @macro This macro is same as CLASS_LOADER_REGISTER_CLASS, but will spit out a message when the plugin is registered
* at library load time
*/
#define CLASS_LOADER_REGISTER_CLASS_WITH_MESSAGE(Derived, Base, Message) CLASS_LOADER_REGISTER_CLASS_INTERNAL_HOP1_WITH_MESSAGE(Derived, Base, __COUNTER__, Message)
#define CLASS_LOADER_REGISTER_CLASS_WITH_MESSAGE(Derived, Base, Message) \
CLASS_LOADER_REGISTER_CLASS_INTERNAL_HOP1_WITH_MESSAGE(Derived, Base, __COUNTER__, Message)

/**
* @macro This is the macro which must be declared within the source (.cpp) file for each class that is to be exported as plugin.
* The macro utilizes a trick where a new struct is generated along with a declaration of static global variable of same type after it. The struct's constructor invokes a registration function with the plugin system. When the plugin system loads a library with registered classes in it, the initialization of static variables forces the invocation of the struct constructors, and all exported classes are automatically registerd.
*/
#define CLASS_LOADER_REGISTER_CLASS(Derived, Base) CLASS_LOADER_REGISTER_CLASS_WITH_MESSAGE(Derived, Base, "")

#endif
#define CLASS_LOADER_REGISTER_CLASS(Derived, Base) \
CLASS_LOADER_REGISTER_CLASS_WITH_MESSAGE(Derived, Base, "")

#endif // CLASS_LOADER__CLASS_LOADER_REGISTER_MACRO_H_
35 changes: 32 additions & 3 deletions include/class_loader/console_bridge_compatibility.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#ifndef CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H
#define CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H
/*
* Copyright (c) 2017, Open Source Robotics Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H_
#define CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H_

#include <console_bridge/console.h>

Expand All @@ -19,4 +48,4 @@
#define CONSOLE_BRIDGE_logInform logInform
#endif

#endif // CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H
#endif // CLASS_LOADER__CONSOLE_BRIDGE_COMPATIBILITY_H_
Loading

0 comments on commit 9e30d57

Please sign in to comment.