/src/poco/XML/src/ChildNodesList.cpp
Line | Count | Source |
1 | | // |
2 | | // ChildNodesList.cpp |
3 | | // |
4 | | // Library: XML |
5 | | // Package: DOM |
6 | | // Module: DOM |
7 | | // |
8 | | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | | // and Contributors. |
10 | | // |
11 | | // SPDX-License-Identifier: BSL-1.0 |
12 | | // |
13 | | |
14 | | |
15 | | #include "Poco/DOM/ChildNodesList.h" |
16 | | #include "Poco/DOM/Node.h" |
17 | | #include "Poco/DOM/Document.h" |
18 | | |
19 | | |
20 | | namespace Poco::XML { |
21 | | |
22 | | |
23 | | ChildNodesList::ChildNodesList(const Node* pParent): |
24 | 0 | _pParent(pParent) |
25 | 0 | { |
26 | 0 | poco_check_ptr (pParent); |
27 | |
|
28 | 0 | _pParent->duplicate(); |
29 | 0 | } |
30 | | |
31 | | |
32 | | ChildNodesList::~ChildNodesList() |
33 | 0 | { |
34 | 0 | _pParent->release(); |
35 | 0 | } |
36 | | |
37 | | |
38 | | Node* ChildNodesList::item(unsigned long index) const |
39 | 0 | { |
40 | 0 | unsigned long n = 0; |
41 | 0 | Node* pCur = _pParent->firstChild(); |
42 | 0 | while (pCur && n++ < index) |
43 | 0 | { |
44 | 0 | pCur = pCur->nextSibling(); |
45 | 0 | } |
46 | 0 | return pCur; |
47 | 0 | } |
48 | | |
49 | | |
50 | | unsigned long ChildNodesList::length() const |
51 | 0 | { |
52 | 0 | unsigned long n = 0; |
53 | 0 | Node* pCur = _pParent->firstChild(); |
54 | 0 | while (pCur) |
55 | 0 | { |
56 | 0 | ++n; |
57 | 0 | pCur = pCur->nextSibling(); |
58 | 0 | } |
59 | 0 | return n; |
60 | 0 | } |
61 | | |
62 | | |
63 | | void ChildNodesList::autoRelease() |
64 | 0 | { |
65 | 0 | auto* pOwner = _pParent->ownerDocument(); |
66 | 0 | if (pOwner != nullptr) |
67 | 0 | pOwner->autoReleasePool().add(this); |
68 | 0 | } |
69 | | |
70 | | |
71 | | } // namespace Poco::XML |