1 | /* |
2 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "SVGPathUtilities.h" |
24 | #include "SVGPropertyTraits.h" |
25 | #include <wtf/Vector.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | // Type definitions for the byte stream data |
30 | typedef union { |
31 | bool value; |
32 | unsigned char bytes[sizeof(bool)]; |
33 | } BoolByte; |
34 | |
35 | typedef union { |
36 | float value; |
37 | unsigned char bytes[sizeof(float)]; |
38 | } FloatByte; |
39 | |
40 | typedef union { |
41 | unsigned short value; |
42 | unsigned char bytes[sizeof(unsigned short)]; |
43 | } UnsignedShortByte; |
44 | |
45 | class SVGPathByteStream { |
46 | WTF_MAKE_FAST_ALLOCATED; |
47 | public: |
48 | typedef Vector<unsigned char> Data; |
49 | typedef Data::const_iterator DataIterator; |
50 | |
51 | SVGPathByteStream() { } |
52 | |
53 | SVGPathByteStream(const String& string) |
54 | { |
55 | buildSVGPathByteStreamFromString(string, *this, UnalteredParsing); |
56 | } |
57 | |
58 | SVGPathByteStream(const SVGPathByteStream& other) |
59 | { |
60 | *this = other; |
61 | } |
62 | |
63 | SVGPathByteStream(SVGPathByteStream&& other) |
64 | { |
65 | *this = WTFMove(other); |
66 | } |
67 | |
68 | SVGPathByteStream& operator=(const SVGPathByteStream& other) |
69 | { |
70 | if (*this == other) |
71 | return *this; |
72 | m_data = other.m_data; |
73 | return *this; |
74 | } |
75 | |
76 | SVGPathByteStream& operator=(SVGPathByteStream&& other) |
77 | { |
78 | if (*this == other) |
79 | return *this; |
80 | m_data = WTFMove(other.m_data); |
81 | return *this; |
82 | } |
83 | |
84 | bool operator==(const SVGPathByteStream& other) const { return m_data == other.m_data; } |
85 | bool operator!=(const SVGPathByteStream& other) const { return !(*this == other); } |
86 | |
87 | std::unique_ptr<SVGPathByteStream> copy() const |
88 | { |
89 | return std::make_unique<SVGPathByteStream>(*this); |
90 | } |
91 | |
92 | DataIterator begin() const { return m_data.begin(); } |
93 | DataIterator end() const { return m_data.end(); } |
94 | |
95 | void append(unsigned char byte) { m_data.append(byte); } |
96 | void append(const SVGPathByteStream& other) { m_data.appendVector(other.m_data); } |
97 | void clear() { m_data.clear(); } |
98 | bool isEmpty() const { return m_data.isEmpty(); } |
99 | unsigned size() const { return m_data.size(); } |
100 | |
101 | private: |
102 | Data m_data; |
103 | }; |
104 | |
105 | } // namespace WebCore |
106 | |