Code

* Lots of documentation for the Inkscape::XML namespace
[inkscape.git] / src / xml / simple-node.cpp
index 7bbec74ee9a620ac39e9b1fd7544662c7f3f7759..3cca393d228366d7b013d9109d7c207ebaddd85f 100644 (file)
@@ -1,7 +1,7 @@
-/*
- * SimpleNode - simple XML node implementation
- *
- * Copyright 2003-2005 MenTaLguY <mental@rydia.net>
+/** @file
+ * @brief Garbage collected XML node implementation
+ */
+/* Copyright 2003-2005 MenTaLguY <mental@rydia.net>
  * Copyright 2003 Nathan Hurst
  * Copyright 1999-2003 Lauris Kaplinski
  * Copyright 2000-2002 Ximian Inc.
@@ -12,7 +12,6 @@
  * of the License, or (at your option) any later version.
  *
  * See the file COPYING for details.
- *
  */
 
 #include <cstring>
@@ -186,14 +185,14 @@ SimpleNode::SimpleNode(SimpleNode const &node, Document *document)
     _parent = _next = NULL;
     _first_child = _last_child = NULL;
 
-    for ( Node *child = node._first_child ;
-          child != NULL ; child = child->next() )
+    for ( SimpleNode *child = node._first_child ;
+          child != NULL ; child = child->_next )
     {
-        Node *child_copy=child->duplicate(document);
+        SimpleNode *child_copy=dynamic_cast<SimpleNode *>(child->duplicate(document));
 
         child_copy->_setParent(this);
         if (_last_child) {
-            _last_child->_setNext(child_copy);
+            _last_child->_next = child_copy;
         } else {
             _first_child = child_copy;
         }
@@ -240,23 +239,23 @@ unsigned SimpleNode::position() const {
     return _parent->_childPosition(*this);
 }
 
-unsigned SimpleNode::_childPosition(Node const &child) const {
+unsigned SimpleNode::_childPosition(SimpleNode const &child) const {
     if (!_cached_positions_valid) {
         unsigned position=0;
-        for ( Node *sibling = _first_child ;
-              sibling ; sibling = sibling->next() )
+        for ( SimpleNode *sibling = _first_child ;
+              sibling ; sibling = sibling->_next )
         {
-            sibling->_setCachedPosition(position);
+            sibling->_cached_position = position;
             position++;
         }
         _cached_positions_valid = true;
     }
-    return child._cachedPosition();
+    return child._cached_position;
 }
 
 Node *SimpleNode::nthChild(unsigned index) {
-    Node *child = _first_child;
-    for ( ; index > 0 && child ; child = child->next() ) {
+    SimpleNode *child = _first_child;
+    for ( ; index > 0 && child ; child = child->_next ) {
         index--;
     }
     return child;
@@ -277,10 +276,9 @@ bool SimpleNode::matchAttributeName(gchar const *partial_name) const {
     return false;
 }
 
-void SimpleNode::_setParent(Node *generic_parent) {
-    SimpleNode *parent = dynamic_cast<SimpleNode *>(generic_parent);
+void SimpleNode::_setParent(SimpleNode *parent) {
     if (_parent) {
-        _subtree_observers.remove(dynamic_cast<SimpleNode *>(_parent)->_subtree_observers);
+        _subtree_observers.remove(_parent->_subtree_observers);
     }
     _parent = parent;
     if (parent) {
@@ -371,7 +369,7 @@ void SimpleNode::addChild(Node *generic_child, Node *generic_ref) {
 
     Debug::EventTracker<DebugAddChild> tracker(*this, *child, ref);
 
-    Node *next;
+    SimpleNode *next;
     if (ref) {
         next = ref->_next;
         ref->_next = child;
@@ -413,7 +411,7 @@ void SimpleNode::removeChild(Node *generic_child) {
 
     Debug::EventTracker<DebugRemoveChild> tracker(*this, *child);
 
-    Node *next = child->_next;
+    SimpleNode *next = child->_next;
     if (ref) {
         ref->_next = next;
     } else {
@@ -452,7 +450,7 @@ void SimpleNode::changeOrder(Node *generic_child, Node *generic_ref) {
 
     if (prev == ref) { return; }
 
-    Node *next;
+    SimpleNode *next;
 
     /* Remove from old position. */
     next = child->_next;
@@ -490,9 +488,9 @@ void SimpleNode::setPosition(int pos) {
     // a position beyond the end of the list means the end of the list;
     // a negative position is the same as an infinitely large position
 
-    Node *ref=NULL;
-    for ( Node *sibling = _parent->firstChild() ;
-          sibling && pos ; sibling = sibling->next() )
+    SimpleNode *ref=NULL;
+    for ( SimpleNode *sibling = _parent->_first_child ;
+          sibling && pos ; sibling = sibling->_next )
     {
         if ( sibling != this ) {
             ref = sibling;
@@ -544,9 +542,9 @@ void SimpleNode::synthesizeEvents(NodeEventVector const *vector, void *data) {
         }
     }
     if (vector->child_added) {
-        Node *ref = NULL;
-        for ( Node *child = this->_first_child ;
-              child ; child = child->next() )
+        SimpleNode *ref = NULL;
+        for ( SimpleNode *child = this->_first_child ;
+              child ; child = child->_next )
         {
             vector->child_added(this, child, ref, data);
             ref = child;
@@ -629,4 +627,4 @@ void SimpleNode::mergeFrom(Node const *src, gchar const *key) {
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :