merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / container / IndexedPropertyValuesContainer.cxx
blob23e9d567377d55ae4a2da002f46cc46492891242
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: IndexedPropertyValuesContainer.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 #include "comphelper_module.hxx"
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/uno/Sequence.h>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <cppuhelper/implbase2.hxx>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
44 #ifndef __SGI_STL_VECTOR
45 #include <vector>
46 #endif
48 using namespace com::sun::star;
50 typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
52 class IndexedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XIndexContainer, lang::XServiceInfo >
54 public:
55 IndexedPropertyValuesContainer() throw();
56 virtual ~IndexedPropertyValuesContainer() throw();
58 // XIndexContainer
59 virtual void SAL_CALL insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
60 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
61 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
62 virtual void SAL_CALL removeByIndex( sal_Int32 nIndex )
63 throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
64 ::com::sun::star::uno::RuntimeException);
66 // XIndexReplace
67 virtual void SAL_CALL replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
68 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
69 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
71 // XIndexAccess
72 virtual sal_Int32 SAL_CALL getCount( )
73 throw(::com::sun::star::uno::RuntimeException);
74 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex )
75 throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
76 ::com::sun::star::uno::RuntimeException);
78 // XElementAccess
79 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
80 throw(::com::sun::star::uno::RuntimeException);
81 virtual sal_Bool SAL_CALL hasElements( )
82 throw(::com::sun::star::uno::RuntimeException);
84 //XServiceInfo
85 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
86 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
87 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
89 // XServiceInfo - static versions (used for component registration)
90 static ::rtl::OUString SAL_CALL getImplementationName_static();
91 static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
92 static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
94 private:
95 IndexedPropertyValues maProperties;
98 IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
102 IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
106 // XIndexContainer
107 void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
108 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
109 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
111 sal_Int32 nSize(maProperties.size());
112 if ((nSize >= nIndex) && (nIndex >= 0))
114 uno::Sequence<beans::PropertyValue> aProps;
115 if (!(aElement >>= aProps))
116 throw lang::IllegalArgumentException();
117 if (nSize == nIndex)
118 maProperties.push_back(aProps);
119 else
121 IndexedPropertyValues::iterator aItr;
122 if ((nIndex * 2) < nSize)
124 aItr = maProperties.begin();
125 sal_Int32 i(0);
126 while(i < nIndex)
128 i++;
129 aItr++;
132 else
134 aItr = maProperties.end();
135 sal_Int32 i(nSize - 1);
136 while(i > nIndex)
138 i--;
139 aItr--;
142 maProperties.insert(aItr, aProps);
145 else
146 throw lang::IndexOutOfBoundsException();
149 void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
150 throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
151 ::com::sun::star::uno::RuntimeException)
153 sal_Int32 nSize(maProperties.size());
154 if ((nIndex < nSize) && (nIndex >= 0))
156 IndexedPropertyValues::iterator aItr;
157 if ((nIndex * 2) < nSize)
159 aItr = maProperties.begin();
160 sal_Int32 i(0);
161 while(i < nIndex)
163 i++;
164 aItr++;
167 else
169 aItr = maProperties.end();
170 sal_Int32 i(nSize - 1);
171 while(i > nIndex)
173 i--;
174 aItr--;
177 maProperties.erase(aItr);
179 else
180 throw lang::IndexOutOfBoundsException();
183 // XIndexReplace
184 void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
185 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
186 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
188 sal_Int32 nSize(maProperties.size());
189 if ((nIndex < nSize) && (nIndex >= 0))
191 uno::Sequence<beans::PropertyValue> aProps;
192 if (!(aElement >>= aProps))
193 throw lang::IllegalArgumentException();
194 maProperties[nIndex] = aProps;
196 else
197 throw lang::IndexOutOfBoundsException();
200 // XIndexAccess
201 sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount( )
202 throw(::com::sun::star::uno::RuntimeException)
204 return maProperties.size();
207 ::com::sun::star::uno::Any SAL_CALL IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex )
208 throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
209 ::com::sun::star::uno::RuntimeException)
211 sal_Int32 nSize(maProperties.size());
212 if (!((nIndex < nSize) && (nIndex >= 0)))
213 throw lang::IndexOutOfBoundsException();
215 uno::Any aAny;
216 aAny <<= maProperties[nIndex];
217 return aAny;
220 // XElementAccess
221 ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType( )
222 throw(::com::sun::star::uno::RuntimeException)
224 return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
227 sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements( )
228 throw(::com::sun::star::uno::RuntimeException)
230 return !maProperties.empty();
233 //XServiceInfo
234 ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
236 return getImplementationName_static();
239 ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static( )
241 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndexedPropertyValuesContainer" ) );
244 sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
246 rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
247 return aServiceName == ServiceName;
250 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
252 return getSupportedServiceNames_static();
256 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static( )
258 const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
259 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
260 return aSeq;
264 uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
265 const uno::Reference< uno::XComponentContext >&)
267 return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
270 void createRegistryInfo_IndexedPropertyValuesContainer()
272 static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;