MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / insertBefore

Method insertBefore

base/poco/XML/src/AbstractContainerNode.cpp:79–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79Node* AbstractContainerNode::insertBefore(Node* newChild, Node* refChild)
80{
81 poco_check_ptr (newChild);
82
83 if (static_cast<AbstractNode*>(newChild)->_pOwner != _pOwner && static_cast<AbstractNode*>(newChild)->_pOwner != this)
84 throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
85 if (refChild && static_cast<AbstractNode*>(refChild)->_pParent != this)
86 throw DOMException(DOMException::NOT_FOUND_ERR);
87 if (newChild == refChild)
88 return newChild;
89 if (this == newChild)
90 throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
91
92 AbstractNode* pFirst = 0;
93 AbstractNode* pLast = 0;
94 if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)
95 {
96 AbstractContainerNode* pFrag = static_cast<AbstractContainerNode*>(newChild);
97 pFirst = pFrag->_pFirstChild;
98 pLast = pFirst;
99 if (pFirst)
100 {
101 while (pLast->_pNext)
102 {
103 pLast->_pParent = this;
104 pLast = pLast->_pNext;
105 }
106 pLast->_pParent = this;
107 }
108 pFrag->_pFirstChild = 0;
109 }
110 else
111 {
112 newChild->duplicate();
113 AbstractContainerNode* pParent = static_cast<AbstractNode*>(newChild)->_pParent;
114 if (pParent) pParent->removeChild(newChild);
115 pFirst = static_cast<AbstractNode*>(newChild);
116 pLast = pFirst;
117 pFirst->_pParent = this;
118 }
119 if (_pFirstChild && pFirst)
120 {
121 AbstractNode* pCur = _pFirstChild;
122 if (pCur == refChild)
123 {
124 pLast->_pNext = _pFirstChild;
125 _pFirstChild = pFirst;
126 }
127 else
128 {
129 while (pCur && pCur->_pNext != refChild) pCur = pCur->_pNext;
130 if (pCur)
131 {
132 pLast->_pNext = pCur->_pNext;
133 pCur->_pNext = pFirst;
134 }
135 else throw DOMException(DOMException::NOT_FOUND_ERR);
136 }

Callers

nothing calls this directly

Calls 5

dispatchNodeInsertedMethod · 0.80
nodeTypeMethod · 0.45
duplicateMethod · 0.45
removeChildMethod · 0.45

Tested by

no test coverage detected