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 
00046 /*
00047             operator QStringList () {
00048                 //QValueList<Object::Ptr> getValue()
00049                 krossdebug("999999999999 ...........................");
00050                 return QStringList();
00051             }
00052 */
00053 
00060             List(QValueList<Object::Ptr> value = QValueList<Object::Ptr>());
00061 
00065             virtual ~List();
00066 
00070             virtual const QString getClassName() const;
00071 
00077             virtual const QString toString();
00078 
00092             Object::Ptr item(uint idx, Object* defaultobject = 0);
00093 
00100             uint count();
00101 
00108             void append(Object::Ptr object);
00109 
00110             template<typename TYPE>
00111             static Object::Ptr toObject(TYPE t) { return t; }
00112     };
00113 
00118     template< class OBJECT >
00119     class ListT : public List
00120     {
00121         public:
00122             ListT() : List() {}
00123             ListT(QValueList<OBJECT> values) : List(values) {}
00124 
00125             template< typename TYPE >
00126             ListT(QValueList<TYPE> values) : List()
00127             {
00128                 QValueListIterator<TYPE> it(values.begin()), end(values.end());
00129                 for(; it != end; ++it)
00130                     this->append( new OBJECT(*it) );
00131             }
00132 
00133             template< typename TYPE >
00134             ListT(QIntDict<TYPE> values) : List()
00135             {
00136                 QIntDictIterator<TYPE> it( values );
00137                 TYPE *t;
00138                 while( (t = it.current()) != 0 ) {
00139                     this->append( new OBJECT(t) );
00140                     ++it;
00141                 }
00142             }
00143 
00144             template< typename TYPE >
00145             ListT(const QPtrList<TYPE> values) : List()
00146             {
00147                 QPtrListIterator<TYPE> it(values);
00148                 TYPE *t;
00149                 while( (t = it.current()) != 0 ) {
00150                     this->append( new OBJECT(t) );
00151                     ++it;
00152                 }
00153             }
00154 
00155             virtual ~ListT() {}
00156 
00157             template<typename TYPE>
00158             static Object::Ptr toObject(TYPE t)
00159             {
00160                 return new ListT(t);
00161             }
00162     };
00163 
00164 }}
00165 
00166 #endif
00167 
KDE Home | KDE Accessibility Home | Description of Access Keys