Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | List of all members
SkDOM Class Reference

#include <SkDOM.h>

Inheritance diagram for SkDOM:
SkNoncopyable

Classes

class  AttrIter
 

Public Types

enum  Type { kElement_Type , kText_Type }
 
typedef SkDOMNode Node
 
typedef SkDOMAttr Attr
 

Public Member Functions

 SkDOM ()
 
 ~SkDOM ()
 
const Nodebuild (SkStream &)
 
const Nodecopy (const SkDOM &dom, const Node *node)
 
const NodegetRootNode () const
 
SkXMLParserbeginParsing ()
 
const NodefinishParsing ()
 
Type getType (const Node *) const
 
const char * getName (const Node *) const
 
const NodegetFirstChild (const Node *, const char elem[]=nullptr) const
 
const NodegetNextSibling (const Node *, const char elem[]=nullptr) const
 
const char * findAttr (const Node *, const char attrName[]) const
 
const AttrgetFirstAttr (const Node *) const
 
const AttrgetNextAttr (const Node *, const Attr *) const
 
const char * getAttrName (const Node *, const Attr *) const
 
const char * getAttrValue (const Node *, const Attr *) const
 
int countChildren (const Node *node, const char elem[]=nullptr) const
 
bool findS32 (const Node *, const char name[], int32_t *value) const
 
bool findScalars (const Node *, const char name[], SkScalar value[], int count) const
 
bool findHex (const Node *, const char name[], uint32_t *value) const
 
bool findBool (const Node *, const char name[], bool *) const
 
int findList (const Node *, const char name[], const char list[]) const
 
bool findScalar (const Node *node, const char name[], SkScalar value[]) const
 
bool hasAttr (const Node *, const char name[], const char value[]) const
 
bool hasS32 (const Node *, const char name[], int32_t value) const
 
bool hasScalar (const Node *, const char name[], SkScalar value) const
 
bool hasHex (const Node *, const char name[], uint32_t value) const
 
bool hasBool (const Node *, const char name[], bool value) const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Detailed Description

Definition at line 24 of file SkDOM.h.

Member Typedef Documentation

◆ Attr

Definition at line 30 of file SkDOM.h.

◆ Node

Definition at line 29 of file SkDOM.h.

Member Enumeration Documentation

◆ Type

Enumerator
kElement_Type 
kText_Type 

Definition at line 42 of file SkDOM.h.

42 {
45 };
@ kText_Type
Definition: SkDOM.h:44
@ kElement_Type
Definition: SkDOM.h:43

Constructor & Destructor Documentation

◆ SkDOM()

SkDOM::SkDOM ( )

Definition at line 72 of file SkDOM.cpp.

72: fAlloc(kMinChunkSize), fRoot(nullptr) {}
#define kMinChunkSize
Definition: SkDOM.cpp:70

◆ ~SkDOM()

SkDOM::~SkDOM ( )

Definition at line 74 of file SkDOM.cpp.

74{}

Member Function Documentation

◆ beginParsing()

SkXMLParser * SkDOM::beginParsing ( )

Definition at line 344 of file SkDOM.cpp.

344 {
345 SkASSERT(!fParser);
346 fParser = std::make_unique<SkDOMParser>(&fAlloc);
347
348 return fParser.get();
349}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ build()

const SkDOM::Node * SkDOM::build ( SkStream docStream)

Returns null on failure

Definition at line 294 of file SkDOM.cpp.

294 {
295 SkDOMParser parser(&fAlloc);
296 if (!parser.parse(docStream))
297 {
298 SkDEBUGCODE(SkDebugf("xml parse error, line %d\n", parser.fParserError.getLineNumber());)
299 fRoot = nullptr;
300 fAlloc.reset();
301 return nullptr;
302 }
303 fRoot = parser.getRoot();
304 return fRoot;
305}
m reset()
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
parser
Definition: zip.py:78

◆ copy()

const SkDOM::Node * SkDOM::copy ( const SkDOM dom,
const Node node 
)

Definition at line 335 of file SkDOM.cpp.

335 {
336 SkDOMParser parser(&fAlloc);
337
338 walk_dom(dom, node, &parser);
339
340 fRoot = parser.getRoot();
341 return fRoot;
342}
static void walk_dom(const SkDOM &dom, const SkDOM::Node *node, SkXMLParser *parser)
Definition: SkDOM.cpp:309
Definition: dom.py:1

◆ countChildren()

int SkDOM::countChildren ( const Node node,
const char  elem[] = nullptr 
) const

Definition at line 361 of file SkDOM.cpp.

361 {
362 int count = 0;
363
364 node = this->getFirstChild(node, elem);
365 while (node) {
366 count += 1;
367 node = this->getNextSibling(node, elem);
368 }
369 return count;
370}
int count
Definition: FontMgrTest.cpp:50
const Node * getNextSibling(const Node *, const char elem[]=nullptr) const
Definition: SkDOM.cpp:94
const Node * getFirstChild(const Node *, const char elem[]=nullptr) const
Definition: SkDOM.cpp:80

◆ findAttr()

const char * SkDOM::findAttr ( const Node node,
const char  attrName[] 
) const

Definition at line 117 of file SkDOM.cpp.

117 {
118 SkASSERT(node);
119 const Attr* attr = node->attrs();
120 const Attr* stop = attr + node->fAttrCount;
121
122 while (attr < stop) {
123 if (!strcmp(attr->fName, name)) {
124 return attr->fValue;
125 }
126 attr += 1;
127 }
128 return nullptr;
129}
SkDOMAttr Attr
Definition: SkDOM.h:30
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ findBool()

bool SkDOM::findBool ( const Node node,
const char  name[],
bool *  value 
) const

Definition at line 391 of file SkDOM.cpp.

391 {
392 const char* vstr = this->findAttr(node, name);
393 return vstr && SkParse::FindBool(vstr, value);
394}
const char * findAttr(const Node *, const char attrName[]) const
Definition: SkDOM.cpp:117
static bool FindBool(const char str[], bool *value)
Definition: SkParse.cpp:260
uint8_t value

◆ findHex()

bool SkDOM::findHex ( const Node node,
const char  name[],
uint32_t *  value 
) const

Definition at line 386 of file SkDOM.cpp.

386 {
387 const char* vstr = this->findAttr(node, name);
388 return vstr && SkParse::FindHex(vstr, value);
389}
static const char * FindHex(const char str[], uint32_t *value)
Definition: SkParse.cpp:114

◆ findList()

int SkDOM::findList ( const Node node,
const char  name[],
const char  list[] 
) const

Definition at line 396 of file SkDOM.cpp.

396 {
397 const char* vstr = this->findAttr(node, name);
398 return vstr ? SkParse::FindList(vstr, list) : -1;
399}
static int FindList(const char str[], const char list[])
Definition: SkParse.cpp:278

◆ findS32()

bool SkDOM::findS32 ( const Node node,
const char  name[],
int32_t *  value 
) const

Definition at line 376 of file SkDOM.cpp.

376 {
377 const char* vstr = this->findAttr(node, name);
378 return vstr && SkParse::FindS32(vstr, value);
379}
static const char * FindS32(const char str[], int32_t *value)
Definition: SkParse.cpp:143

◆ findScalar()

bool SkDOM::findScalar ( const Node node,
const char  name[],
SkScalar  value[] 
) const
inline

Definition at line 68 of file SkDOM.h.

68 {
69 return this->findScalars(node, name, value, 1);
70 }
bool findScalars(const Node *, const char name[], SkScalar value[], int count) const
Definition: SkDOM.cpp:381

◆ findScalars()

bool SkDOM::findScalars ( const Node node,
const char  name[],
SkScalar  value[],
int  count 
) const

Definition at line 381 of file SkDOM.cpp.

381 {
382 const char* vstr = this->findAttr(node, name);
383 return vstr && SkParse::FindScalars(vstr, value, count);
384}
static const char * FindScalars(const char str[], SkScalar value[], int count)
Definition: SkParse.cpp:231

◆ finishParsing()

const SkDOM::Node * SkDOM::finishParsing ( )

Definition at line 351 of file SkDOM.cpp.

351 {
352 SkASSERT(fParser);
353 fRoot = fParser->getRoot();
354 fParser.reset();
355
356 return fRoot;
357}

◆ getAttrName()

const char * SkDOM::getAttrName ( const Node node,
const Attr attr 
) const

Definition at line 145 of file SkDOM.cpp.

145 {
146 SkASSERT(node);
147 SkASSERT(attr);
148 return attr->fName;
149}

◆ getAttrValue()

