31 #include <wtf/RefCounted.h>
32 #include <wtf/PassRefPtr.h>
33 #include <wtf/Vector.h>
39 template<
typename Item>
40 struct SVGListTypeOperations {
41 static Item nullItem()
43 return SVGListTraits<UsesDefaultInitializer<Item>::value,
Item>::nullItem();
47 template<
typename Item>
48 class SVGList :
public RefCounted<SVGList<Item> > {
50 typedef SVGListTypeOperations<Item> TypeOperations;
53 virtual ~SVGList() { }
55 const QualifiedName& associatedAttributeName()
const {
return m_associatedAttributeName; }
57 unsigned int numberOfItems()
const {
return m_vector.size(); }
58 void clear(ExceptionCode &) { m_vector.clear(); }
60 Item initialize(Item newItem, ExceptionCode& ec)
63 return appendItem(newItem, ec);
75 return getItem(m_vector.size() - 1, ec);
80 if (index >= m_vector.size()) {
81 ec = DOMException::INDEX_SIZE_ERR;
82 return TypeOperations::nullItem();
85 return m_vector.at(index);
88 const Item getItem(
unsigned int index, ExceptionCode& ec)
const
90 if (index >= m_vector.size()) {
91 ec = DOMException::INDEX_SIZE_ERR;
92 return TypeOperations::nullItem();
95 return m_vector[index];
98 Item insertItemBefore(Item newItem,
unsigned int index, ExceptionCode&)
100 if (index < m_vector.size()) {
101 m_vector.insert(index, newItem);
103 m_vector.append(newItem);
108 Item replaceItem(Item newItem,
unsigned int index, ExceptionCode& ec)
110 if (index >= m_vector.size()) {
111 ec = DOMException::INDEX_SIZE_ERR;
112 return TypeOperations::nullItem();
115 m_vector[index] = newItem;
119 Item removeItem(
unsigned int index, ExceptionCode& ec)
121 if (index >= m_vector.size()) {
122 ec = DOMException::INDEX_SIZE_ERR;
123 return TypeOperations::nullItem();
126 Item item = m_vector[index];
127 m_vector.remove(index);
131 Item appendItem(Item newItem, ExceptionCode&)
133 m_vector.append(newItem);
138 SVGList(
const QualifiedName& attributeName)
139 : m_associatedAttributeName(attributeName)
144 Vector<Item> m_vector;
145 const QualifiedName& m_associatedAttributeName;
148 template<
typename Item>
149 class SVGPODListItem :
public RefCounted<SVGPODListItem<Item> > {
151 static PassRefPtr<SVGPODListItem>
create() {
return adoptRef(
new SVGPODListItem); }
152 static PassRefPtr<SVGPODListItem>
copy(
const Item& item) {
return adoptRef(
new SVGPODListItem(item)); }
154 operator Item&() {
return m_item; }
155 operator const Item&()
const {
return m_item; }
158 Item value()
const {
return m_item; }
159 void setValue(Item newItem) { m_item = newItem; }
162 SVGPODListItem() : m_item() { }
163 SVGPODListItem(
const Item& item) : RefCounted<SVGPODListItem<
Item> >(), m_item(item) { }
168 template<
typename Item>
169 class SVGPODList :
public SVGList<RefPtr<SVGPODListItem<Item> > >
172 Item initialize(Item newItem, ExceptionCode& ec)
174 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::initialize(SVGPODListItem<Item>::copy(newItem), ec).
get());
178 return static_cast<const Item&
>(*ptr);
181 Item getFirst()
const
183 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getFirst().
get());
187 return static_cast<const Item&
>(*ptr);
192 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::getLast().
get());
196 return static_cast<const Item&
>(*ptr);
199 Item getItem(
unsigned int index, ExceptionCode& ec)
201 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::
getItem(index, ec).
get());
205 return static_cast<const Item&
>(*ptr);
208 const Item getItem(
unsigned int index, ExceptionCode& ec)
const
210 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::
getItem(index, ec).
get());
214 return static_cast<const Item&
>(*ptr);
217 Item insertItemBefore(Item newItem,
unsigned int index, ExceptionCode& ec)
219 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::insertItemBefore(SVGPODListItem<Item>::copy(newItem), index, ec).
get());
223 return static_cast<const Item&
>(*ptr);
226 Item replaceItem(Item newItem,
unsigned int index, ExceptionCode& ec)
228 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::replaceItem(SVGPODListItem<Item>::copy(newItem), index, ec).
get());
232 return static_cast<const Item&
>(*ptr);
235 Item removeItem(
unsigned int index, ExceptionCode& ec)
237 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::removeItem(index, ec).
get());
241 return static_cast<const Item&
>(*ptr);
244 Item appendItem(Item newItem, ExceptionCode& ec)
246 SVGPODListItem<Item>* ptr(SVGList<RefPtr<SVGPODListItem<Item> > >::appendItem(SVGPODListItem<Item>::copy(newItem), ec).
get());
250 return static_cast<const Item&
>(*ptr);
254 SVGPODList(
const QualifiedName& attributeName)
255 : SVGList<RefPtr<SVGPODListItem<
Item> > >(attributeName) { }
260 #endif // ENABLE(SVG)
KAction * copy(const QObject *recvr, const char *slot, QObject *parent)
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)