lib
list.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
|