lib

list.cpp
1/***************************************************************************
2 * list.cpp
3 * This file is part of the KDE project
4 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include "list.h"
21#include "exception.h"
22
23using namespace Kross::Api;
24
25List::List(TQValueList<Object::Ptr> value)
26 : Value< List, TQValueList<Object::Ptr> >(value)
27{
28}
29
31{
32}
33
34const TQString List::getClassName() const
35{
36 return "Kross::Api::List";
37}
38
39const TQString List::toString()
40{
41 TQString s = "[";
42 TQValueList<Object::Ptr> list = getValue();
43 for(TQValueList<Object::Ptr>::Iterator it = list.begin(); it != list.end(); ++it)
44 s += "'" + (*it)->toString() + "', ";
45 return (s.endsWith(", ") ? s.left(s.length() - 2) : s) + "]";
46}
47
48Object::Ptr List::item(uint idx, Object* defaultobject)
49{
50 TQValueList<Object::Ptr>& list = getValue();
51 if(idx >= list.count()) {
52 if(defaultobject)
53 return defaultobject;
54 krossdebug( TQString("List::item index=%1 is out of bounds. Raising TypeException.").arg(idx) );
55 throw Exception::Ptr( new Exception(TQString("List-index %1 out of bounds.").arg(idx)) );
56 }
57 return list[idx];
58}
59
61{
62 return getValue().count();
63}
64
66{
67 getValue().append(object);
68}
69
Common exception class used for representing exceptions in Kross.
Definition exception.h:39
TDESharedPtr< Exception > Ptr
Shared pointer to implement reference-counting.
Definition exception.h:45
virtual const TQString getClassName() const
See.
Definition list.cpp:34
Object::Ptr item(uint idx, Object *defaultobject=0)
Return the Object with defined index from the TQValueList this list holds.
Definition list.cpp:48
List(TQValueList< Object::Ptr > value=TQValueList< Object::Ptr >())
Constructor.
Definition list.cpp:25
TDESharedPtr< List > Ptr
Shared pointer to implement reference-counting.
Definition list.h:46
virtual ~List()
Destructor.
Definition list.cpp:30
uint count()
Return the number of items in the TQValueList this list holds.
Definition list.cpp:60
void append(Object::Ptr object)
Append an Kross::Api::Object to the list.
Definition list.cpp:65
virtual const TQString toString()
Definition list.cpp:39
The common Object class all other object-classes are inheritated from.
Definition object.h:50
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:56
TQValueList< Object::Ptr > & getValue()
Definition value.h:64
Value(TQValueList< Object::Ptr > value)
Definition value.h:48
The common Kross API used as common codebase.
Definition callable.h:33
KOFFICE_EXPORT void krossdebug(const TQString &s)
Debugging function.