Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unoxml/source/xpath/nodelist.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice 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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <utility>
21
22
#include "nodelist.hxx"
23
24
#include "../dom/document.hxx"
25
26
using namespace css::uno;
27
using namespace css::xml::dom;
28
29
namespace XPath
30
{
31
    CNodeList::CNodeList(
32
                ::rtl::Reference<DOM::CDocument> pDocument,
33
                ::osl::Mutex & rMutex,
34
                std::shared_ptr<xmlXPathObject> const& rxpathObj)
35
916
        : m_pDocument(std::move(pDocument))
36
916
        , m_rMutex(rMutex)
37
916
        , m_pNodeSet(nullptr)
38
916
    {
39
916
        if (rxpathObj != nullptr && rxpathObj->type == XPATH_NODESET)
40
916
        {
41
916
            m_pNodeSet = rxpathObj->nodesetval;
42
916
            m_pXPathObj = rxpathObj;
43
916
        }
44
916
    }
45
46
    /**
47
    The number of nodes in the list.
48
    */
49
    sal_Int32 SAL_CALL CNodeList::getLength()
50
458
    {
51
458
        ::osl::MutexGuard const g(m_rMutex);
52
53
458
        sal_Int32 value = 0;
54
458
        if (m_pNodeSet != nullptr)
55
458
            value = xmlXPathNodeSetGetLength(m_pNodeSet);
56
458
        return value;
57
458
    }
58
59
    /**
60
    Returns the indexth item in the collection.
61
    */
62
    Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index)
63
0
    {
64
0
        ::osl::MutexGuard const g(m_rMutex);
65
66
0
        if (nullptr == m_pNodeSet) {
67
0
            return nullptr;
68
0
        }
69
0
        xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index);
70
0
        return m_pDocument->GetCNode(pNode);
71
0
    }
72
}
73
74
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */