HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_XMLReader.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_XMLReader.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  * The reader uses the libxml2 API documented at:
10  * http://xmlsoft.org/html/libxml-xmlreader.html
11  * http://xmlsoft.org/examples/reader1.c
12  *
13  * COMMENTS:
14  */
15 
16 #ifndef __UT_XMLReader__
17 #define __UT_XMLReader__
18 
19 #include "UT_API.h"
20 #include "UT_StringHolder.h"
21 #include "UT_UniquePtr.h"
22 #include "UT_WorkBuffer.h"
23 #include "UT_XMLNode.h"
24 
25 struct _xmlTextReader;
26 typedef struct _xmlTextReader *xmlTextReaderPtr;
27 
29 {
30 public:
31  /// Standard constructor.
32  UT_XMLReader();
33 
34  /// Standard destructor.
35  ~UT_XMLReader();
36 
37  /// Initialize the reader to read from file.
38  bool beginReadingFromFile(const char *file);
39 
40  /// Initialize the reader to read from memory buffer.
41  bool beginReadingFromMemory(
42  const UT_WorkBuffer &memory,
43  const char *URL,
44  const char *encoding = nullptr);
45 
46  /// Read the next XML element.
47  bool read();
48 
49  /// Return the currently read node.
50  /// Return NULL if no node has been read.
51  const UT_XMLNode *getNode();
52 
53  /// Return the type for the currently read XML node.
54  UT_XMLNodeType getNodeType() const;
55 
56  /// Pass back the name of the currently read XML node.
57  /// @{
58  void getNodeName(UT_WorkBuffer &name) const;
59  void getNodeName(UT_StringHolder &name) const
60  {
61  UT_WorkBuffer tmp;
62  getNodeName(tmp);
63  name = std::move(tmp);
64  }
65  /// @}
66 
67  /// Pass back the contents of the currently read XML element or text node.
68  /// @{
69  void getNodeContents(UT_WorkBuffer &contents) const;
71  UT_StringHolder &contents) const
72  {
73  UT_WorkBuffer tmp;
74  getNodeContents(tmp);
75  contents = std::move(tmp);
76  }
77  /// @}
78 
79  /// Return the depth of the current node in the XML document.
80  int getNodeDepth() const;
81 
82  /// Return true if the currently read node has attributes.
83  /// Return false otherwise.
84  bool hasNodeAttributes() const;
85 
86  /// Pass back the value of the specified attribute on the current node.
87  /// @{
88  void getNodeAttribute(const char *attr_name,
89  UT_WorkBuffer &attr_val) const;
90  void getNodeAttribute(const char *attr_name,
91  UT_StringHolder &attr_val) const
92  {
93  UT_WorkBuffer tmp;
94  getNodeAttribute(attr_name, tmp);
95  attr_val = std::move(tmp);
96  }
97  /// @}
98 
99  /// Return true if the currently read node has a value.
100  /// Return false otherwise.
101  bool hasNodeValue() const;
102 
103  /// Pass back the value of the current node.
104  /// @{
105  void getNodeValue(UT_WorkBuffer &node_val) const;
106  void getNodeValue(UT_StringHolder &node_val) const
107  {
108  UT_WorkBuffer tmp;
109  getNodeValue(tmp);
110  node_val = std::move(tmp);
111  }
112  /// @}
113 
114 private:
115  static void deleteTextReader(xmlTextReaderPtr p);
116  using TextReaderPtr = UT_UniquePtr<_xmlTextReader,
117  decltype(&deleteTextReader)>;
118 
119  /// The reader that does the actual reading:
120  TextReaderPtr myReader;
121 
122  /// Temporary storage for the current node.
124 };
125 
126 #endif
127 
GLsizei GLenum GLsizei GLsizei GLuint memory
Definition: RE_OGL.h:202
#define UT_API
Definition: UT_API.h:14
struct _xmlTextReader * xmlTextReaderPtr
Definition: UT_XMLReader.h:26
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void getNodeAttribute(const char *attr_name, UT_StringHolder &attr_val) const
Definition: UT_XMLReader.h:90
void getNodeName(UT_StringHolder &name) const
Definition: UT_XMLReader.h:59
void getNodeValue(UT_StringHolder &node_val) const
Definition: UT_XMLReader.h:106
GLuint const GLchar * name
Definition: glcorearb.h:786
xmlElementType UT_XMLNodeType
Definition: UT_XMLNode.h:35
void getNodeContents(UT_StringHolder &contents) const
Definition: UT_XMLReader.h:70