src/tools/tCallback.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "tCallback.h"
00029 #include "tCallbackString.h"
00030 #include "tError.h"
00031 
00032 tCallback::tCallback(tCallback*& anchor, AA_VOIDFUNC *f)
00033         :tListItem<tCallback>(anchor), func(f){
00034     tASSERT(f != NULL);
00035 }
00036 
00037 void tCallback::Exec(tCallback *anchor){
00038     if (anchor){
00039         (*anchor->func)();
00040         Exec(anchor->Next());
00041     }
00042 }
00043 
00044 
00045 #ifdef HAVE_LIBRUBY
00046 
00047 tCallbackRuby::tCallbackRuby(tCallbackRuby *& anchor)
00048         :tListItem<tCallbackRuby>(anchor), block(rb_block_proc())
00049 {
00050 }
00051 
00052 void tCallbackRuby::Exec(tCallbackRuby *anchor) {
00053     if (anchor) {
00054         int status = 0;
00055         rb_protect(ExecProtect, anchor->block, &status);
00056         tRuby::CheckStatus(status);
00057         Exec(anchor->Next());
00058     }
00059 }
00060 
00061 VALUE tCallbackRuby::ExecProtect(VALUE block)
00062 {
00063     return rb_funcall(block, rb_intern("call"), 0);
00064 }
00065 #endif // HAVE_LIBRUBY
00066 
00067 tCallbackAnd::tCallbackAnd(tCallbackAnd*& anchor, BOOLRETFUNC *f)
00068         :tListItem<tCallbackAnd>(anchor), func(f){
00069     tASSERT(f);
00070 }
00071 
00072 bool tCallbackAnd::Exec(tCallbackAnd *anchor){
00073     if (anchor)
00074         return (*anchor->func)() && Exec(anchor->Next());
00075     else
00076         return true;
00077 }
00078 
00079 
00080 tCallbackOr::tCallbackOr(tCallbackOr*& anchor, BOOLRETFUNC *f)
00081         :tListItem<tCallbackOr>(anchor), func(f){
00082     tASSERT(f);
00083 }
00084 
00085 bool tCallbackOr::Exec(tCallbackOr *anchor){
00086     if (anchor)
00087         return (*anchor->func)() || Exec(anchor->Next());
00088     else
00089         return false;
00090 }
00091 
00092 
00093 
00094 tCallbackString::tCallbackString(tCallbackString*& anchor, STRINGRETFUNC *f)
00095         :tListItem<tCallbackString>(anchor), func(f){
00096     tASSERT(f);
00097 }
00098 
00099 tString tCallbackString::Exec(tCallbackString *anchor){
00100     tString ret("");
00101     if (anchor)
00102         ret << (*anchor->func)() << Exec(anchor->Next());
00103 
00104     return ret;
00105 }
00106 

Generated on Sat Mar 15 22:55:59 2008 for Armagetron Advanced by  doxygen 1.5.4