bump product version to 6.4.0.3
[LibreOffice.git] / comphelper / source / container / IndexedPropertyValuesContainer.cxx
blob0053cc8e4374d1ef2e1880d6a4307467e2fe5b0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/container/XIndexContainer.hpp>
21 #include <com/sun/star/uno/Sequence.h>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/supportsservice.hxx>
29 #include <vector>
31 namespace com::sun::star::uno { class XComponentContext; }
33 using namespace com::sun::star;
35 typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
37 class IndexedPropertyValuesContainer : public cppu::WeakImplHelper< container::XIndexContainer, lang::XServiceInfo >
39 public:
40 IndexedPropertyValuesContainer() throw();
42 // XIndexContainer
43 virtual void SAL_CALL insertByIndex( sal_Int32 nIndex, const css::uno::Any& aElement ) override;
44 virtual void SAL_CALL removeByIndex( sal_Int32 nIndex ) override;
46 // XIndexReplace
47 virtual void SAL_CALL replaceByIndex( sal_Int32 nIndex, const css::uno::Any& aElement ) override;
49 // XIndexAccess
50 virtual sal_Int32 SAL_CALL getCount( ) override;
51 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) override;
53 // XElementAccess
54 virtual css::uno::Type SAL_CALL getElementType( ) override;
55 virtual sal_Bool SAL_CALL hasElements( ) override;
57 //XServiceInfo
58 virtual OUString SAL_CALL getImplementationName( ) override;
59 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
60 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
62 private:
63 IndexedPropertyValues maProperties;
66 IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
70 // XIndexContainer
71 void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, const css::uno::Any& aElement )
73 sal_Int32 nSize(maProperties.size());
74 if ((nSize < nIndex) || (nIndex < 0))
75 throw lang::IndexOutOfBoundsException();
77 uno::Sequence<beans::PropertyValue> aProps;
78 if (!(aElement >>= aProps))
79 throw lang::IllegalArgumentException();
80 if (nSize == nIndex)
81 maProperties.push_back(aProps);
82 else
83 maProperties.insert(maProperties.begin() + nIndex, aProps);
86 void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
88 if ((nIndex >= sal_Int32(maProperties.size())) || (nIndex < 0))
89 throw lang::IndexOutOfBoundsException();
91 maProperties.erase(maProperties.begin() + nIndex);
94 // XIndexReplace
95 void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex, const css::uno::Any& aElement )
97 sal_Int32 nSize(maProperties.size());
98 if ((nIndex >= nSize) || (nIndex < 0))
99 throw lang::IndexOutOfBoundsException();
101 uno::Sequence<beans::PropertyValue> aProps;
102 if (!(aElement >>= aProps))
103 throw lang::IllegalArgumentException();
104 maProperties[nIndex] = aProps;
107 // XIndexAccess
108 sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount( )
110 return maProperties.size();
113 css::uno::Any SAL_CALL IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex )
115 sal_Int32 nSize(maProperties.size());
116 if (!((nIndex < nSize) && (nIndex >= 0)))
117 throw lang::IndexOutOfBoundsException();
119 return uno::Any( maProperties[nIndex] );
122 // XElementAccess
123 css::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType( )
125 return cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get();
128 sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements( )
130 return !maProperties.empty();
133 //XServiceInfo
134 OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName( )
136 return "IndexedPropertyValuesContainer";
139 sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName )
141 return cppu::supportsService(this, ServiceName);
144 css::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( )
146 return { "com.sun.star.document.IndexedPropertyValues" };
149 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
150 IndexedPropertyValuesContainer_get_implementation(
151 css::uno::XComponentContext *,
152 css::uno::Sequence<css::uno::Any> const &)
154 return cppu::acquire(new IndexedPropertyValuesContainer());
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */