#ifndef callback_tcc #define callback_tcc // callback.tcc // marvin - programme du robot 2006. {{{ // // Copyright (C) 2003-2006 Nicolas Schodet // // Robot APB Team/Efrei 2006. // Web: http://assos.efrei.fr/robot/ // Email: robot AT efrei DOT fr // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} #include /// Default constructor. Make an empty callback. template Callback::Callback (void) : holder_ (0) { } /// Constructor. template template Callback::Callback (T callback) : holder_ (new Holder (callback)) { } /// Copy constructor. template Callback::Callback (const Callback &other) : holder_ (other.holder_ ? other.holder_->clone () : 0) { } /// Destructor. template Callback::~Callback (void) { delete holder_; } /// Assignement operator. template Callback & Callback::operator= (const Callback &rhs) { Callback (rhs).swap (*this); return *this; } /// Call the contained callback. template R Callback::operator () (void) { if (!holder_) throw bad_callback (); else return (*holder_) (); } /// Swap the callback content with another callback. template void Callback::swap (Callback &rhs) { std::swap (holder_, rhs.holder_); } /// Change the contained callback. template template Callback & Callback::operator= (T rhs) { Callback (rhs).swap (*this); return *this; } /// Test if empty. template bool Callback::empty (void) const { return !holder_; } /// Test if not empty. template Callback::operator bool (void) const { return !empty (); } template Callback::AbstractHolder::~AbstractHolder (void) { } template template Callback::Holder::Holder (T callback) : callback_ (callback) { } template template R Callback::Holder::operator () (void) { return callback_ (); } template template typename Callback::AbstractHolder * Callback::Holder::clone (void) { return new Holder (callback_); } #endif // callback_tcc