/src/skia/src/xml/SkDOM.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2006 The Android Open Source Project |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #ifndef SkDOM_DEFINED |
9 | | #define SkDOM_DEFINED |
10 | | |
11 | | #include "include/core/SkScalar.h" |
12 | | #include "include/core/SkTypes.h" |
13 | | #include "include/private/base/SkNoncopyable.h" |
14 | | #include "include/private/base/SkTemplates.h" |
15 | | #include "src/base/SkArenaAlloc.h" |
16 | | |
17 | | struct SkDOMNode; |
18 | | struct SkDOMAttr; |
19 | | |
20 | | class SkDOMParser; |
21 | | class SkStream; |
22 | | class SkXMLParser; |
23 | | |
24 | | class SkDOM : public SkNoncopyable { |
25 | | public: |
26 | | SkDOM(); |
27 | | ~SkDOM(); |
28 | | |
29 | | typedef SkDOMNode Node; |
30 | | typedef SkDOMAttr Attr; |
31 | | |
32 | | /** Returns null on failure |
33 | | */ |
34 | | const Node* build(SkStream&); |
35 | | const Node* copy(const SkDOM& dom, const Node* node); |
36 | | |
37 | | const Node* getRootNode() const; |
38 | | |
39 | | SkXMLParser* beginParsing(); |
40 | | const Node* finishParsing(); |
41 | | |
42 | | enum Type { |
43 | | kElement_Type, |
44 | | kText_Type |
45 | | }; |
46 | | Type getType(const Node*) const; |
47 | | |
48 | | const char* getName(const Node*) const; |
49 | | const Node* getFirstChild(const Node*, const char elem[] = nullptr) const; |
50 | | const Node* getNextSibling(const Node*, const char elem[] = nullptr) const; |
51 | | |
52 | | const char* findAttr(const Node*, const char attrName[]) const; |
53 | | const Attr* getFirstAttr(const Node*) const; |
54 | | const Attr* getNextAttr(const Node*, const Attr*) const; |
55 | | const char* getAttrName(const Node*, const Attr*) const; |
56 | | const char* getAttrValue(const Node*, const Attr*) const; |
57 | | |
58 | | // helpers for walking children |
59 | | int countChildren(const Node* node, const char elem[] = nullptr) const; |
60 | | |
61 | | // helpers for calling SkParse |
62 | | bool findS32(const Node*, const char name[], int32_t* value) const; |
63 | | bool findScalars(const Node*, const char name[], SkScalar value[], int count) const; |
64 | | bool findHex(const Node*, const char name[], uint32_t* value) const; |
65 | | bool findBool(const Node*, const char name[], bool*) const; |
66 | | int findList(const Node*, const char name[], const char list[]) const; |
67 | | |
68 | 0 | bool findScalar(const Node* node, const char name[], SkScalar value[]) const { |
69 | 0 | return this->findScalars(node, name, value, 1); |
70 | 0 | } |
71 | | |
72 | | bool hasAttr(const Node*, const char name[], const char value[]) const; |
73 | | bool hasS32(const Node*, const char name[], int32_t value) const; |
74 | | bool hasScalar(const Node*, const char name[], SkScalar value) const; |
75 | | bool hasHex(const Node*, const char name[], uint32_t value) const; |
76 | | bool hasBool(const Node*, const char name[], bool value) const; |
77 | | |
78 | | class AttrIter { |
79 | | public: |
80 | | AttrIter(const SkDOM&, const Node*); |
81 | | const char* next(const char** value); |
82 | | private: |
83 | | const Attr* fAttr; |
84 | | const Attr* fStop; |
85 | | }; |
86 | | |
87 | | private: |
88 | | SkArenaAllocWithReset fAlloc; |
89 | | Node* fRoot; |
90 | | std::unique_ptr<SkDOMParser> fParser; |
91 | | |
92 | | using INHERITED = SkNoncopyable; |
93 | | }; |
94 | | |
95 | | #endif |