lib

list.h

00001 /***************************************************************************
00002  * list.h
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 #ifndef KROSS_API_LIST_H
00021 #define KROSS_API_LIST_H
00022 
00023 #include <qstring.h>
00024 #include <qvaluelist.h>
00025 #include <qintdict.h>
00026 
00027 #include "object.h"
00028 #include "value.h"
00029 
00030 namespace Kross { namespace Api {
00031 
00036     class List : public Value< List, QValueList<Object::Ptr> >
00037     {
00038             friend class Value< List, QValueList<Object::Ptr> >;
00039         public:
00040 
00044             typedef KSharedPtr<List> Ptr;
00045 
00053             List(QValueList<Object::Ptr> value = QValueList<Object::Ptr>(), const QString& name = "list");
00054 
00058             virtual ~List();
00059 
00063             virtual const QString getClassName() const;
00064 
00070             virtual const QString toString();
00071 
00080             Object::Ptr item(uint idx);
00081 
00088             uint count();
00089 
00096             void append(Object::Ptr object);
00097 
00098     };
00099 
00104     template< class OBJECT, class TYPE >
00105     class ListT : public List
00106     {
00107         public:
00108             ListT(QValueList<TYPE> values) : List(values) {}
00109 
00110             ListT(QIntDict<TYPE> values) : List() {
00111                 QIntDictIterator<TYPE> it( values );
00112                 TYPE *t;
00113                 while( (t = it.current()) != 0 ) {
00114                     this->append( new OBJECT(t) );
00115                     ++it;
00116                 }
00117             }
00118 
00119             ListT(const QPtrList<TYPE> values) : List() {
00120                 QPtrListIterator<TYPE> it( values );
00121                 TYPE *t;
00122                 while( (t = it.current()) != 0 ) {
00123                     this->append( new OBJECT(t) );
00124                     ++it;
00125                 }
00126             }
00127 
00128             virtual ~ListT() {}
00129     };
00130 
00131 }}
00132 
00133 #endif
00134 
KDE Home | KDE Accessibility Home | Description of Access Keys