Gnash  0.8.11dev
XMLNode_as.h
Go to the documentation of this file.
1 // XMLNode_as.h: ActionScript 3 "XMLNode" class, for Gnash.
2 //
3 // Copyright (C) 2009, 2010, 2011. 2012 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef GNASH_ASOBJ3_XMLNODE_H
21 #define GNASH_ASOBJ3_XMLNODE_H
22 
23 #include <list>
24 #include <string>
25 #include <cassert>
26 
27 #include "Relay.h"
28 
29 namespace gnash {
30  class as_object;
31  class Global_as;
32  struct ObjectURI;
33 }
34 
35 namespace gnash {
36 
37 
39 //
42 //
53 class XMLNode_as : public Relay
54 {
55 public:
56 
57  enum NodeType {
58  Element = 1,
59  Attribute = 2,
60  Text = 3,
61  Cdata = 4,
62  EntityRef = 5,
63  Entity = 6,
64  ProcInstr = 7,
65  Comment = 8,
66  Document = 9,
67  DocType = 10,
69  Notation = 12
70  };
71 
72  XMLNode_as(Global_as& gl);
73 
74  virtual ~XMLNode_as();
75 
76  size_t length() const { return _children.size(); }
77 
78  const std::string& nodeName() const { return _name; }
79 
80  const std::string& nodeValue() const { return _value; }
81 
83  NodeType nodeType() const { return _type; }
84 
87  _type = type;
88  }
89 
91  void nodeNameSet(const std::string& name) { _name = name; }
92 
93  bool extractPrefix(std::string& prefix) const;
94 
96  void nodeValueSet(const std::string& value) { _value = value; }
97 
99  void getNamespaceForPrefix(const std::string& prefix, std::string& ns)
100  const;
101 
103  //
105  bool getPrefixForNamespace(const std::string& ns, std::string& prefix)
106  const;
107 
108  void setNamespaceURI(const std::string& value) {
109  _namespaceURI = value;
110  }
111 
112  const std::string& getNamespaceURI() const {
113  return _namespaceURI;
114  }
115 
118  bool hasChildNodes() const;
119 
120  XMLNode_as* firstChild() const;
121  XMLNode_as* lastChild() const;
122 
123  // Use a list for quick erasing
124  typedef std::list<XMLNode_as*> Children;
125 
127 
128  XMLNode_as* previousSibling() const;
129  XMLNode_as* nextSibling() const;
130 
132  //
137  XMLNode_as* cloneNode(bool deep) const;
138 
140  //
143  //
145  //
147  void appendChild(XMLNode_as* node);
148 
150  //
153  //
155  //
157  void removeChild(XMLNode_as* node);
158 
161  return _parent;
162  }
163 
165  //
179  void insertBefore(XMLNode_as* newnode, XMLNode_as* pos);
180 
182  //
187  virtual void toString(std::ostream& str, bool encode = false) const;
188 
190  as_object* getAttributes() const { return _attributes; }
191 
193  //
198  void setAttribute(const std::string& name, const std::string& value);
199 
201  //
206  assert(!_object);
207  assert(o);
208  _object = o;
209  }
210 
212  //
214  as_object* object();
215 
216 protected:
217 
219  //
221  virtual void setReachable();
222 
224 
226  //
229  void clearChildren();
230 
231 private:
232 
234  //
236  void setParent(XMLNode_as* node) { _parent = node; }
237 
239  //
243  void updateChildNodes();
244 
246  XMLNode_as(const XMLNode_as &node, bool deep);
247 
248  Children _children;
249 
250  as_object* _object;
251 
252  XMLNode_as* _parent;
253 
254  as_object* _attributes;
255 
256  as_object* _childNodes;
257 
258  std::string _name;
259 
260  std::string _value;
261 
262  NodeType _type;
263 
264  std::string _namespaceURI;
265 
266  static void stringify(const XMLNode_as& xml, std::ostream& xmlout,
267  bool encode);
268 
270  //
273  bool _gcMarkInProgress;
274 
276  //
280  class GCMarkGuard {
281  XMLNode_as* _x;
282  public:
283  GCMarkGuard(XMLNode_as* x): _x(x) { _x->_gcMarkInProgress = true; }
284  ~GCMarkGuard() { _x->_gcMarkInProgress = false; }
285  };
286  friend class GCMarkGuard;
287 
288 };
289 
290 // Initialize the global XMLNode class
291 void xmlnode_class_init(as_object& where, const ObjectURI& uri);
292 
294 void registerXMLNodeNative(as_object& where);
295 
296 } // gnash namespace
297 
298 // GNASH_ASOBJ3_XMLNODE_H
299 #endif
300 
301 // local Variables:
302 // mode: C++
303 // indent-tabs-mode: t
304 // End:
305 
306 
XMLNode_as * getParent() const
Get the parent XMLNode_as of this node. Can be 0.
Definition: XMLNode_as.h:160
void setAttribute(const std::string &name, const std::string &value)
Set a named attribute to a value.
Definition: XMLNode_as.cpp:301
friend class GCMarkGuard
Definition: XMLNode_as.h:286
XMLNode_as * cloneNode(bool deep) const
Copy a node.
Definition: XMLNode_as.cpp:199
Definition: XMLNode_as.h:62
as_object * object()
Return the object associated with this XMLNode_as.
Definition: XMLNode_as.cpp:130
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
XMLNode_as * nextSibling() const
Definition: XMLNode_as.cpp:276
const std::string & nodeValue() const
Definition: XMLNode_as.h:80
type
Definition: GnashKey.h:329
The base class for all ActionScript objects.
Definition: as_object.h:161
XMLNode_as(Global_as &gl)
Definition: XMLNode_as.cpp:79
bool hasChildNodes() const
Definition: XMLNode_as.cpp:186
Definition: GnashKey.h:161
virtual void toString(std::ostream &str, bool encode=false) const
Convert the XMLNode to a string.
Definition: XMLNode_as.cpp:295
void nodeTypeSet(NodeType type)
Set the type of an XML Node.
Definition: XMLNode_as.h:86
A URI for describing as_objects.
Definition: ObjectURI.h:44
size_t length() const
Definition: XMLNode_as.h:76
Definition: XMLNode_as.h:61
XMLNode_as * lastChild() const
Definition: XMLNode_as.cpp:206
Definition: XMLNode_as.h:66
void setNamespaceURI(const std::string &value)
Definition: XMLNode_as.h:108
Definition: XMLNode_as.h:58
void clearChildren()
Clear all children, making sure unreferenced children are deleted.
Definition: XMLNode_as.cpp:392
Definition: XMLNode_as.h:67
void appendChild(XMLNode_as *node)
Append a child node to this XML object.
Definition: XMLNode_as.cpp:223
as_object * childNodes()
Definition: XMLNode_as.cpp:176
const size_t _x
Definition: BitmapData_as.cpp:465
void nodeValueSet(const std::string &value)
Set value of this node.
Definition: XMLNode_as.h:96
virtual ~XMLNode_as()
Definition: XMLNode_as.cpp:113
boost::int32_t x
Definition: BitmapData_as.cpp:434
const std::string & nodeName() const
Definition: XMLNode_as.h:78
void nodeNameSet(const std::string &name)
Set name of this node.
Definition: XMLNode_as.h:91
void xmlnode_class_init(as_object &where, const ObjectURI &uri)
Definition: XMLNode_as.cpp:518
Definition: XMLNode_as.h:65
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:55
NodeType nodeType() const
Get the type of an XML Node.
Definition: XMLNode_as.h:83
void getNamespaceForPrefix(const std::string &prefix, std::string &ns) const
Performs a recursive search of node attributes to find a match.
Definition: XMLNode_as.cpp:348
void registerXMLNodeNative(as_object &where)
Register ASnative methods.
Definition: XMLNode_as.cpp:504
const std::string & getNamespaceURI() const
Definition: XMLNode_as.h:112
This is the base class for type-specific object data.
Definition: Relay.h:49
Global_as & _global
Definition: XMLNode_as.h:223
virtual void setReachable()
Mark reachable elements.
Definition: XMLNode_as.cpp:480
Definition: XMLNode_as.h:63
void insertBefore(XMLNode_as *newnode, XMLNode_as *pos)
Insert a node before a node.
Definition: XMLNode_as.cpp:232
XMLNode_as * firstChild() const
Definition: XMLNode_as.cpp:192
Definition: XMLNode_as.h:60
NodeType
Definition: XMLNode_as.h:57
void removeChild(XMLNode_as *node)
Remove a child node from this XML object.
Definition: XMLNode_as.cpp:215
Definition: XMLNode_as.h:64
Definition: XMLNode_as.h:69
A node in an XML tree.
Definition: XMLNode_as.h:53
bool extractPrefix(std::string &prefix) const
Definition: XMLNode_as.cpp:377
as_object * getAttributes() const
Return the attributes object associated with this node.
Definition: XMLNode_as.h:190
XMLNode_as * previousSibling() const
Definition: XMLNode_as.cpp:258
Definition: XMLNode_as.h:68
bool getPrefixForNamespace(const std::string &ns, std::string &prefix) const
Performs a recursive search of node attributes to find a match.
Definition: XMLNode_as.cpp:310
std::string name
Definition: LocalConnection_as.cpp:151
std::list< XMLNode_as * > Children
Definition: XMLNode_as.h:124
void setObject(as_object *o)
Associate an as_object with this XMLNode_as.
Definition: XMLNode_as.h:205
Definition: XMLNode_as.h:59