LibreOffice Module comphelper (master) 1
IndexedPropertyValuesContainer.cxx
Go to the documentation of this file.
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 <com/sun/star/lang/IllegalArgumentException.hpp>
21#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <o3tl/safeint.hxx>
25
26namespace com::sun::star::uno { class XComponentContext; }
27
28using namespace com::sun::star;
29
30
31namespace comphelper {
32
33
35{
36}
37
38// XIndexContainer
39void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, const css::uno::Any& aElement )
40{
41 sal_Int32 nSize(maProperties.size());
42 if ((nSize < nIndex) || (nIndex < 0))
43 throw lang::IndexOutOfBoundsException();
44
45 uno::Sequence<beans::PropertyValue> aProps;
46 if (!(aElement >>= aProps))
47 throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
48 if (nSize == nIndex)
49 maProperties.push_back(aProps);
50 else
51 maProperties.insert(maProperties.begin() + nIndex, aProps);
52}
53
54void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
55{
56 if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maProperties.size()))
57 throw lang::IndexOutOfBoundsException();
58
59 maProperties.erase(maProperties.begin() + nIndex);
60}
61
62// XIndexReplace
63void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex, const css::uno::Any& aElement )
64{
65 sal_Int32 nSize(maProperties.size());
66 if ((nIndex >= nSize) || (nIndex < 0))
67 throw lang::IndexOutOfBoundsException();
68
69 uno::Sequence<beans::PropertyValue> aProps;
70 if (!(aElement >>= aProps))
71 throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
72 maProperties[nIndex] = aProps;
73}
74
75// XIndexAccess
77{
78 return maProperties.size();
79}
80
81css::uno::Any SAL_CALL IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex )
82{
83 sal_Int32 nSize(maProperties.size());
84 if ((nIndex >= nSize) || (nIndex < 0))
85 throw lang::IndexOutOfBoundsException();
86
87 return uno::Any( maProperties[nIndex] );
88}
89
90// XElementAccess
92{
94}
95
97{
98 return !maProperties.empty();
99}
100
101//XServiceInfo
103{
104 return "IndexedPropertyValuesContainer";
105}
106
107sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName )
108{
110}
111
112css::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( )
113{
114 return { "com.sun.star.document.IndexedPropertyValues" };
115}
116
117} // namespace comphelper
118
119extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
121 css::uno::XComponentContext *,
122 css::uno::Sequence<css::uno::Any> const &)
123{
124 return cppu::acquire(new comphelper::IndexedPropertyValuesContainer());
125}
126
127/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * IndexedPropertyValuesContainer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL replaceByIndex(sal_Int32 nIndex, const css::uno::Any &aElement) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeByIndex(sal_Int32 nIndex) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL insertByIndex(sal_Int32 nIndex, const css::uno::Any &aElement) override
sal_Int32 nIndex
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
unsigned char sal_Bool