lib
list.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00048
00049
00050
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
|