| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* | 
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * | 
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be | 
|  | 5 | * found in the LICENSE file. | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ | 
|  | 7 |  | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkDOM_DEFINED | 
|  | 9 | #define SkDOM_DEFINED | 
|  | 10 |  | 
| bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 11 | #include "../private/SkTemplates.h" | 
| Herb Derby | 70c6063 | 2017-02-14 15:21:07 -0500 | [diff] [blame] | 12 | #include "SkArenaAlloc.h" | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkScalar.h" | 
| fmalita | 7445e86 | 2016-07-14 19:14:06 -0700 | [diff] [blame] | 14 | #include "SkTypes.h" | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 |  | 
|  | 16 | struct SkDOMNode; | 
|  | 17 | struct SkDOMAttr; | 
|  | 18 |  | 
| fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 19 | class SkDOMParser; | 
| fmalita | 7445e86 | 2016-07-14 19:14:06 -0700 | [diff] [blame] | 20 | class SkStream; | 
| fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 21 | class SkXMLParser; | 
|  | 22 |  | 
| Herb Derby | 5a8fe97 | 2017-02-14 14:42:30 -0500 | [diff] [blame] | 23 | class SkDOM : public SkNoncopyable { | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | public: | 
|  | 25 | SkDOM(); | 
|  | 26 | ~SkDOM(); | 
|  | 27 |  | 
|  | 28 | typedef SkDOMNode Node; | 
|  | 29 | typedef SkDOMAttr Attr; | 
|  | 30 |  | 
|  | 31 | /** Returns null on failure | 
|  | 32 | */ | 
| fmalita | 7445e86 | 2016-07-14 19:14:06 -0700 | [diff] [blame] | 33 | const Node* build(SkStream&); | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | const Node* copy(const SkDOM& dom, const Node* node); | 
|  | 35 |  | 
|  | 36 | const Node* getRootNode() const; | 
|  | 37 |  | 
| fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 38 | SkXMLParser* beginParsing(); | 
|  | 39 | const Node* finishParsing(); | 
|  | 40 |  | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | enum Type { | 
|  | 42 | kElement_Type, | 
|  | 43 | kText_Type | 
|  | 44 | }; | 
| Mike Reed | c3063e5 | 2017-01-07 16:16:02 -0500 | [diff] [blame] | 45 | Type getType(const Node*) const; | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 |  | 
|  | 47 | const char* getName(const Node*) const; | 
|  | 48 | const Node* getFirstChild(const Node*, const char elem[] = NULL) const; | 
|  | 49 | const Node* getNextSibling(const Node*, const char elem[] = NULL) const; | 
|  | 50 |  | 
|  | 51 | const char* findAttr(const Node*, const char attrName[]) const; | 
|  | 52 | const Attr* getFirstAttr(const Node*) const; | 
|  | 53 | const Attr* getNextAttr(const Node*, const Attr*) const; | 
|  | 54 | const char* getAttrName(const Node*, const Attr*) const; | 
|  | 55 | const char* getAttrValue(const Node*, const Attr*) const; | 
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 56 |  | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | // helpers for walking children | 
|  | 58 | int countChildren(const Node* node, const char elem[] = NULL) const; | 
|  | 59 |  | 
|  | 60 | // helpers for calling SkParse | 
|  | 61 | bool findS32(const Node*, const char name[], int32_t* value) const; | 
|  | 62 | bool findScalars(const Node*, const char name[], SkScalar value[], int count) const; | 
|  | 63 | bool findHex(const Node*, const char name[], uint32_t* value) const; | 
|  | 64 | bool findBool(const Node*, const char name[], bool*) const; | 
|  | 65 | int  findList(const Node*, const char name[], const char list[]) const; | 
|  | 66 |  | 
| Mike Reed | c3063e5 | 2017-01-07 16:16:02 -0500 | [diff] [blame] | 67 | bool findScalar(const Node* node, const char name[], SkScalar value[]) const { | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | return this->findScalars(node, name, value, 1); | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 | bool hasAttr(const Node*, const char name[], const char value[]) const; | 
|  | 72 | bool hasS32(const Node*, const char name[], int32_t value) const; | 
|  | 73 | bool hasScalar(const Node*, const char name[], SkScalar value) const; | 
|  | 74 | bool hasHex(const Node*, const char name[], uint32_t value) const; | 
|  | 75 | bool hasBool(const Node*, const char name[], bool value) const; | 
|  | 76 |  | 
|  | 77 | class AttrIter { | 
|  | 78 | public: | 
| fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 79 | AttrIter(const SkDOM&, const Node*); | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | const char* next(const char** value); | 
|  | 81 | private: | 
|  | 82 | const Attr* fAttr; | 
|  | 83 | const Attr* fStop; | 
|  | 84 | }; | 
|  | 85 |  | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | private: | 
| Herb Derby | 70c6063 | 2017-02-14 15:21:07 -0500 | [diff] [blame] | 87 | SkArenaAlloc                 fAlloc; | 
| bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 88 | Node*                        fRoot; | 
|  | 89 | std::unique_ptr<SkDOMParser> fParser; | 
| fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 90 |  | 
| fmalita | 7445e86 | 2016-07-14 19:14:06 -0700 | [diff] [blame] | 91 | typedef SkNoncopyable INHERITED; | 
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | }; | 
|  | 93 |  | 
|  | 94 | #endif |