// callback.tcc // robert - programme du robot 2005. {{{ // // Copyright (C) 2004 Nicolas Schodet // // 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. // // Contact : // Web: http://perso.efrei.fr/~schodet/ // Email: // }}} #include template Callback::Callback (void) : holder_ (0) { } template template Callback::Callback (T callback) : holder_ (new Holder (callback)) { } template Callback::Callback (const Callback &other) : holder_ (other.holder_ ? other.holder_->clone () : 0) { } template Callback::~Callback (void) { delete holder_; } template R Callback::operator () (void) { if (!holder_) throw bad_callback (); else return (*holder_) (); } template void Callback::swap (Callback &rhs) { std::swap (holder_, rhs.holder_); } template Callback & Callback::operator= (const Callback &rhs) { Callback (rhs).swap (*this); return *this; } template template Callback & Callback::operator= (T rhs) { Callback (rhs).swap (*this); return *this; } template bool Callback::empty (void) const { return !holder_; } 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_); }