1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/lang/IllegalArgumentException.hpp>
21 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22 #include <comphelper/indexedpropertyvalues.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <o3tl/safeint.hxx>
26 namespace com::sun::star::uno
{ class XComponentContext
; }
28 using namespace com::sun::star
;
31 namespace comphelper
{
34 IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() noexcept
39 void SAL_CALL
IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex
, const css::uno::Any
& aElement
)
41 sal_Int32
nSize(maProperties
.size());
42 if ((nSize
< nIndex
) || (nIndex
< 0))
43 throw lang::IndexOutOfBoundsException();
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);
49 maProperties
.push_back(aProps
);
51 maProperties
.insert(maProperties
.begin() + nIndex
, aProps
);
54 void SAL_CALL
IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex
)
56 if ((nIndex
< 0) || (o3tl::make_unsigned(nIndex
) >= maProperties
.size()))
57 throw lang::IndexOutOfBoundsException();
59 maProperties
.erase(maProperties
.begin() + nIndex
);
63 void SAL_CALL
IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex
, const css::uno::Any
& aElement
)
65 sal_Int32
nSize(maProperties
.size());
66 if ((nIndex
>= nSize
) || (nIndex
< 0))
67 throw lang::IndexOutOfBoundsException();
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
;
76 sal_Int32 SAL_CALL
IndexedPropertyValuesContainer::getCount( )
78 return maProperties
.size();
81 css::uno::Any SAL_CALL
IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex
)
83 sal_Int32
nSize(maProperties
.size());
84 if ((nIndex
>= nSize
) || (nIndex
< 0))
85 throw lang::IndexOutOfBoundsException();
87 return uno::Any( maProperties
[nIndex
] );
91 css::uno::Type SAL_CALL
IndexedPropertyValuesContainer::getElementType( )
93 return cppu::UnoType
<uno::Sequence
<beans::PropertyValue
>>::get();
96 sal_Bool SAL_CALL
IndexedPropertyValuesContainer::hasElements( )
98 return !maProperties
.empty();
102 OUString SAL_CALL
IndexedPropertyValuesContainer::getImplementationName( )
104 return "IndexedPropertyValuesContainer";
107 sal_Bool SAL_CALL
IndexedPropertyValuesContainer::supportsService( const OUString
& ServiceName
)
109 return cppu::supportsService(this, ServiceName
);
112 css::uno::Sequence
< OUString
> SAL_CALL
IndexedPropertyValuesContainer::getSupportedServiceNames( )
114 return { "com.sun.star.document.IndexedPropertyValues" };
117 } // namespace comphelper
119 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
120 IndexedPropertyValuesContainer_get_implementation(
121 css::uno::XComponentContext
*,
122 css::uno::Sequence
<css::uno::Any
> const &)
124 return cppu::acquire(new comphelper::IndexedPropertyValuesContainer());
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */