2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkDOM_DEFINED
|
|
|
|
#define SkDOM_DEFINED
|
|
|
|
|
2016-11-07 19:23:59 +00:00
|
|
|
#include "../private/SkChunkAlloc.h"
|
2015-08-19 18:56:48 +00:00
|
|
|
#include "../private/SkTemplates.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkScalar.h"
|
2016-07-15 02:14:06 +00:00
|
|
|
#include "SkTypes.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
struct SkDOMNode;
|
|
|
|
struct SkDOMAttr;
|
|
|
|
|
2015-02-20 21:54:40 +00:00
|
|
|
class SkDOMParser;
|
2016-07-15 02:14:06 +00:00
|
|
|
class SkStream;
|
2015-02-20 21:54:40 +00:00
|
|
|
class SkXMLParser;
|
|
|
|
|
2016-07-15 02:14:06 +00:00
|
|
|
class SK_API SkDOM : public SkNoncopyable {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
|
|
|
SkDOM();
|
|
|
|
~SkDOM();
|
|
|
|
|
|
|
|
typedef SkDOMNode Node;
|
|
|
|
typedef SkDOMAttr Attr;
|
|
|
|
|
|
|
|
/** Returns null on failure
|
|
|
|
*/
|
2016-07-15 02:14:06 +00:00
|
|
|
const Node* build(SkStream&);
|
2008-12-17 15:59:43 +00:00
|
|
|
const Node* copy(const SkDOM& dom, const Node* node);
|
|
|
|
|
|
|
|
const Node* getRootNode() const;
|
|
|
|
|
2015-02-20 21:54:40 +00:00
|
|
|
SkXMLParser* beginParsing();
|
|
|
|
const Node* finishParsing();
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
enum Type {
|
|
|
|
kElement_Type,
|
|
|
|
kText_Type
|
|
|
|
};
|
2017-01-07 21:16:02 +00:00
|
|
|
Type getType(const Node*) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
const char* getName(const Node*) const;
|
|
|
|
const Node* getFirstChild(const Node*, const char elem[] = NULL) const;
|
|
|
|
const Node* getNextSibling(const Node*, const char elem[] = NULL) const;
|
|
|
|
|
|
|
|
const char* findAttr(const Node*, const char attrName[]) const;
|
|
|
|
const Attr* getFirstAttr(const Node*) const;
|
|
|
|
const Attr* getNextAttr(const Node*, const Attr*) const;
|
|
|
|
const char* getAttrName(const Node*, const Attr*) const;
|
|
|
|
const char* getAttrValue(const Node*, const Attr*) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// helpers for walking children
|
|
|
|
int countChildren(const Node* node, const char elem[] = NULL) const;
|
|
|
|
|
|
|
|
// helpers for calling SkParse
|
|
|
|
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;
|
|
|
|
|
2017-01-07 21:16:02 +00:00
|
|
|
bool findScalar(const Node* node, const char name[], SkScalar value[]) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->findScalars(node, name, value, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
class AttrIter {
|
|
|
|
public:
|
2016-07-27 01:46:34 +00:00
|
|
|
AttrIter(const SkDOM&, const Node*);
|
2008-12-17 15:59:43 +00:00
|
|
|
const char* next(const char** value);
|
|
|
|
private:
|
|
|
|
const Attr* fAttr;
|
|
|
|
const Attr* fStop;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2016-10-27 16:30:08 +00:00
|
|
|
SkChunkAlloc fAlloc;
|
|
|
|
Node* fRoot;
|
|
|
|
std::unique_ptr<SkDOMParser> fParser;
|
2015-02-20 21:54:40 +00:00
|
|
|
|
2016-07-15 02:14:06 +00:00
|
|
|
typedef SkNoncopyable INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|