Branch data Line data Source code
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 : :
21 : : #include "comphelper_module.hxx"
22 : :
23 : : #include <com/sun/star/container/XIndexContainer.hpp>
24 : : #include <com/sun/star/uno/Sequence.h>
25 : : #include <com/sun/star/beans/PropertyValue.hpp>
26 : : #include <cppuhelper/implbase2.hxx>
27 : : #include <com/sun/star/lang/XServiceInfo.hpp>
28 : :
29 : : #include <vector>
30 : :
31 : : using namespace com::sun::star;
32 : :
33 : : typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
34 : :
35 : : class IndexedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XIndexContainer, lang::XServiceInfo >
36 : : {
37 : : public:
38 : : IndexedPropertyValuesContainer() throw();
39 : : virtual ~IndexedPropertyValuesContainer() throw();
40 : :
41 : : // XIndexContainer
42 : : virtual void SAL_CALL insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
43 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
44 : : ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
45 : : virtual void SAL_CALL removeByIndex( sal_Int32 nIndex )
46 : : throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
47 : : ::com::sun::star::uno::RuntimeException);
48 : :
49 : : // XIndexReplace
50 : : virtual void SAL_CALL replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
51 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
52 : : ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
53 : :
54 : : // XIndexAccess
55 : : virtual sal_Int32 SAL_CALL getCount( )
56 : : throw(::com::sun::star::uno::RuntimeException);
57 : : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex )
58 : : throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
59 : : ::com::sun::star::uno::RuntimeException);
60 : :
61 : : // XElementAccess
62 : : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
63 : : throw(::com::sun::star::uno::RuntimeException);
64 : : virtual sal_Bool SAL_CALL hasElements( )
65 : : throw(::com::sun::star::uno::RuntimeException);
66 : :
67 : : //XServiceInfo
68 : : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
69 : : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
70 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
71 : :
72 : : // XServiceInfo - static versions (used for component registration)
73 : : static ::rtl::OUString SAL_CALL getImplementationName_static();
74 : : static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
75 : : static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
76 : :
77 : : private:
78 : : IndexedPropertyValues maProperties;
79 : : };
80 : :
81 [ + - ]: 3589 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
82 : : {
83 : 3589 : }
84 : :
85 : 3492 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
86 : : {
87 [ - + ]: 6984 : }
88 : :
89 : : // XIndexContainer
90 : 1865 : void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
91 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
92 : : ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
93 : : {
94 : 1865 : sal_Int32 nSize(maProperties.size());
95 [ + - ][ + + ]: 1865 : if ((nSize >= nIndex) && (nIndex >= 0))
96 : : {
97 [ + - ]: 1863 : uno::Sequence<beans::PropertyValue> aProps;
98 [ + - ][ + + ]: 1863 : if (!(aElement >>= aProps))
99 [ + - ]: 2 : throw lang::IllegalArgumentException();
100 [ + + ]: 1861 : if (nSize == nIndex)
101 [ + - ]: 1858 : maProperties.push_back(aProps);
102 : : else
103 : : {
104 : 3 : IndexedPropertyValues::iterator aItr;
105 [ + - ]: 3 : if ((nIndex * 2) < nSize)
106 : : {
107 : 3 : aItr = maProperties.begin();
108 : 3 : sal_Int32 i(0);
109 [ - + ]: 3 : while(i < nIndex)
110 : : {
111 : 0 : ++i;
112 : 0 : ++aItr;
113 : : }
114 : : }
115 : : else
116 : : {
117 : 0 : aItr = maProperties.end();
118 : 0 : sal_Int32 i(nSize - 1);
119 [ # # ]: 0 : while(i > nIndex)
120 : : {
121 : 0 : --i;
122 : 0 : --aItr;
123 : : }
124 : : }
125 [ + - ]: 3 : maProperties.insert(aItr, aProps);
126 [ + - ]: 1863 : }
127 : : }
128 : : else
129 [ + - ]: 2 : throw lang::IndexOutOfBoundsException();
130 : 1861 : }
131 : :
132 : 20 : void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
133 : : throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
134 : : ::com::sun::star::uno::RuntimeException)
135 : : {
136 : 20 : sal_Int32 nSize(maProperties.size());
137 [ + - ][ + + ]: 20 : if ((nIndex < nSize) && (nIndex >= 0))
138 : : {
139 : 18 : IndexedPropertyValues::iterator aItr;
140 [ + - ]: 18 : if ((nIndex * 2) < nSize)
141 : : {
142 : 18 : aItr = maProperties.begin();
143 : 18 : sal_Int32 i(0);
144 [ - + ]: 18 : while(i < nIndex)
145 : : {
146 : 0 : ++i;
147 : 0 : ++aItr;
148 : : }
149 : : }
150 : : else
151 : : {
152 : 0 : aItr = maProperties.end();
153 : 0 : sal_Int32 i(nSize - 1);
154 [ # # ]: 0 : while(i > nIndex)
155 : : {
156 : 0 : --i;
157 : 0 : --aItr;
158 : : }
159 : : }
160 [ + - ]: 18 : maProperties.erase(aItr);
161 : : }
162 : : else
163 [ + - ]: 2 : throw lang::IndexOutOfBoundsException();
164 : 18 : }
165 : :
166 : : // XIndexReplace
167 : 2 : void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
168 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
169 : : ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
170 : : {
171 : 2 : sal_Int32 nSize(maProperties.size());
172 [ + - ][ + - ]: 2 : if ((nIndex < nSize) && (nIndex >= 0))
173 : : {
174 [ + - ]: 2 : uno::Sequence<beans::PropertyValue> aProps;
175 [ + - ][ - + ]: 2 : if (!(aElement >>= aProps))
176 [ # # ]: 0 : throw lang::IllegalArgumentException();
177 [ + - ][ + - ]: 2 : maProperties[nIndex] = aProps;
178 : : }
179 : : else
180 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
181 : 2 : }
182 : :
183 : : // XIndexAccess
184 : 2247 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount( )
185 : : throw(::com::sun::star::uno::RuntimeException)
186 : : {
187 : 2247 : return maProperties.size();
188 : : }
189 : :
190 : 3963 : ::com::sun::star::uno::Any SAL_CALL IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex )
191 : : throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
192 : : ::com::sun::star::uno::RuntimeException)
193 : : {
194 : 3963 : sal_Int32 nSize(maProperties.size());
195 [ - + ][ + - ]: 3963 : if (!((nIndex < nSize) && (nIndex >= 0)))
196 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
197 : :
198 : 3963 : uno::Any aAny;
199 [ + - ]: 3963 : aAny <<= maProperties[nIndex];
200 : 3963 : return aAny;
201 : : }
202 : :
203 : : // XElementAccess
204 : 2 : ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType( )
205 : : throw(::com::sun::star::uno::RuntimeException)
206 : : {
207 : 2 : return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
208 : : }
209 : :
210 : 1816 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements( )
211 : : throw(::com::sun::star::uno::RuntimeException)
212 : : {
213 : 1816 : return !maProperties.empty();
214 : : }
215 : :
216 : : //XServiceInfo
217 : 0 : ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
218 : : {
219 : 0 : return getImplementationName_static();
220 : : }
221 : :
222 : 227 : ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static( )
223 : : {
224 : 227 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndexedPropertyValuesContainer" ) );
225 : : }
226 : :
227 : 0 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
228 : : {
229 [ # # ]: 0 : rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
230 : 0 : return aServiceName == ServiceName;
231 : : }
232 : :
233 : 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
234 : : {
235 : 0 : return getSupportedServiceNames_static();
236 : : }
237 : :
238 : :
239 : 227 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static( )
240 : : {
241 [ + - ]: 227 : const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
242 [ + - ]: 227 : const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
243 : 227 : return aSeq;
244 : : }
245 : :
246 : :
247 : 3589 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
248 : : SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
249 : : {
250 : 3589 : return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
251 : : }
252 : :
253 : 227 : void createRegistryInfo_IndexedPropertyValuesContainer()
254 : : {
255 [ + - ][ + - ]: 227 : static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
[ + - ][ # # ]
256 : 227 : }
257 : :
258 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|