SkDOM.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkDOM_DEFINED
  8. #define SkDOM_DEFINED
  9. #include "include/core/SkScalar.h"
  10. #include "include/core/SkTypes.h"
  11. #include "include/private/SkNoncopyable.h"
  12. #include "include/private/SkTemplates.h"
  13. #include "src/core/SkArenaAlloc.h"
  14. struct SkDOMNode;
  15. struct SkDOMAttr;
  16. class SkDOMParser;
  17. class SkStream;
  18. class SkXMLParser;
  19. class SkDOM : public SkNoncopyable {
  20. public:
  21. SkDOM();
  22. ~SkDOM();
  23. typedef SkDOMNode Node;
  24. typedef SkDOMAttr Attr;
  25. /** Returns null on failure
  26. */
  27. const Node* build(SkStream&);
  28. const Node* copy(const SkDOM& dom, const Node* node);
  29. const Node* getRootNode() const;
  30. SkXMLParser* beginParsing();
  31. const Node* finishParsing();
  32. enum Type {
  33. kElement_Type,
  34. kText_Type
  35. };
  36. Type getType(const Node*) const;
  37. const char* getName(const Node*) const;
  38. const Node* getFirstChild(const Node*, const char elem[] = nullptr) const;
  39. const Node* getNextSibling(const Node*, const char elem[] = nullptr) const;
  40. const char* findAttr(const Node*, const char attrName[]) const;
  41. const Attr* getFirstAttr(const Node*) const;
  42. const Attr* getNextAttr(const Node*, const Attr*) const;
  43. const char* getAttrName(const Node*, const Attr*) const;
  44. const char* getAttrValue(const Node*, const Attr*) const;
  45. // helpers for walking children
  46. int countChildren(const Node* node, const char elem[] = nullptr) const;
  47. // helpers for calling SkParse
  48. bool findS32(const Node*, const char name[], int32_t* value) const;
  49. bool findScalars(const Node*, const char name[], SkScalar value[], int count) const;
  50. bool findHex(const Node*, const char name[], uint32_t* value) const;
  51. bool findBool(const Node*, const char name[], bool*) const;
  52. int findList(const Node*, const char name[], const char list[]) const;
  53. bool findScalar(const Node* node, const char name[], SkScalar value[]) const {
  54. return this->findScalars(node, name, value, 1);
  55. }
  56. bool hasAttr(const Node*, const char name[], const char value[]) const;
  57. bool hasS32(const Node*, const char name[], int32_t value) const;
  58. bool hasScalar(const Node*, const char name[], SkScalar value) const;
  59. bool hasHex(const Node*, const char name[], uint32_t value) const;
  60. bool hasBool(const Node*, const char name[], bool value) const;
  61. class AttrIter {
  62. public:
  63. AttrIter(const SkDOM&, const Node*);
  64. const char* next(const char** value);
  65. private:
  66. const Attr* fAttr;
  67. const Attr* fStop;
  68. };
  69. private:
  70. SkArenaAlloc fAlloc;
  71. Node* fRoot;
  72. std::unique_ptr<SkDOMParser> fParser;
  73. typedef SkNoncopyable INHERITED;
  74. };
  75. #endif