• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
SVGList.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#ifndef SVGList_h
24#define SVGList_h
25
26#if ENABLE(SVG)
27#include "ExceptionCode.h"
28#include "SVGListTraits.h"
29#include "Document.h"
30
31#include <wtf/RefCounted.h>
32#include <wtf/PassRefPtr.h>
33#include <wtf/Vector.h>
34
35namespace WebCore {
36
37 //class QualifiedName;
38
39 template<typename Item>
40 struct SVGListTypeOperations {
41 static Item nullItem()
42 {
43 return SVGListTraits<UsesDefaultInitializer<Item>::value, Item>::nullItem();
44 }
45 };
46
47 template<typename Item>
48 class SVGList : public RefCounted<SVGList<Item> > {
49 private:
50 typedef SVGListTypeOperations<Item> TypeOperations;
51
52 public:
53 virtual ~SVGList() { }
54
55 const QualifiedName& associatedAttributeName() const { return m_associatedAttributeName; }
56
57 unsigned int numberOfItems() const { return m_vector.size(); }
58 void clear(ExceptionCode &) { m_vector.clear(); }
59
60 Item initialize(Item newItem, ExceptionCode& ec)
61 {
62 clear(ec);
63 return appendItem(newItem, ec);
64 }
65
66 Item getFirst() const
67 {
68 ExceptionCode ec = 0;
69 return getItem(0, ec);
70 }
71
72 Item getLast() const
73 {
74 ExceptionCode ec = 0;
75 return getItem(m_vector.size() - 1, ec);
76 }
77
78 Item getItem(unsigned int index, ExceptionCode& ec)
79 {
80 if (index >= m_vector.size()) {
81 ec = DOMException::INDEX_SIZE_ERR;
82 return TypeOperations::nullItem();
83 }
84
85 return m_vector.at(index);
86 }
87
88 const Item getItem(unsigned int index, ExceptionCode& ec) const
89 {
90 if (index >= m_vector.size()) {
91 ec = DOMException::INDEX_SIZE_ERR;
92 return TypeOperations::nullItem();
93 }
94
95 return m_vector[index];
96 }
97
98 Item insertItemBefore(Item newItem, unsigned int index, ExceptionCode&)
99 {
100 if (index < m_vector.size()) {
101 m_vector.insert(index, newItem);
102 } else {
103 m_vector.append(newItem);
104 }
105 return newItem;
106 }
107
108 Item replaceItem(Item newItem, unsigned int index, ExceptionCode& ec)
109 {
110 if (index >= m_vector.size()) {
111 ec = DOMException::INDEX_SIZE_ERR;
112 return TypeOperations::nullItem();
113 }
114
115 m_vector[index] = newItem;
116 return newItem;
117 }
118
119 Item removeItem(unsigned int index, ExceptionCode& ec)
120 {
121 if (index >= m_vector.size()) {
122 ec = DOMException::INDEX_SIZE_ERR;
123 return TypeOperations::nullItem();
124 }
125
126 Item item = m_vector[index];
127 m_vector.remove(index);
128 return item;
129 }
130
131 Item appendItem(Item newItem, ExceptionCode&)
132 {
133 m_vector.append(newItem);
134 return newItem;
135 }
136
137 protected:
138 SVGList(const QualifiedName& attributeName)
139 : m_associatedAttributeName(attributeName)
140 {
141 }
142
143 private:
144 Vector<Item> m_vector;
145 const QualifiedName& m_associatedAttributeName;
146 };
147
148 template<typename Item>
149 class SVGPODListItem : public RefCounted<SVGPODListItem<Item> > {
150 public:
151 static PassRefPtr<SVGPODListItem> create() { return adoptRef(new SVGPODListItem); }
152 static PassRefPtr<SVGPODListItem> copy(const Item& item) { return adoptRef(new SVGPODListItem(item)); }
153
154 operator Item&() { return m_item; }
155 operator const Item&() const { return m_item; }
156
157 // Updating facilities, used by JSSVGPODTypeWrapperCreatorForList
158 Item value() const { return m_item; }
159 void setValue(Item newItem) { m_item = newItem; }
160
161 private:
162 SVGPODListItem() : m_item() { }
163 SVGPODListItem(const Item& item) : RefCounted<SVGPODListItem<Item> >(), m_item(item) { }
164
165 Item m_item;
166 };
167
168 template<typename Item>
169 class SVGPODList : public SVGList<RefPtr<SVGPODListItem<Item> > >
170 {
171 public:
172 Item initialize(Item newItem, ExceptionCode& ec)
173 {
174 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::initialize(SVGPODListItem<Item>::copy(newItem), ec).get());
175 if (!ptr)
176 return Item();
177
178 return static_cast<const Item&>(*ptr);
179 }
180
181 Item getFirst() const
182 {
183 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getFirst().get());
184 if (!ptr)
185 return Item();
186
187 return static_cast<const Item&>(*ptr);
188 }
189
190 Item getLast() const
191 {
192 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getLast().get());
193 if (!ptr)
194 return Item();
195
196 return static_cast<const Item&>(*ptr);
197 }
198
199 Item getItem(unsigned int index, ExceptionCode& ec)
200 {
201 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getItem(index, ec).get());
202 if (!ptr)
203 return Item();
204
205 return static_cast<const Item&>(*ptr);
206 }
207
208 const Item getItem(unsigned int index, ExceptionCode& ec) const
209 {
210 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getItem(index, ec).get());
211 if (!ptr)
212 return Item();
213
214 return static_cast<const Item&>(*ptr);
215 }
216
217 Item insertItemBefore(Item newItem, unsigned int index, ExceptionCode& ec)
218 {
219 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::insertItemBefore(SVGPODListItem<Item>::copy(newItem), index, ec).get());
220 if (!ptr)
221 return Item();
222
223 return static_cast<const Item&>(*ptr);
224 }
225
226 Item replaceItem(Item newItem, unsigned int index, ExceptionCode& ec)
227 {
228 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::replaceItem(SVGPODListItem<Item>::copy(newItem), index, ec).get());
229 if (!ptr)
230 return Item();
231
232 return static_cast<const Item&>(*ptr);
233 }
234
235 Item removeItem(unsigned int index, ExceptionCode& ec)
236 {
237 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::removeItem(index, ec).get());
238 if (!ptr)
239 return Item();
240
241 return static_cast<const Item&>(*ptr);
242 }
243
244 Item appendItem(Item newItem, ExceptionCode& ec)
245 {
246 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::appendItem(SVGPODListItem<Item>::copy(newItem), ec).get());
247 if (!ptr)
248 return Item();
249
250 return static_cast<const Item&>(*ptr);
251 }
252
253 protected:
254 SVGPODList(const QualifiedName& attributeName)
255 : SVGList<RefPtr<SVGPODListItem<Item> > >(attributeName) { }
256 };
257
258} // namespace WebCore
259
260#endif // ENABLE(SVG)
261#endif // SVGList_h
ExceptionCode.h
SVGListTraits.h
newItem
QString newItem(const QString &type, const QString &name, const QString &key, const QString &defaultValue, const CfgConfig &cfg, const QString &param=QString())
get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
getItem
QString getItem(const QString &caption, const QString &label, const QStringList &list, int current=0, bool editable=false, bool *ok=0, QWidget *parent=0)
copy
KAction * copy(const QObject *recvr, const char *slot, QObject *parent)
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
Item
Item
WebCore
Definition: CSSHelper.h:7
khtml::ExceptionCode
unsigned short ExceptionCode
Definition: ExceptionCode.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal