list.h
1/***************************************************************************
2 * list.h
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#ifndef KROSS_API_LIST_H
21#define KROSS_API_LIST_H
22
23#include <tqstring.h>
24#include <tqvaluelist.h>
25#include <tqintdict.h>
26
27#include "object.h"
28#include "value.h"
29
30namespace Kross { namespace Api {
31
36 class List : public Value< List, TQValueList<Object::Ptr> >
37 {
38 friend class Value< List, TQValueList<Object::Ptr> >;
39 public:
40
44 typedef TDESharedPtr<List> Ptr;
45
46/*
47 operator TQStringList () {
48 //TQValueList<Object::Ptr> getValue()
49 krossdebug("999999999999 ...........................");
50 return TQStringList();
51 }
52*/
53
60 List(TQValueList<Object::Ptr> value = TQValueList<Object::Ptr>());
61
65 virtual ~List();
66
70 virtual const TQString getClassName() const;
71
77 virtual const TQString toString();
78
92 Object::Ptr item(uint idx, Object* defaultobject = 0);
93
100 uint count();
101
108 void append(Object::Ptr object);
109
110 template<typename TYPE>
111 static Object::Ptr toObject(TYPE t) { return t; }
112 };
113
118 template< class OBJECT >
119 class ListT : public List
120 {
121 public:
122 ListT() : List() {}
123 ListT(TQValueList<OBJECT> values) : List(values) {}
124
125 template< typename TYPE >
126 ListT(TQValueList<TYPE> values) : List()
127 {
128 TQValueListIterator<TYPE> it(values.begin()), end(values.end());
129 for(; it != end; ++it)
130 this->append( new OBJECT(*it) );
131 }
132
133 template< typename TYPE >
134 ListT(TQIntDict<TYPE> values) : List()
135 {
136 TQIntDictIterator<TYPE> it( values );
137 TYPE *t;
138 while( (t = it.current()) != 0 ) {
139 this->append( new OBJECT(t) );
140 ++it;
141 }
142 }
143
144 template< typename TYPE >
145 ListT(const TQPtrList<TYPE> values) : List()
146 {
147 TQPtrListIterator<TYPE> it(values);
148 TYPE *t;
149 while( (t = it.current()) != 0 ) {
150 this->append( new OBJECT(t) );
151 ++it;
152 }
153 }
154
155 virtual ~ListT() {}
156
157 template<typename TYPE>
158 static Object::Ptr toObject(TYPE t)
159 {
160 return new ListT(t);
161 }
162 };
163
164}}
165
166#endif
167
This template class extends the List class with generic functionality to deal with lists.
Definition list.h:120
The List class implementates Value to handle lists and collections.
Definition list.h:37
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
TDESharedPtr< List > Ptr
Shared pointer to implement reference-counting.
Definition list.h:44
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:51
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:57
Template class to represent values.
Definition value.h:39
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:31