KHtml

SVGList.h
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005 Rob Buis <[email protected]>
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 
35 namespace WebCore
36 {
37 
38 //class QualifiedName;
39 
40 template<typename Item>
41 struct SVGListTypeOperations {
42  static Item nullItem()
43  {
44  return SVGListTraits<UsesDefaultInitializer<Item>::value, Item>::nullItem();
45  }
46 };
47 
48 template<typename Item>
49 class SVGList : public RefCounted<SVGList<Item> >
50 {
51 private:
52  typedef SVGListTypeOperations<Item> TypeOperations;
53 
54 public:
55  virtual ~SVGList() { }
56 
57  const QualifiedName &associatedAttributeName() const
58  {
59  return m_associatedAttributeName;
60  }
61 
62  unsigned int numberOfItems() const
63  {
64  return m_vector.size();
65  }
66  void clear(ExceptionCode &)
67  {
68  m_vector.clear();
69  }
70 
71  Item initialize(Item newItem, ExceptionCode &ec)
72  {
73  clear(ec);
74  return appendItem(newItem, ec);
75  }
76 
77  Item getFirst() const
78  {
79  ExceptionCode ec = 0;
80  return getItem(0, ec);
81  }
82 
83  Item getLast() const
84  {
85  ExceptionCode ec = 0;
86  return getItem(m_vector.size() - 1, ec);
87  }
88 
89  Item getItem(unsigned int index, ExceptionCode &ec)
90  {
91  if (index >= m_vector.size()) {
92  ec = DOMException::INDEX_SIZE_ERR;
93  return TypeOperations::nullItem();
94  }
95 
96  return m_vector.at(index);
97  }
98 
99  const Item getItem(unsigned int index, ExceptionCode &ec) const
100  {
101  if (index >= m_vector.size()) {
102  ec = DOMException::INDEX_SIZE_ERR;
103  return TypeOperations::nullItem();
104  }
105 
106  return m_vector[index];
107  }
108 
109  Item insertItemBefore(Item newItem, unsigned int index, ExceptionCode &)
110  {
111  if (index < m_vector.size()) {
112  m_vector.insert(index, newItem);
113  } else {
114  m_vector.append(newItem);
115  }
116  return newItem;
117  }
118 
119  Item replaceItem(Item newItem, 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  m_vector[index] = newItem;
127  return newItem;
128  }
129 
130  Item removeItem(unsigned int index, ExceptionCode &ec)
131  {
132  if (index >= m_vector.size()) {
133  ec = DOMException::INDEX_SIZE_ERR;
134  return TypeOperations::nullItem();
135  }
136 
137  Item item = m_vector[index];
138  m_vector.remove(index);
139  return item;
140  }
141 
142  Item appendItem(Item newItem, ExceptionCode &)
143  {
144  m_vector.append(newItem);
145  return newItem;
146  }
147 
148 protected:
149  SVGList(const QualifiedName &attributeName)
150  : m_associatedAttributeName(attributeName)
151  {
152  }
153 
154 private:
155  Vector<Item> m_vector;
156  const QualifiedName &m_associatedAttributeName;
157 };
158 
159 template<typename Item>
160 class SVGPODListItem : public RefCounted<SVGPODListItem<Item> >
161 {
162 public:
163  static PassRefPtr<SVGPODListItem> create()
164  {
165  return adoptRef(new SVGPODListItem);
166  }
167  static PassRefPtr<SVGPODListItem> copy(const Item &item)
168  {
169  return adoptRef(new SVGPODListItem(item));
170  }
171 
172  operator Item &()
173  {
174  return m_item;
175  }
176  operator const Item &() const
177  {
178  return m_item;
179  }
180 
181  // Updating facilities, used by JSSVGPODTypeWrapperCreatorForList
182  Item value() const
183  {
184  return m_item;
185  }
186  void setValue(Item newItem)
187  {
188  m_item = newItem;
189  }
190 
191 private:
192  SVGPODListItem() : m_item() { }
193  SVGPODListItem(const Item &item) : RefCounted<SVGPODListItem<Item> >(), m_item(item) { }
194 
195  Item m_item;
196 };
197 
198 template<typename Item>
199 class SVGPODList : public SVGList<RefPtr<SVGPODListItem<Item> > >
200 {
201 public:
202  Item initialize(Item newItem, ExceptionCode &ec)
203  {
204  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::initialize(SVGPODListItem<Item>::copy(newItem), ec).get());
205  if (!ptr) {
206  return Item();
207  }
208 
209  return static_cast<const Item &>(*ptr);
210  }
211 
212  Item getFirst() const
213  {
214  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getFirst().get());
215  if (!ptr) {
216  return Item();
217  }
218 
219  return static_cast<const Item &>(*ptr);
220  }
221 
222  Item getLast() const
223  {
224  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getLast().get());
225  if (!ptr) {
226  return Item();
227  }
228 
229  return static_cast<const Item &>(*ptr);
230  }
231 
232  Item getItem(unsigned int index, ExceptionCode &ec)
233  {
234  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getItem(index, ec).get());
235  if (!ptr) {
236  return Item();
237  }
238 
239  return static_cast<const Item &>(*ptr);
240  }
241 
242  const Item getItem(unsigned int index, ExceptionCode &ec) const
243  {
244  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getItem(index, ec).get());
245  if (!ptr) {
246  return Item();
247  }
248 
249  return static_cast<const Item &>(*ptr);
250  }
251 
252  Item insertItemBefore(Item newItem, unsigned int index, ExceptionCode &ec)
253  {
254  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::insertItemBefore(SVGPODListItem<Item>::copy(newItem), index, ec).get());
255  if (!ptr) {
256  return Item();
257  }
258 
259  return static_cast<const Item &>(*ptr);
260  }
261 
262  Item replaceItem(Item newItem, unsigned int index, ExceptionCode &ec)
263  {
264  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::replaceItem(SVGPODListItem<Item>::copy(newItem), index, ec).get());
265  if (!ptr) {
266  return Item();
267  }
268 
269  return static_cast<const Item &>(*ptr);
270  }
271 
272  Item removeItem(unsigned int index, ExceptionCode &ec)
273  {
274  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::removeItem(index, ec).get());
275  if (!ptr) {
276  return Item();
277  }
278 
279  return static_cast<const Item &>(*ptr);
280  }
281 
282  Item appendItem(Item newItem, ExceptionCode &ec)
283  {
284  SVGPODListItem<Item> *ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::appendItem(SVGPODListItem<Item>::copy(newItem), ec).get());
285  if (!ptr) {
286  return Item();
287  }
288 
289  return static_cast<const Item &>(*ptr);
290  }
291 
292 protected:
293  SVGPODList(const QualifiedName &attributeName)
294  : SVGList<RefPtr<SVGPODListItem<Item> > >(attributeName) { }
295 };
296 
297 } // namespace WebCore
298 
299 #endif // ENABLE(SVG)
300 #endif // SVGList_h
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
KCRASH_EXPORT void initialize()
KIOCORE_EXPORT CopyJob * copy(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QString getItem(const QString &caption, const QString &label, const QStringList &list, int current=0, bool editable=false, bool *ok=nullptr, QWidget *parent=nullptr)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.