michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkDOM_DEFINED michael@0: #define SkDOM_DEFINED michael@0: michael@0: #include "SkChunkAlloc.h" michael@0: #include "SkScalar.h" michael@0: #include "SkTemplates.h" michael@0: michael@0: struct SkDOMNode; michael@0: struct SkDOMAttr; michael@0: michael@0: class SkDOM { michael@0: public: michael@0: SkDOM(); michael@0: ~SkDOM(); michael@0: michael@0: typedef SkDOMNode Node; michael@0: typedef SkDOMAttr Attr; michael@0: michael@0: /** Returns null on failure michael@0: */ michael@0: const Node* build(const char doc[], size_t len); michael@0: const Node* copy(const SkDOM& dom, const Node* node); michael@0: michael@0: const Node* getRootNode() const; michael@0: michael@0: enum Type { michael@0: kElement_Type, michael@0: kText_Type michael@0: }; michael@0: Type getType(const Node*) const; michael@0: michael@0: const char* getName(const Node*) const; michael@0: const Node* getFirstChild(const Node*, const char elem[] = NULL) const; michael@0: const Node* getNextSibling(const Node*, const char elem[] = NULL) const; michael@0: michael@0: const char* findAttr(const Node*, const char attrName[]) const; michael@0: const Attr* getFirstAttr(const Node*) const; michael@0: const Attr* getNextAttr(const Node*, const Attr*) const; michael@0: const char* getAttrName(const Node*, const Attr*) const; michael@0: const char* getAttrValue(const Node*, const Attr*) const; michael@0: michael@0: // helpers for walking children michael@0: int countChildren(const Node* node, const char elem[] = NULL) const; michael@0: michael@0: // helpers for calling SkParse michael@0: bool findS32(const Node*, const char name[], int32_t* value) const; michael@0: bool findScalars(const Node*, const char name[], SkScalar value[], int count) const; michael@0: bool findHex(const Node*, const char name[], uint32_t* value) const; michael@0: bool findBool(const Node*, const char name[], bool*) const; michael@0: int findList(const Node*, const char name[], const char list[]) const; michael@0: michael@0: bool findScalar(const Node* node, const char name[], SkScalar value[]) const michael@0: { michael@0: return this->findScalars(node, name, value, 1); michael@0: } michael@0: michael@0: bool hasAttr(const Node*, const char name[], const char value[]) const; michael@0: bool hasS32(const Node*, const char name[], int32_t value) const; michael@0: bool hasScalar(const Node*, const char name[], SkScalar value) const; michael@0: bool hasHex(const Node*, const char name[], uint32_t value) const; michael@0: bool hasBool(const Node*, const char name[], bool value) const; michael@0: michael@0: class AttrIter { michael@0: public: michael@0: AttrIter(const class SkDOM&, const Node*); michael@0: const char* next(const char** value); michael@0: private: michael@0: const Attr* fAttr; michael@0: const Attr* fStop; michael@0: }; michael@0: michael@0: SkDEBUGCODE(void dump(const Node* node = NULL, int tabLevel = 0) const;) michael@0: SkDEBUGCODE(static void UnitTest();) michael@0: michael@0: private: michael@0: SkChunkAlloc fAlloc; michael@0: Node* fRoot; michael@0: friend class AttrIter; michael@0: friend class SkDOMParser; michael@0: }; michael@0: michael@0: #endif