const char * SkDOM::getAttrValue ( const Node node,
const Attr attr 
) const

Definition at line 151 of file SkDOM.cpp.

151 {
152 SkASSERT(node);
153 SkASSERT(attr);
154 return attr->fValue;
155}

◆ getFirstAttr()

const SkDOM::Attr * SkDOM::getFirstAttr ( const Node node) const

Definition at line 133 of file SkDOM.cpp.

133 {
134 return node->fAttrCount ? node->attrs() : nullptr;
135}

◆ getFirstChild()

const SkDOM::Node * SkDOM::getFirstChild ( const Node node,
const char  elem[] = nullptr 
) const

Definition at line 80 of file SkDOM.cpp.

80 {
81 SkASSERT(node);
82 const Node* child = node->fFirstChild;
83
84 if (name) {
85 for (; child != nullptr; child = child->fNextSibling) {
86 if (!strcmp(name, child->fName)) {
87 break;
88 }
89 }
90 }
91 return child;
92}
Definition: dart.idl:29

◆ getName()

const char * SkDOM::getName ( const Node node) const

Definition at line 112 of file SkDOM.cpp.

112 {
113 SkASSERT(node);
114 return node->fName;
115}

◆ getNextAttr()

const SkDOM::Attr * SkDOM::getNextAttr ( const Node node,
const Attr attr 
) const

Definition at line 137 of file SkDOM.cpp.

137 {
138 SkASSERT(node);
139 if (attr == nullptr) {
140 return nullptr;
141 }
142 return (attr - node->attrs() + 1) < node->fAttrCount ? attr + 1 : nullptr;
143}

◆ getNextSibling()

const SkDOM::Node * SkDOM::getNextSibling ( const Node node,
const char  elem[] = nullptr 
) const

Definition at line 94 of file SkDOM.cpp.

94 {
95 SkASSERT(node);
96 const Node* sibling = node->fNextSibling;
97 if (name) {
98 for (; sibling != nullptr; sibling = sibling->fNextSibling) {
99 if (!strcmp(name, sibling->fName)) {
100 break;
101 }
102 }
103 }
104 return sibling;
105}

◆ getRootNode()

const SkDOM::Node * SkDOM::getRootNode ( ) const

Definition at line 76 of file SkDOM.cpp.

76 {
77 return fRoot;
78}

◆ getType()

SkDOM::Type SkDOM::getType ( const Node node) const

Definition at line 107 of file SkDOM.cpp.

107 {
108 SkASSERT(node);
109 return (Type)node->fType;
110}

◆ hasAttr()

bool SkDOM::hasAttr ( const Node node,
const char  name[],
const char  value[] 
) const

Definition at line 401 of file SkDOM.cpp.

401 {
402 const char* vstr = this->findAttr(node, name);
403 return vstr && !strcmp(vstr, value);
404}

◆ hasBool()

bool SkDOM::hasBool ( const Node node,
const char  name[],
bool  value 
) const

Definition at line 424 of file SkDOM.cpp.

424 {
425 const char* vstr = this->findAttr(node, name);
426 bool value;
427 return vstr && SkParse::FindBool(vstr, &value) && value == target;
428}
uint32_t * target

◆ hasHex()

bool SkDOM::hasHex ( const Node node,
const char  name[],
uint32_t  value 
) const

Definition at line 418 of file SkDOM.cpp.

418 {
419 const char* vstr = this->findAttr(node, name);
420 uint32_t value;
421 return vstr && SkParse::FindHex(vstr, &value) && value == target;
422}

◆ hasS32()

bool SkDOM::hasS32 ( const Node node,
const char  name[],
int32_t  value 
) const

Definition at line 406 of file SkDOM.cpp.

406 {
407 const char* vstr = this->findAttr(node, name);
408 int32_t value;
409 return vstr && SkParse::FindS32(vstr, &value) && value == target;
410}

◆ hasScalar()

bool SkDOM::hasScalar ( const Node node,
const char  name[],
SkScalar  value 
) const

Definition at line 412 of file SkDOM.cpp.

412 {
413 const char* vstr = this->findAttr(node, name);
415 return vstr && SkParse::FindScalar(vstr, &value) && value == target;
416}
static const char * FindScalar(const char str[], SkScalar *value)
Definition: SkParse.cpp:216
float SkScalar
Definition: extension.cpp:12

The documentation for this class was generated from the following files: