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

kjs

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

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
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |