1 /****************************************************************************
3 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
5 ** This file is part of Qt Jambi.
7 ** ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** 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 ****************************************************************************/
25 /* This file is part of KDevelop
26 Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
28 This library is free software; you can redistribute it and/or
29 modify it under the terms of the GNU Library General Public
30 License version 2 as published by the Free Software Foundation.
32 This library is distributed in the hope that it will be useful,
33 but WITHOUT ANY WARRANTY; without even the implied warranty of
34 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 Library General Public License for more details.
37 You should have received a copy of the GNU Library General Public License
38 along with this library; see the file COPYING.LIB. If not, write to
39 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
40 Boston, MA 02110-1301, USA.
46 #include "smallobject.h"
48 template <typename Tp
>
53 mutable const ListNode
<Tp
> *next
;
55 static ListNode
*create(const Tp
&element
, pool
*p
)
57 ListNode
<Tp
> *node
= new (p
->allocate(sizeof(ListNode
))) ListNode();
58 node
->element
= element
;
65 static ListNode
*create(const ListNode
*n1
, const Tp
&element
, pool
*p
)
67 ListNode
<Tp
> *n2
= ListNode::create(element
, p
);
69 n2
->index
= n1
->index
+ 1;
76 inline ListNode
<Tp
>() { }
78 inline const ListNode
<Tp
> *at(int index
) const
80 const ListNode
<Tp
> *node
= this;
81 while (index
!= node
->index
)
87 inline bool hasNext() const
88 { return index
< next
->index
; }
90 inline int count() const
91 { return 1 + toBack()->index
; }
93 inline const ListNode
<Tp
> *toFront() const
94 { return toBack()->next
; }
96 inline const ListNode
<Tp
> *toBack() const
98 const ListNode
<Tp
> *node
= this;
99 while (node
->hasNext())
107 inline const ListNode
<Tp
> *snoc(const ListNode
<Tp
> *list
,
108 const Tp
&element
, pool
*p
)
111 return ListNode
<Tp
>::create(element
, p
);
113 return ListNode
<Tp
>::create(list
->toBack(), element
, p
);
118 // kate: space-indent on; indent-width 2; replace-tabs on;