• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
reference_list.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2003 Apple Computer, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#include "reference_list.h"
23
24namespace KJS {
25 class ReferenceListNode {
26 friend class ReferenceList;
27 friend class ReferenceListIterator;
28
29 protected:
30 ReferenceListNode(const Reference &ref) : reference(ref), next(NULL) {}
31
32 private:
33 Reference reference;
34 ReferenceListNode *next;
35 };
36
37 class ReferenceListHeadNode : private ReferenceListNode {
38 friend class ReferenceList;
39 friend class ReferenceListIterator;
40
41 ReferenceListHeadNode(const Reference &ref) : ReferenceListNode(ref), refcount(1), length(0) {}
42 int refcount;
43 int length;
44 };
45
46}
47
48using namespace KJS;
49
50// ReferenceList
51
52ReferenceList::ReferenceList() :
53 head(NULL),
54 tail(NULL)
55{
56}
57
58ReferenceList::ReferenceList(const ReferenceList &list)
59{
60 head = list.head;
61 tail = list.tail;
62 if (head != NULL) {
63 head->refcount++;
64 }
65}
66
67ReferenceList &ReferenceList::operator=(const ReferenceList &list)
68{
69 ReferenceList tmp(list);
70 tmp.swap(*this);
71
72 return *this;
73}
74
75void ReferenceList::swap(ReferenceList &list)
76{
77 ReferenceListHeadNode *tmpHead = list.head;
78 list.head = head;
79 head = tmpHead;
80
81 ReferenceListNode *tmpTail = list.tail;
82 list.tail = tail;
83 tail = tmpTail;
84}
85
86
87void ReferenceList::append(const Reference& ref)
88{
89 if (tail == NULL) {
90 tail = head = new ReferenceListHeadNode(ref);
91 } else {
92 tail->next = new ReferenceListNode(ref);
93 tail = tail->next;
94 }
95 head->length++;
96}
97
98int ReferenceList::length()
99{
100 return head ? head->length : 0;
101}
102
103ReferenceList::~ReferenceList()
104{
105 if (head != NULL && --(head->refcount) == 0) {
106 ReferenceListNode *next;
107
108 for (ReferenceListNode *p = head; p != NULL; p = next) {
109 next = p->next;
110 if (p == head) {
111 delete (ReferenceListHeadNode *)p;
112 } else {
113 delete p;
114 }
115 }
116 }
117}
118
119ReferenceListIterator ReferenceList::begin() const
120{
121 return ReferenceListIterator(head);
122}
123
124ReferenceListIterator ReferenceList::end() const
125{
126 return ReferenceListIterator(NULL);
127}
128
129
130// ReferenceListIterator
131
132
133ReferenceListIterator::ReferenceListIterator(ReferenceListNode *n) :
134 node(n)
135{
136}
137
138bool ReferenceListIterator::operator!=(const ReferenceListIterator &it) const
139{
140 return node != it.node;
141}
142
143const Reference *ReferenceListIterator::operator->() const
144{
145 return &node->reference;
146}
147
148const Reference &ReferenceListIterator::operator++(int /*i*/)
149{
150 const Reference &ref = node->reference;
151 node = node->next;
152 return ref;
153}
KJS::ReferenceListIterator
An iterator for a ReferenceList.
Definition: reference_list.h:36
KJS::ReferenceList
A list of Reference objects.
Definition: reference_list.h:53
KJS::Reference
Defines a Javascript reference.
Definition: reference.h:34
TDEStdAccel::next
const TDEShortcut & next()

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.9.4
This website is maintained by Timothy Pearson.