/* * Copyright (C) 2015 by Multi-Tech Systems * * This file is part of libmts. * * libmts is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * libmts is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libmts. If not, see . * */ /*! \file MTS_BasicSubscriber.h \brief A simple subscriber \date 28MAR12 \author Sean Godinez A subscriber. */ #ifndef _MTS_BASICSUBSCRIBER_H_ #define _MTS_BASICSUBSCRIBER_H_ #include #include namespace MTS { //! A basic subscriber /*! A basic subscriber provides simple subscribing functionality. \sa Publisher, Subscriber, BasicPublisher */ template class BasicSubscriber: public Subscriber { public: explicit BasicSubscriber(const Callback& callback, const std::string& name = ""); //!< Constructor virtual ~BasicSubscriber();//!< Destructor virtual void update(const T& object); //!< Invokes callback with published data T private: Callback* callback; //Prevent Copy and Assignment operators from being called BasicSubscriber(const BasicSubscriber&); BasicSubscriber& operator=(const BasicSubscriber&); }; template BasicSubscriber::BasicSubscriber(const Callback& callback, const std::string& name) : Subscriber(name), callback(callback.clone()) { } template BasicSubscriber::~BasicSubscriber() { delete callback; } template void BasicSubscriber::update(const T& object) { callback->invoke(object); } } #endif