1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/xml/SkDOM.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkDOM_DEFINED 1.14 +#define SkDOM_DEFINED 1.15 + 1.16 +#include "SkChunkAlloc.h" 1.17 +#include "SkScalar.h" 1.18 +#include "SkTemplates.h" 1.19 + 1.20 +struct SkDOMNode; 1.21 +struct SkDOMAttr; 1.22 + 1.23 +class SkDOM { 1.24 +public: 1.25 + SkDOM(); 1.26 + ~SkDOM(); 1.27 + 1.28 + typedef SkDOMNode Node; 1.29 + typedef SkDOMAttr Attr; 1.30 + 1.31 + /** Returns null on failure 1.32 + */ 1.33 + const Node* build(const char doc[], size_t len); 1.34 + const Node* copy(const SkDOM& dom, const Node* node); 1.35 + 1.36 + const Node* getRootNode() const; 1.37 + 1.38 + enum Type { 1.39 + kElement_Type, 1.40 + kText_Type 1.41 + }; 1.42 + Type getType(const Node*) const; 1.43 + 1.44 + const char* getName(const Node*) const; 1.45 + const Node* getFirstChild(const Node*, const char elem[] = NULL) const; 1.46 + const Node* getNextSibling(const Node*, const char elem[] = NULL) const; 1.47 + 1.48 + const char* findAttr(const Node*, const char attrName[]) const; 1.49 + const Attr* getFirstAttr(const Node*) const; 1.50 + const Attr* getNextAttr(const Node*, const Attr*) const; 1.51 + const char* getAttrName(const Node*, const Attr*) const; 1.52 + const char* getAttrValue(const Node*, const Attr*) const; 1.53 + 1.54 + // helpers for walking children 1.55 + int countChildren(const Node* node, const char elem[] = NULL) const; 1.56 + 1.57 + // helpers for calling SkParse 1.58 + bool findS32(const Node*, const char name[], int32_t* value) const; 1.59 + bool findScalars(const Node*, const char name[], SkScalar value[], int count) const; 1.60 + bool findHex(const Node*, const char name[], uint32_t* value) const; 1.61 + bool findBool(const Node*, const char name[], bool*) const; 1.62 + int findList(const Node*, const char name[], const char list[]) const; 1.63 + 1.64 + bool findScalar(const Node* node, const char name[], SkScalar value[]) const 1.65 + { 1.66 + return this->findScalars(node, name, value, 1); 1.67 + } 1.68 + 1.69 + bool hasAttr(const Node*, const char name[], const char value[]) const; 1.70 + bool hasS32(const Node*, const char name[], int32_t value) const; 1.71 + bool hasScalar(const Node*, const char name[], SkScalar value) const; 1.72 + bool hasHex(const Node*, const char name[], uint32_t value) const; 1.73 + bool hasBool(const Node*, const char name[], bool value) const; 1.74 + 1.75 + class AttrIter { 1.76 + public: 1.77 + AttrIter(const class SkDOM&, const Node*); 1.78 + const char* next(const char** value); 1.79 + private: 1.80 + const Attr* fAttr; 1.81 + const Attr* fStop; 1.82 + }; 1.83 + 1.84 + SkDEBUGCODE(void dump(const Node* node = NULL, int tabLevel = 0) const;) 1.85 + SkDEBUGCODE(static void UnitTest();) 1.86 + 1.87 +private: 1.88 + SkChunkAlloc fAlloc; 1.89 + Node* fRoot; 1.90 + friend class AttrIter; 1.91 + friend class SkDOMParser; 1.92 +}; 1.93 + 1.94 +#endif