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 using namespace Kross::Api;
00024
00025 List::List(QValueList<Object::Ptr> value)
00026 : Value< List, QValueList<Object::Ptr> >(value)
00027 {
00028 }
00029
00030 List::~List()
00031 {
00032 }
00033
00034 const QString List::getClassName() const
00035 {
00036 return "Kross::Api::List";
00037 }
00038
00039 const QString List::toString()
00040 {
00041 QString s = "[";
00042 QValueList<Object::Ptr> list = getValue();
00043 for(QValueList<Object::Ptr>::Iterator it = list.begin(); it != list.end(); ++it)
00044 s += "'" + (*it)->toString() + "', ";
00045 return (s.endsWith(", ") ? s.left(s.length() - 2) : s) + "]";
00046 }
00047
00048 Object::Ptr List::item(uint idx, Object* defaultobject)
00049 {
00050 QValueList<Object::Ptr>& list = getValue();
00051 if(idx >= list.count()) {
00052 if(defaultobject)
00053 return defaultobject;
00054 krossdebug( QString("List::item index=%1 is out of bounds. Raising TypeException.").arg(idx) );
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
|