00001 /* 00002 * KAVIterator.cc 00003 * 00004 * Smalltalk like class library for C++ 00005 * Collection keys and values iterator. 00006 * 00007 * Copyright (c) 2003 Milan Cermak 00008 */ 00009 /* 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library 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 GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #include <stlib/KAVIterator.h> 00025 #include <stlib/Association.h> 00026 #include <stlib/Dictionary.h> 00027 #include <stlib/Object.h> 00028 #include <stlib/String.h> 00029 00030 KeysAndValuesIterator::KeysAndValuesIterator(const Dictionary *coll) 00031 : CollectionIterator(coll) 00032 { 00033 } 00034 00035 /* Class-accessing protocol */ 00036 String *KeysAndValuesIterator::className(void) const 00037 { 00038 return new String("KeysAndValuesIterator"); 00039 } 00040 00041 /* Accessing protocol */ 00042 Object *KeysAndValuesIterator::key(void) 00043 { 00044 if (!item->isAssociation()) 00045 error(new String("Improper object for iteration. Association expected.")); 00046 return ((Association *) item)->key(); 00047 } 00048 00049 Object *KeysAndValuesIterator::value(void) 00050 { 00051 if (!item->isAssociation()) 00052 error(new String("Improper object for iteration. Association expected.")); 00053 return ((Association *) item)->value(); 00054 }