/work/obj-fuzz/dist/include/SVGStringList.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_SVGSTRINGLIST_H__ |
8 | | #define MOZILLA_SVGSTRINGLIST_H__ |
9 | | |
10 | | #include "nsDebug.h" |
11 | | #include "nsTArray.h" |
12 | | #include "nsString.h" // IWYU pragma: keep |
13 | | |
14 | | namespace mozilla { |
15 | | |
16 | | /** |
17 | | * |
18 | | * The DOM wrapper class for this class is DOMSVGStringList. |
19 | | */ |
20 | | class SVGStringList |
21 | | { |
22 | | friend class DOMSVGStringList; |
23 | | |
24 | | public: |
25 | | |
26 | | SVGStringList() : mIsSet(false), mIsCommaSeparated(false) {} |
27 | | ~SVGStringList(){} |
28 | | |
29 | | void SetIsCommaSeparated(bool aIsCommaSeparated) { |
30 | | mIsCommaSeparated = aIsCommaSeparated; |
31 | | } |
32 | | nsresult SetValue(const nsAString& aValue); |
33 | | |
34 | | void Clear() { |
35 | | mStrings.Clear(); |
36 | | mIsSet = false; |
37 | | } |
38 | | |
39 | | /// This may return an incomplete string on OOM, but that's acceptable. |
40 | | void GetValue(nsAString& aValue) const; |
41 | | |
42 | | bool IsEmpty() const { |
43 | | return mStrings.IsEmpty(); |
44 | | } |
45 | | |
46 | | uint32_t Length() const { |
47 | | return mStrings.Length(); |
48 | | } |
49 | | |
50 | | const nsAString& operator[](uint32_t aIndex) const { |
51 | | return mStrings[aIndex]; |
52 | | } |
53 | | |
54 | 0 | bool operator==(const SVGStringList& rhs) const { |
55 | 0 | return mStrings == rhs.mStrings; |
56 | 0 | } |
57 | | |
58 | | bool SetCapacity(uint32_t size) { |
59 | | return mStrings.SetCapacity(size, fallible); |
60 | | } |
61 | | |
62 | 0 | void Compact() { |
63 | 0 | mStrings.Compact(); |
64 | 0 | } |
65 | | |
66 | | // Returns true if the value of this stringlist has been explicitly |
67 | | // set by markup or a DOM call, false otherwise. |
68 | | bool IsExplicitlySet() const |
69 | | { return mIsSet; } |
70 | | |
71 | | // Access to methods that can modify objects of this type is deliberately |
72 | | // limited. This is to reduce the chances of someone modifying objects of |
73 | | // this type without taking the necessary steps to keep DOM wrappers in sync. |
74 | | // If you need wider access to these methods, consider adding a method to |
75 | | // SVGAnimatedStringList and having that class act as an intermediary so it |
76 | | // can take care of keeping DOM wrappers in sync. |
77 | | |
78 | | protected: |
79 | | |
80 | | /** |
81 | | * This may fail on OOM if the internal capacity needs to be increased, in |
82 | | * which case the list will be left unmodified. |
83 | | */ |
84 | | nsresult CopyFrom(const SVGStringList& rhs); |
85 | | |
86 | | nsAString& operator[](uint32_t aIndex) { |
87 | | return mStrings[aIndex]; |
88 | | } |
89 | | |
90 | | /** |
91 | | * This may fail (return false) on OOM if the internal capacity is being |
92 | | * increased, in which case the list will be left unmodified. |
93 | | */ |
94 | 0 | bool SetLength(uint32_t aStringOfItems) { |
95 | 0 | return mStrings.SetLength(aStringOfItems, fallible); |
96 | 0 | } |
97 | | |
98 | | private: |
99 | | |
100 | | // Marking the following private only serves to show which methods are only |
101 | | // used by our friend classes (as opposed to our subclasses) - it doesn't |
102 | | // really provide additional safety. |
103 | | |
104 | | bool InsertItem(uint32_t aIndex, const nsAString &aString) { |
105 | | if (aIndex >= mStrings.Length()) { |
106 | | aIndex = mStrings.Length(); |
107 | | } |
108 | | if (mStrings.InsertElementAt(aIndex, aString, fallible)) { |
109 | | mIsSet = true; |
110 | | return true; |
111 | | } |
112 | | return false; |
113 | | } |
114 | | |
115 | | void ReplaceItem(uint32_t aIndex, const nsAString &aString) { |
116 | | MOZ_ASSERT(aIndex < mStrings.Length(), |
117 | | "DOM wrapper caller should have raised INDEX_SIZE_ERR"); |
118 | | mStrings[aIndex] = aString; |
119 | | } |
120 | | |
121 | | void RemoveItem(uint32_t aIndex) { |
122 | | MOZ_ASSERT(aIndex < mStrings.Length(), |
123 | | "DOM wrapper caller should have raised INDEX_SIZE_ERR"); |
124 | | mStrings.RemoveElementAt(aIndex); |
125 | | } |
126 | | |
127 | | bool AppendItem(const nsAString &aString) { |
128 | | if (mStrings.AppendElement(aString, fallible)) { |
129 | | mIsSet = true; |
130 | | return true; |
131 | | } |
132 | | return false; |
133 | | } |
134 | | |
135 | | protected: |
136 | | |
137 | | /* See SVGLengthList for the rationale for using FallibleTArray<float> instead |
138 | | * of FallibleTArray<float, 1>. |
139 | | */ |
140 | | FallibleTArray<nsString> mStrings; |
141 | | bool mIsSet; |
142 | | bool mIsCommaSeparated; |
143 | | }; |
144 | | |
145 | | } // namespace mozilla |
146 | | |
147 | | #endif // MOZILLA_SVGSTRINGLIST_H__ |