Eneboo - Documentación para desarrolladores
src/qsa/src/engine/qstypes.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qstypes.h  1.1.5   edited 2006-02-23T15:39:57$
00003 **
00004 ** Copyright (C) 2001-2006 Trolltech AS.  All rights reserved.
00005 **
00006 ** This file is part of the Qt Script for Applications framework (QSA).
00007 **
00008 ** This file may be distributed and/or modified under the terms of the
00009 ** GNU General Public License version 2 as published by the Free Software
00010 ** Foundation and appearing in the file LICENSE.GPL included in the
00011 ** packaging of this file.
00012 **
00013 ** Licensees holding a valid Qt Script for Applications license may use
00014 ** this file in accordance with the Qt Script for Applications License
00015 ** Agreement provided with the Software.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00021 **   information about QSA Commercial License Agreements.
00022 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00023 **
00024 ** Contact info@trolltech.com if any conditions of this licensing are
00025 ** not clear to you.
00026 **
00027 *****************************************************************************/
00028 
00029 #ifndef QSTYPES_H
00030 #define QSTYPES_H
00031 
00032 #include "qsvalues.h"
00033 
00034 class QSList;
00035 class QSListIterator;
00036 
00040 class QUICKCORE_EXPORT ListNode
00041 {
00042   friend class QSList;
00043   friend class QSListIterator;
00044   ListNode(QSObject obj, ListNode *p, ListNode *n)
00045     : member(obj), prev(p), next(n) {};
00046   QSObject member;
00047   ListNode *prev, *next;
00048 };
00049 
00053 class QUICKCORE_EXPORT QSListIterator
00054 {
00055   friend class QSList;
00056   QSListIterator();
00057   QSListIterator(ListNode *n) : node(n) { }
00058 public:
00063   QSListIterator(const QSList &list);
00067   QSListIterator &operator=(const QSListIterator &iterator) {
00068     node = iterator.node;
00069     return *this;
00070   }
00074   QSListIterator(const QSListIterator &i) : node(i.node) { }
00079   QSObject *operator->() const {
00080     return &node->member;
00081   }
00082   QSObject operator*() const {
00083     return node->member;
00084   }
00089   QSObject operator++() {
00090     node = node->next;
00091     return node->member;
00092   }
00096   QSObject operator++(int) {
00097     const ListNode *n = node;
00098     ++*this;
00099     return n->member;
00100   }
00104   QSObject operator--() {
00105     node = node->prev;
00106     return node->member;
00107   }
00111   QSObject operator--(int) {
00112     const ListNode *n = node;
00113     --*this;
00114     return n->member;
00115   }
00121   bool operator==(const QSListIterator &it) const {
00122     return node == it.node;
00123   }
00128   bool operator!=(const QSListIterator &it) const {
00129     return node != it.node;
00130   }
00131 private:
00132   ListNode *node;
00133 };
00134 
00145 class QUICKCORE_EXPORT QSList
00146 {
00147   friend class QSListIterator;
00148 public:
00152   QSList() {
00153 #if QS_DEBUG_MEM == 1
00154     count++;
00155 #endif
00156     init();
00157   }
00158 
00159   QSList(const QSObject &first) {
00160 #if QS_DEBUG_MEM == 1
00161     count++;
00162 #endif
00163     init();
00164     append(first);
00165   }
00166 
00170   ~QSList() {
00171 #if QS_DEBUG_MEM == 1
00172     count--;
00173 #endif
00174 
00175     clear();
00176     delete hook;
00177   }
00183   void append(const QSObject &obj);
00189   void prepend(const QSObject &obj);
00193   void removeFirst();
00197   void removeLast();
00198   /*
00199    * Remove obj from list.
00200    */
00201   void remove(const QSObject &obj);
00205   void clear();
00210   QSList *copy() const;
00214   QSListIterator begin() const {
00215     return QSListIterator(hook->next);
00216   }
00220   QSListIterator end() const {
00221     return QSListIterator(hook);
00222   }
00226   bool isEmpty() const {
00227     return hook->prev == hook;
00228   }
00232   int size() const {
00233     //### AbanQ
00234     return size_;
00235   }
00244   QSObject at(int i) const;
00248   QSObject operator[](int i) const {
00249     return at(i);
00250   }
00251 
00252 #if QS_DEBUG_MEM == 1
00253 
00256   static int count;
00257 #endif
00258 private:
00259   // not implemented
00260   QSList(const QSList &);
00261   QSList &operator=(const QSList &);
00262 
00263   void init();
00264   void erase(ListNode *n);
00265   ListNode *hook;
00266 
00267   //### AbanQ
00268   int size_;
00269 };
00270 
00271 //### AbanQ
00272 inline void QSList::init()
00273 {
00274   hook = new ListNode(QSObject(), 0L, 0L);
00275   hook->next = hook;
00276   hook->prev = hook;
00277 
00278   //### AbanQ
00279   size_ = 0;
00280 }
00281 inline void QSList::append(const QSObject &obj)
00282 {
00283   ListNode *n = new ListNode(obj, hook->prev, hook);
00284   hook->prev->next = n;
00285   hook->prev = n;
00286 
00287   //### AbanQ
00288   ++size_;
00289 }
00290 inline void QSList::prepend(const QSObject &obj)
00291 {
00292   ListNode *n = new ListNode(obj, hook, hook->next);
00293   hook->next->prev = n;
00294   hook->next = n;
00295 
00296   //### AbanQ
00297   ++size_;
00298 }
00299 inline void QSList::removeFirst()
00300 {
00301   erase(hook->next);
00302 }
00303 inline void QSList::removeLast()
00304 {
00305   erase(hook->prev);
00306 }
00307 inline void QSList::remove(const QSObject &obj)
00308 {
00309   Q_UNUSED(obj)
00310 
00311 #if 0 // ###
00312   if (!obj.isValid())
00313     return;
00314 
00315   ListNode *n = hook->next;
00316   while (n != hook) {
00317     if (n->member.imp() == obj.imp()) {
00318       erase(n);
00319       return;
00320     }
00321     n = n->next;
00322   }
00323 #endif
00324 }
00325 inline void QSList::clear()
00326 {
00327   ListNode *n = hook->next;
00328   while (n != hook) {
00329     n = n->next;
00330     delete n->prev;
00331   }
00332 
00333   hook->next = hook;
00334   hook->prev = hook;
00335 
00336   //### AbanQ
00337   size_ = 0;
00338 }
00339 inline QSList *QSList::copy() const
00340 {
00341   QSList *newList = new QSList();
00342   QSListIterator e = end();
00343   QSListIterator it = begin();
00344 
00345   while (it != e) {
00346     newList->append(*it);
00347     ++it;
00348   }
00349 
00350   return newList;
00351 }
00352 inline void QSList::erase(ListNode *n)
00353 {
00354   if (n != hook) {
00355     n->next->prev = n->prev;
00356     n->prev->next = n->next;
00357     delete n;
00358 
00359     //### AbanQ
00360     --size_;
00361   }
00362 }
00363 inline QSObject QSList::at(int i) const
00364 {
00365   const ListNode *n = hook->next;
00366   while (i > 0 && n != hook) {
00367     n = n->next;
00368     --i;
00369   }
00370   return n->member;
00371 }
00372 //### AbanQ
00373 
00374 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'