XMLTreeNode.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libe-book project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef XMLTREENODE_H_INCLUDED
11 #define XMLTREENODE_H_INCLUDED
12 
13 #include <deque>
14 #include <string>
15 #include <utility>
16 
17 #include <boost/intrusive_ptr.hpp>
18 
19 #include "libebook_libcss.h"
20 
21 namespace libebook
22 {
23 
24 struct XMLTreeNode;
25 typedef boost::intrusive_ptr<XMLTreeNode> XMLTreeNodePtr_t;
26 
28 {
29  enum NodeType
30  {
33  NODE_TYPE_TEXT = 1 << 3,
36  };
37 
38  struct QName
39  {
42 
43  QName();
44  explicit QName(const LWCStringPtr_t &name, const LWCStringPtr_t &ns = LWCStringPtr_t());
45  };
46 
47  typedef std::pair<QName, QName> LinkId_t;
48 
50  {
51  bool caseless;
52 
53  std::deque<QName> classes; //< A list of attributes representing a "class".
54  std::deque<QName> ids; //< a list of attributes representing an "ID".
55  std::deque<QName> langs; //< a list of attributes representing a "lang".
56 
62  std::deque<LinkId_t> links;
63 
64  explicit Configuration(bool caseless_ = false);
65  };
66 
67  typedef std::shared_ptr<Configuration> ConfigurationPtr_t;
68 
69  struct ElementData
70  {
72  mutable int id;
73  mutable bool idSet;
74 
75  ElementData();
76  explicit ElementData(const LWCStringPtr_t &name, const LWCStringPtr_t &ns = LWCStringPtr_t());
77  };
78 
80  {
83  mutable int id;
84  mutable bool idSet;
85 
86  AttributeData();
87  AttributeData(const LWCStringPtr_t &name, const LWCStringPtr_t &ns, const LWCStringPtr_t &val);
88  AttributeData(const LWCStringPtr_t &name, const LWCStringPtr_t &val);
89  };
90 
91 public:
92  explicit XMLTreeNode(NodeType nodeType, const ConfigurationPtr_t &config = ConfigurationPtr_t());
93  ~XMLTreeNode();
94 
97 
99  std::deque<AttributeData> attributes;
100  std::string text;
101 
103  // siblings
106  // children
109 
110  size_t elements;
111 
112  mutable int refcount;
113 
114  XMLTreeNodePtr_t clone(bool deep = false) const;
115 
118  void removeChild(const XMLTreeNodePtr_t &child);
119  void transferChildren(const XMLTreeNodePtr_t &newParent);
120 
121  void addAttributes(const std::deque<AttributeData> &attrs);
122 
123  bool hasChildren(bool ignoreText = false) const;
124 
125 private:
126  // disable copying
127  XMLTreeNode(const XMLTreeNode &);
129 };
130 
134 
137 
140 
143 
144 }
145 
146 #endif // XMLTREENODE_H_INCLUDED
147 
148 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
boost::intrusive_ptr< XMLTreeNode > XMLTreeNodePtr_t
Definition: XMLTreeNode.h:24
Definition: EBOOKHTMLToken.h:309
std::deque< LinkId_t > links
A list of element / attribute pairs representing a "link".
Definition: XMLTreeNode.h:62
LWCStringPtr_t name
Definition: XMLTreeNode.h:40
XMLTreeNodePtr_t appendChild(const XMLTreeNodePtr_t &child)
Definition: XMLTreeNode.cpp:404
LWCStringPtr_t ns
Definition: XMLTreeNode.h:41
int id
Definition: XMLTreeNode.h:72
NodeType type
Definition: XMLTreeNode.h:95
Definition: XMLTreeNode.h:32
void transferChildren(const XMLTreeNodePtr_t &newParent)
Definition: XMLTreeNode.cpp:422
size_t elements
Definition: XMLTreeNode.h:110
bool hasChildren(bool ignoreText=false) const
Definition: XMLTreeNode.cpp:434
XMLTreeNode & operator=(const XMLTreeNode &)
Definition: EBOOKHTMLToken.h:290
bool operator==(const XMLTreeNode::QName &lhs, const XMLTreeNode::QName &rhs)
Definition: XMLTreeNode.cpp:440
Definition: XMLTreeNode.h:34
XMLTreeNodePtr_t last
Definition: XMLTreeNode.h:108
std::shared_ptr< Configuration > ConfigurationPtr_t
Definition: XMLTreeNode.h:67
Definition: XMLTreeNode.h:79
int id
Definition: XMLTreeNode.h:83
std::pair< QName, QName > LinkId_t
Definition: XMLTreeNode.h:47
XMLTreeNodePtr_t next
Definition: XMLTreeNode.h:105
Definition: XMLTreeNode.h:69
bool operator!=(const XMLTreeNode::QName &lhs, const XMLTreeNode::QName &rhs)
Definition: XMLTreeNode.cpp:445
Definition: XMLTreeNode.h:35
void intrusive_ptr_release(XMLTreeNode *const p)
Definition: XMLTreeNode.cpp:488
Definition: XMLTreeNode.h:33
LWCStringPtr_t value
Definition: XMLTreeNode.h:82
Configuration(bool caseless_=false)
Definition: XMLTreeNode.cpp:329
Definition: XMLTreeNode.h:27
XMLTreeNode(NodeType nodeType, const ConfigurationPtr_t &config=ConfigurationPtr_t())
Definition: XMLTreeNode.cpp:376
XMLTreeNode::ConfigurationPtr_t config
Definition: EBOOKHTMLParser.cpp:177
ConfigurationPtr_t configuration
Definition: XMLTreeNode.h:96
~XMLTreeNode()
Definition: XMLTreeNode.cpp:392
ElementData()
Definition: XMLTreeNode.cpp:338
AttributeData()
Definition: XMLTreeNode.cpp:352
std::deque< QName > classes
Definition: XMLTreeNode.h:53
const char * name
Definition: EBOOKHTMLToken.cpp:44
XMLTreeNodePtr_t insertChildBefore(const XMLTreeNodePtr_t &child, const XMLTreeNodePtr_t &selected)
Definition: XMLTreeNode.cpp:410
Definition: XMLTreeNode.h:31
bool idSet
Definition: XMLTreeNode.h:73
XMLTreeNodePtr_t clone(bool deep=false) const
Definition: XMLTreeNode.cpp:398
bool caselessEqual(const XMLTreeNode::QName &lhs, const XMLTreeNode::QName &rhs)
Definition: XMLTreeNode.cpp:450
QName qname
Definition: XMLTreeNode.h:81
Definition: EBOOKHTMLToken.h:116
Definition: EBOOKHTMLToken.h:247
bool idSet
Definition: XMLTreeNode.h:84
QName qname
Definition: XMLTreeNode.h:71
QName()
Definition: XMLTreeNode.cpp:317
bool caseless
Definition: XMLTreeNode.h:51
int refcount
Definition: XMLTreeNode.h:112
std::deque< AttributeData > attributes
Definition: XMLTreeNode.h:99
Definition: XMLTreeNode.h:38
XMLTreeNodePtr_t prev
Definition: XMLTreeNode.h:104
Definition: BBeBCollector.cpp:18
Definition: XMLTreeNode.h:49
XMLTreeNodePtr_t first
Definition: XMLTreeNode.h:107
std::deque< QName > langs
Definition: XMLTreeNode.h:55
boost::intrusive_ptr< lwc_string > LWCStringPtr_t
Definition: libebook_libcss.h:27
NodeType
Definition: XMLTreeNode.h:29
std::string text
Definition: XMLTreeNode.h:100
void addAttributes(const std::deque< AttributeData > &attrs)
Definition: XMLTreeNode.cpp:428
std::deque< QName > ids
Definition: XMLTreeNode.h:54
void intrusive_ptr_add_ref(XMLTreeNode *const p)
Definition: XMLTreeNode.cpp:483
XMLTreeNodePtr_t parent
Definition: XMLTreeNode.h:102
void removeChild(const XMLTreeNodePtr_t &child)
Definition: XMLTreeNode.cpp:416

Generated for libe-book by doxygen 1.8.14