Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/framework/source/fwe/helper/propertysetcontainer.cxx
Line
Count
Source (jump to first uncovered line)
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 <helper/propertysetcontainer.hxx>
21
22
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23
#include <cppuhelper/queryinterface.hxx>
24
#include <vcl/svapp.hxx>
25
26
constexpr OUString WRONG_TYPE_EXCEPTION = u"Only XPropertSet allowed!"_ustr;
27
28
using namespace cppu;
29
using namespace com::sun::star::uno;
30
using namespace com::sun::star::container;
31
using namespace com::sun::star::lang;
32
using namespace com::sun::star::beans;
33
34
namespace framework
35
{
36
37
PropertySetContainer::PropertySetContainer()
38
0
{
39
0
}
Unexecuted instantiation: framework::PropertySetContainer::PropertySetContainer()
Unexecuted instantiation: framework::PropertySetContainer::PropertySetContainer()
40
41
PropertySetContainer::~PropertySetContainer()
42
0
{
43
0
}
44
45
// XIndexContainer
46
void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const css::uno::Any& Element )
47
0
{
48
0
    std::unique_lock g(m_aMutex);
49
50
0
    sal_Int32 nSize = m_aPropertySetVector.size();
51
52
0
    if ( nSize < Index )
53
0
        throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
54
55
0
    Reference< XPropertySet > aPropertySetElement;
56
57
0
    if ( !(Element >>= aPropertySetElement) )
58
0
    {
59
0
        throw IllegalArgumentException(
60
0
            WRONG_TYPE_EXCEPTION,
61
0
            static_cast<OWeakObject *>(this), 2 );
62
0
    }
63
64
0
    if ( nSize == Index )
65
0
        m_aPropertySetVector.push_back( aPropertySetElement );
66
0
    else
67
0
    {
68
0
        PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
69
0
        aIter += Index;
70
0
        m_aPropertySetVector.insert( aIter, aPropertySetElement );
71
0
    }
72
0
}
73
74
void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 nIndex )
75
0
{
76
0
    std::unique_lock g(m_aMutex);
77
78
0
    if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= nIndex )
79
0
        throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
80
81
0
    m_aPropertySetVector.erase(m_aPropertySetVector.begin() +  nIndex);
82
0
}
83
84
// XIndexReplace
85
void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const css::uno::Any& Element )
86
0
{
87
0
    std::unique_lock g(m_aMutex);
88
89
0
    if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= Index )
90
0
        throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
91
92
0
    Reference< XPropertySet > aPropertySetElement;
93
94
0
    if ( !(Element >>= aPropertySetElement) )
95
0
    {
96
0
        throw IllegalArgumentException(
97
0
            WRONG_TYPE_EXCEPTION,
98
0
            static_cast<OWeakObject *>(this), 2 );
99
0
    }
100
101
0
    m_aPropertySetVector[ Index ] = std::move(aPropertySetElement);
102
0
}
103
104
// XIndexAccess
105
sal_Int32 SAL_CALL PropertySetContainer::getCount()
106
0
{
107
0
    std::unique_lock g(m_aMutex);
108
109
0
    return m_aPropertySetVector.size();
110
0
}
111
112
Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
113
0
{
114
0
    std::unique_lock g(m_aMutex);
115
116
0
    if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= Index )
117
0
        throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
118
119
0
    return Any(m_aPropertySetVector[ Index ]);
120
0
}
121
122
// XElementAccess
123
sal_Bool SAL_CALL PropertySetContainer::hasElements()
124
0
{
125
0
    std::unique_lock g(m_aMutex);
126
127
0
    return !( m_aPropertySetVector.empty() );
128
0
}
129
130
}
131
132
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */