use separate slot implementation for each module
[lqt.git] / cpptoxml / parser / list.h
blobe25a6d93eca5064ee12280fca54b1a85c92b0813
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
26 #ifndef FASTLIST_H
27 #define FASTLIST_H
29 #include "smallobject.h"
31 template <typename Tp>
32 struct ListNode
34 Tp element;
35 int index;
36 mutable const ListNode<Tp> *next;
38 static ListNode *create(const Tp &element, pool *p)
40 ListNode<Tp> *node = new (p->allocate(sizeof(ListNode))) ListNode();
41 node->element = element;
42 node->index = 0;
43 node->next = node;
45 return node;
48 static ListNode *create(const ListNode *n1, const Tp &element, pool *p)
50 ListNode<Tp> *n2 = ListNode::create(element, p);
52 n2->index = n1->index + 1;
53 n2->next = n1->next;
54 n1->next = n2;
56 return n2;
59 inline ListNode<Tp>() { }
61 inline const ListNode<Tp> *at(int index) const
63 const ListNode<Tp> *node = this;
64 while (index != node->index)
65 node = node->next;
67 return node;
70 inline bool hasNext() const
71 { return index < next->index; }
73 inline int count() const
74 { return 1 + toBack()->index; }
76 inline const ListNode<Tp> *toFront() const
77 { return toBack()->next; }
79 inline const ListNode<Tp> *toBack() const
81 const ListNode<Tp> *node = this;
82 while (node->hasNext())
83 node = node->next;
85 return node;
89 template <class Tp>
90 inline const ListNode<Tp> *snoc(const ListNode<Tp> *list,
91 const Tp &element, pool *p)
93 if (!list)
94 return ListNode<Tp>::create(element, p);
96 return ListNode<Tp>::create(list->toBack(), element, p);
99 #endif // FASTLIST_H
101 // kate: space-indent on; indent-width 2; replace-tabs on;