00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #include "lisp/list_iterator.hpp" 00018 #include <stdexcept> 00019 00020 namespace lisp { 00021 00022 ListIterator::ListIterator(const lisp::Lisp* newlisp) : 00023 current_item(), 00024 current_lisp(0), 00025 cur(newlisp) 00026 { 00027 } 00028 00029 bool 00030 ListIterator::next() 00031 { 00032 if(cur == 0) 00033 return false; 00034 00035 const lisp::Lisp* child = cur->get_car(); 00036 if(!child) 00037 throw std::runtime_error("child is 0 in list entry"); 00038 if(child->get_type() != lisp::Lisp::TYPE_CONS) 00039 throw std::runtime_error("Expected CONS"); 00040 const lisp::Lisp* name = child->get_car(); 00041 if(!name || ( 00042 name->get_type() != lisp::Lisp::TYPE_SYMBOL 00043 && name->get_type() != lisp::Lisp::TYPE_STRING)) 00044 throw std::runtime_error("Expected symbol"); 00045 name->get(current_item); 00046 current_lisp = child->get_cdr(); 00047 00048 cur = cur->get_cdr(); 00049 return true; 00050 } 00051 00052 } 00053 00054 /* EOF */