lib

list.cpp

00001 /***************************************************************************
00002  * list.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "list.h"
00021 #include "exception.h"
00022 
00023 #include <kdebug.h>
00024 
00025 using namespace Kross::Api;
00026 
00027 List::List(QValueList<Object::Ptr> value, const QString& name)
00028     : Value< List, QValueList<Object::Ptr> >(value, name)
00029 {
00030 }
00031 
00032 List::~List()
00033 {
00034 }
00035 
00036 const QString List::getClassName() const
00037 {
00038     return "Kross::Api::List";
00039 }
00040 
00041 const QString List::toString()
00042 {
00043     QString s = "[";
00044     QValueList<Object::Ptr> list = getValue();
00045     for(QValueList<Object::Ptr>::Iterator it = list.begin(); it != list.end(); ++it)
00046         s += "'" + (*it)->toString() + "', ";
00047     return (s.endsWith(", ") ? s.left(s.length() - 2) : s) + "]";
00048 }
00049 
00050 Object::Ptr List::item(uint idx)
00051 {
00052     QValueList<Object::Ptr>& list = getValue();
00053     if(idx >= list.count()) {
00054         kdDebug() << "List::item index=" << idx << " is out of bounds. Raising TypeException." << endl;
00055         throw Exception::Ptr( new Exception(QString("List-index %1 out of bounds.").arg(idx)) );
00056     }
00057     return list[idx];
00058 }
00059 
00060 uint List::count()
00061 {
00062     return getValue().count();
00063 }
00064 
00065 void List::append(Object::Ptr object)
00066 {
00067     getValue().append(object);
00068 }
00069 
KDE Home | KDE Accessibility Home | Description of Access Keys