Program Listing for File connect.hpp

Return to documentation for file (/tmp/ws/src/ecl_lite/ecl_sigslots_lite/include/ecl/sigslots_lite/connect.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef ECL_SIGSLOTS_LITE_CONNECT_HPP_
#define ECL_SIGSLOTS_LITE_CONNECT_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include "slot.hpp"
#include "signal.hpp"
#include "errors.hpp"

/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace ecl {
namespace lite {

/*****************************************************************************
** Privately Used Connects
*****************************************************************************/

namespace sigslots {
template <typename Data, unsigned int Capacity, typename FunctionClass>
ecl::lite::sigslots::Error connect(ecl::lite::Signal<Data, Capacity> &signal, MemberSlot<Data,FunctionClass> &slot) {
    return signal.connect(slot);
}

template <typename Data, unsigned int Capacity>
ecl::lite::sigslots::Error connect(ecl::lite::Signal<Data, Capacity> &signal, GlobalSlot<Data> &slot) {
    return signal.connect(slot);
}

} // namespace sigslots

/*****************************************************************************
** Publicly Used Connects
*****************************************************************************/

template <typename Data, unsigned int Capacity, typename FunctionClass>
sigslots::Error connect(Signal<Data,Capacity> &signal, void(FunctionClass::*f)(Data), FunctionClass &o) {
    // Need to do this just in case o has member slot interfaces for multiple Data types.
    // If we don't it can't resolve the footprint that seems to get lost when passing
    // the function pointers down the line - another way to resolve maybe?
    sigslots::MemberSlotsBase<Data,FunctionClass> &member_slots = o;
    sigslots::MemberSlot<Data,FunctionClass> *slot = member_slots.addSlot(f,o);
    if ( slot != NULL ) {
        return sigslots::connect(signal,*slot); // koenig lookup also works
    } else {
        return sigslots::Error(sigslots::OutOfResourcesError);
    }
}
template <typename Data, unsigned int Capacity>
sigslots::Error connect(Signal<Data, Capacity> &signal, void (*function)(Data)) {
    sigslots::GlobalSlot<Data> *slot = GlobalSlots<Data>::addSlot(function);
    if ( slot != NULL ) {
        return sigslots::connect(signal,*slot);
    } else {
        return sigslots::Error(sigslots::OutOfResourcesError);
    }

}

/*****************************************************************************
** Publicly Used Connect Overloads
*****************************************************************************/

template <unsigned int Capacity, typename FunctionClass>
sigslots::Error connect(Signal<void, Capacity> &signal, void(FunctionClass::*function)(void), FunctionClass &o) {
    // Need to do this just in case o has member slot interfaces for multiple Data types.
    // If we don't it can't resolve the footprint that seems to get lost when passing
    // the function pointers down the line - another way to resolve maybe?
    sigslots::MemberSlotsBase<void,FunctionClass> &member_slots = o;
    sigslots::MemberSlot<void,FunctionClass> *slot = member_slots.addSlot(function,o);
    if ( slot != NULL ) {
        return sigslots::connect(signal,*slot); // koenig lookup also works
    } else {
        return sigslots::Error(sigslots::OutOfResourcesError);
    }
}
template <unsigned int Capacity>
sigslots::Error connect(Signal<void, Capacity> &signal, void (*function)(void)) {
    sigslots::GlobalSlot<void> *slot = GlobalSlots<void>::addSlot(function);
    if ( slot != NULL ) {
        return sigslots::connect(signal,*slot);
    } else {
        return sigslots::Error(sigslots::OutOfResourcesError);
    }

}

} // namespace lite
} // namespace ecl

#endif /* ECL_SIGSLOTS_LITE_CONNECT_HPP_ */