.. _program_listing_file__tmp_ws_src_message_filters_include_message_filters_signal9.h: Program Listing for File signal9.h ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/message_filters/include/message_filters/signal9.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2010, Willow Garage, 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 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 MESSAGE_FILTERS__SIGNAL9_H_ #define MESSAGE_FILTERS__SIGNAL9_H_ #include #include #include "message_filters/connection.h" #include "message_filters/null_types.h" #include "message_filters/message_event.h" #include "message_filters/parameter_adapter.h" namespace message_filters { template class CallbackHelper9 { public: typedef MessageEvent M0Event; typedef MessageEvent M1Event; typedef MessageEvent M2Event; typedef MessageEvent M3Event; typedef MessageEvent M4Event; typedef MessageEvent M5Event; typedef MessageEvent M6Event; typedef MessageEvent M7Event; typedef MessageEvent M8Event; virtual ~CallbackHelper9() {} virtual void call(bool nonconst_force_copy, const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3, const M4Event& e4, const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8) = 0; typedef std::shared_ptr Ptr; }; template class CallbackHelper9T : public CallbackHelper9::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message, typename ParameterAdapter::Message> { private: typedef ParameterAdapter A0; typedef ParameterAdapter A1; typedef ParameterAdapter A2; typedef ParameterAdapter A3; typedef ParameterAdapter A4; typedef ParameterAdapter A5; typedef ParameterAdapter A6; typedef ParameterAdapter A7; typedef ParameterAdapter A8; typedef typename A0::Event M0Event; typedef typename A1::Event M1Event; typedef typename A2::Event M2Event; typedef typename A3::Event M3Event; typedef typename A4::Event M4Event; typedef typename A5::Event M5Event; typedef typename A6::Event M6Event; typedef typename A7::Event M7Event; typedef typename A8::Event M8Event; public: typedef std::function Callback; CallbackHelper9T(const Callback& cb) : callback_(cb) { } virtual void call(bool nonconst_force_copy, const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3, const M4Event& e4, const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8) { M0Event my_e0(e0, nonconst_force_copy || e0.nonConstWillCopy()); M1Event my_e1(e1, nonconst_force_copy || e0.nonConstWillCopy()); M2Event my_e2(e2, nonconst_force_copy || e0.nonConstWillCopy()); M3Event my_e3(e3, nonconst_force_copy || e0.nonConstWillCopy()); M4Event my_e4(e4, nonconst_force_copy || e0.nonConstWillCopy()); M5Event my_e5(e5, nonconst_force_copy || e0.nonConstWillCopy()); M6Event my_e6(e6, nonconst_force_copy || e0.nonConstWillCopy()); M7Event my_e7(e7, nonconst_force_copy || e0.nonConstWillCopy()); M8Event my_e8(e8, nonconst_force_copy || e0.nonConstWillCopy()); callback_(A0::getParameter(e0), A1::getParameter(e1), A2::getParameter(e2), A3::getParameter(e3), A4::getParameter(e4), A5::getParameter(e5), A6::getParameter(e6), A7::getParameter(e7), A8::getParameter(e8)); } private: Callback callback_; }; template class Signal9 { typedef std::shared_ptr > CallbackHelper9Ptr; typedef std::vector V_CallbackHelper9; public: typedef MessageEvent M0Event; typedef MessageEvent M1Event; typedef MessageEvent M2Event; typedef MessageEvent M3Event; typedef MessageEvent M4Event; typedef MessageEvent M5Event; typedef MessageEvent M6Event; typedef MessageEvent M7Event; typedef MessageEvent M8Event; typedef std::shared_ptr M0ConstPtr; typedef std::shared_ptr M1ConstPtr; typedef std::shared_ptr M2ConstPtr; typedef std::shared_ptr M3ConstPtr; typedef std::shared_ptr M4ConstPtr; typedef std::shared_ptr M5ConstPtr; typedef std::shared_ptr M6ConstPtr; typedef std::shared_ptr M7ConstPtr; typedef std::shared_ptr M8ConstPtr; typedef const std::shared_ptr& NullP; template Connection addCallback(const std::function& callback) { CallbackHelper9T* helper = new CallbackHelper9T(callback); std::lock_guard lock(mutex_); callbacks_.push_back(CallbackHelper9Ptr(helper)); return Connection(std::bind(&Signal9::removeCallback, this, callbacks_.back())); } template Connection addCallback(void(*callback)(P0, P1)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2))); } template Connection addCallback(void(*callback)(P0, P1, P2)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3, P4)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8))); } template Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7, P8)) { return addCallback(std::function(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9))); } template Connection addCallback(void(T::*callback)(P0, P1), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2))); } template Connection addCallback(void(T::*callback)(P0, P1, P2), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); } template Connection addCallback(void(T::*callback)(P0, P1, P2, P3), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))); } template Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5))); } template Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6))); } template Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7))); } template Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6, P7), T* t) { return addCallback(std::function(std::bind(callback, t, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8))); } template Connection addCallback( C& callback) { return addCallback(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)); } void removeCallback(const CallbackHelper9Ptr& helper) { std::lock_guard lock(mutex_); typename V_CallbackHelper9::iterator it = std::find(callbacks_.begin(), callbacks_.end(), helper); if (it != callbacks_.end()) { callbacks_.erase(it); } } void call(const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3, const M4Event& e4, const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8) { std::lock_guard lock(mutex_); bool nonconst_force_copy = callbacks_.size() > 1; typename V_CallbackHelper9::iterator it = callbacks_.begin(); typename V_CallbackHelper9::iterator end = callbacks_.end(); for (; it != end; ++it) { const CallbackHelper9Ptr& helper = *it; helper->call(nonconst_force_copy, e0, e1, e2, e3, e4, e5, e6, e7, e8); } } private: std::mutex mutex_; V_CallbackHelper9 callbacks_; }; } // namespace message_filters #endif // MESSAGE_FILTERS__SIGNAL9_H_