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 "CachedDataSequence.hxx"
22 : : #include "macros.hxx"
23 : : #include "PropertyHelper.hxx"
24 : : #include "ContainerHelper.hxx"
25 : : #include "CommonFunctors.hxx"
26 : : #include "ModifyListenerHelper.hxx"
27 : :
28 : : #include <comphelper/sequenceashashmap.hxx>
29 : :
30 : : #include <algorithm>
31 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : : #include <rtl/math.hxx>
33 : :
34 : : using namespace ::com::sun::star;
35 : : using namespace ::chart::ContainerHelper;
36 : :
37 : : using ::com::sun::star::uno::Sequence;
38 : : using ::com::sun::star::uno::Reference;
39 : : using ::com::sun::star::uno::Any;
40 : : using ::rtl::OUString;
41 : : using ::osl::MutexGuard;
42 : :
43 : : // necessary for MS compiler
44 : : using ::comphelper::OPropertyContainer;
45 : : using ::comphelper::OMutexAndBroadcastHelper;
46 : : using ::comphelper::OPropertyArrayUsageHelper;
47 : : using ::chart::impl::CachedDataSequence_Base;
48 : :
49 : : namespace
50 : : {
51 : 16 : static const OUString lcl_aServiceName(
52 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.CachedDataSequence" ));
53 : :
54 : : enum
55 : : {
56 : : // PROP_SOURCE_IDENTIFIER,
57 : : PROP_NUMBERFORMAT_KEY,
58 : : PROP_PROPOSED_ROLE
59 : : };
60 : : } // anonymous namespace
61 : :
62 : :
63 : : // ____________________
64 : : namespace chart
65 : : {
66 : :
67 : 0 : CachedDataSequence::CachedDataSequence()
68 : 0 : : OPropertyContainer( GetBroadcastHelper()),
69 : 0 : CachedDataSequence_Base( GetMutex()),
70 : : m_eCurrentDataType( NUMERICAL ),
71 [ # # ]: 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ # # # # ]
[ # # ][ # # ]
[ # # ]
72 : : {
73 [ # # ]: 0 : registerProperties();
74 : 0 : }
75 : 0 : CachedDataSequence::CachedDataSequence( const Reference< uno::XComponentContext > & /*xContext*/ )
76 : 0 : : OPropertyContainer( GetBroadcastHelper()),
77 : 0 : CachedDataSequence_Base( GetMutex()),
78 : : m_eCurrentDataType( MIXED ),
79 [ # # ]: 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder( ))
[ # # # # ]
[ # # ][ # # ]
[ # # ]
80 : : {
81 [ # # ]: 0 : registerProperties();
82 : 0 : }
83 : :
84 : 0 : CachedDataSequence::CachedDataSequence( const OUString & rSingleText )
85 : 0 : : OPropertyContainer( GetBroadcastHelper()),
86 : 0 : CachedDataSequence_Base( GetMutex()),
87 : : m_eCurrentDataType( TEXTUAL ),
88 [ # # ]: 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ # # # # ]
[ # # ][ # # ]
[ # # ]
89 : : {
90 [ # # ]: 0 : m_aTextualSequence.realloc(1);
91 [ # # ]: 0 : m_aTextualSequence[0] = rSingleText;
92 [ # # ]: 0 : registerProperties();
93 : 0 : }
94 : :
95 : 0 : CachedDataSequence::CachedDataSequence( const CachedDataSequence & rSource )
96 : : : OMutexAndBroadcastHelper(),
97 : 0 : OPropertyContainer( GetBroadcastHelper()),
98 : : OPropertyArrayUsageHelper< CachedDataSequence >(),
99 : 0 : CachedDataSequence_Base( GetMutex()),
100 : : m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
101 : : m_sRole( rSource.m_sRole ),
102 : : m_eCurrentDataType( rSource.m_eCurrentDataType ),
103 [ # # ]: 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ # # # # ]
[ # # ][ # # ]
[ # # ]
104 : : {
105 [ # # # # ]: 0 : switch( m_eCurrentDataType )
106 : : {
107 : : case TEXTUAL:
108 [ # # ]: 0 : m_aTextualSequence = rSource.m_aTextualSequence;
109 : 0 : break;
110 : : case NUMERICAL:
111 [ # # ]: 0 : m_aNumericalSequence = rSource.m_aNumericalSequence;
112 : 0 : break;
113 : : case MIXED:
114 [ # # ]: 0 : m_aMixedSequence = rSource.m_aMixedSequence;
115 : 0 : break;
116 : : }
117 : :
118 [ # # ]: 0 : registerProperties();
119 : 0 : }
120 : :
121 [ # # ][ # # ]: 0 : CachedDataSequence::~CachedDataSequence()
[ # # ][ # # ]
[ # # ][ # # ]
122 [ # # ]: 0 : {}
123 : :
124 : 0 : void CachedDataSequence::registerProperties()
125 : : {
126 : : registerProperty( C2U( "NumberFormatKey" ),
127 : : PROP_NUMBERFORMAT_KEY,
128 : : 0, // PropertyAttributes
129 : : & m_nNumberFormatKey,
130 [ # # ]: 0 : ::getCppuType( & m_nNumberFormatKey ) );
131 : :
132 : : registerProperty( C2U( "Role" ),
133 : : PROP_PROPOSED_ROLE,
134 : : 0, // PropertyAttributes
135 : : & m_sRole,
136 [ # # ]: 0 : ::getCppuType( & m_sRole ) );
137 : 0 : }
138 : :
139 : 0 : Sequence< double > CachedDataSequence::Impl_getNumericalData() const
140 : : {
141 [ # # ]: 0 : if( m_eCurrentDataType == NUMERICAL )
142 [ # # ]: 0 : return m_aNumericalSequence;
143 : :
144 : : sal_Int32 nSize = ( m_eCurrentDataType == TEXTUAL )
145 : 0 : ? m_aTextualSequence.getLength()
146 [ # # ]: 0 : : m_aMixedSequence.getLength();
147 : :
148 [ # # ]: 0 : Sequence< double > aResult( nSize );
149 [ # # ]: 0 : double * pResultArray = aResult.getArray();
150 : :
151 [ # # ]: 0 : if( m_eCurrentDataType == TEXTUAL )
152 : : {
153 : 0 : const OUString * pTextArray = m_aTextualSequence.getConstArray();
154 : : ::std::transform( pTextArray, pTextArray + nSize,
155 : : pResultArray,
156 : 0 : CommonFunctors::OUStringToDouble() );
157 : : }
158 : : else
159 : : {
160 : : OSL_ASSERT( m_eCurrentDataType == MIXED );
161 : 0 : const Any * pMixedArray = m_aMixedSequence.getConstArray();
162 : : ::std::transform( pMixedArray, pMixedArray + nSize,
163 : : pResultArray,
164 : 0 : CommonFunctors::AnyToDouble() );
165 : : }
166 [ # # ][ # # ]: 0 : return aResult;
167 : : }
168 : :
169 : 0 : Sequence< OUString > CachedDataSequence::Impl_getTextualData() const
170 : : {
171 [ # # ]: 0 : if( m_eCurrentDataType == TEXTUAL )
172 [ # # ]: 0 : return m_aTextualSequence;
173 : :
174 : : sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
175 : 0 : ? m_aNumericalSequence.getLength()
176 [ # # ]: 0 : : m_aMixedSequence.getLength();
177 : :
178 [ # # ]: 0 : Sequence< OUString > aResult( nSize );
179 [ # # ]: 0 : OUString * pResultArray = aResult.getArray();
180 : :
181 [ # # ]: 0 : if( m_eCurrentDataType == NUMERICAL )
182 : : {
183 : 0 : const double * pTextArray = m_aNumericalSequence.getConstArray();
184 : : ::std::transform( pTextArray, pTextArray + nSize,
185 : : pResultArray,
186 : 0 : CommonFunctors::DoubleToOUString() );
187 : : }
188 : : else
189 : : {
190 : : OSL_ASSERT( m_eCurrentDataType == MIXED );
191 : 0 : const Any * pMixedArray = m_aMixedSequence.getConstArray();
192 : : ::std::transform( pMixedArray, pMixedArray + nSize,
193 : : pResultArray,
194 : 0 : CommonFunctors::AnyToString() );
195 : : }
196 : :
197 [ # # ][ # # ]: 0 : return aResult;
198 : : }
199 : :
200 : 0 : Sequence< Any > CachedDataSequence::Impl_getMixedData() const
201 : : {
202 [ # # ]: 0 : if( m_eCurrentDataType == MIXED )
203 [ # # ]: 0 : return m_aMixedSequence;
204 : :
205 : : sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
206 : 0 : ? m_aNumericalSequence.getLength()
207 [ # # ]: 0 : : m_aTextualSequence.getLength();
208 : :
209 [ # # ]: 0 : Sequence< Any > aResult( nSize );
210 [ # # ]: 0 : Any * pResultArray = aResult.getArray();
211 : :
212 [ # # ]: 0 : if( m_eCurrentDataType == NUMERICAL )
213 : : {
214 : 0 : const double * pTextArray = m_aNumericalSequence.getConstArray();
215 : : ::std::transform( pTextArray, pTextArray + nSize,
216 : : pResultArray,
217 [ # # ]: 0 : CommonFunctors::makeAny< double >() );
218 : : }
219 : : else
220 : : {
221 : : OSL_ASSERT( m_eCurrentDataType == TEXTUAL );
222 : 0 : const OUString * pMixedArray = m_aTextualSequence.getConstArray();
223 : : ::std::transform( pMixedArray, pMixedArray + nSize,
224 : : pResultArray,
225 [ # # ]: 0 : CommonFunctors::makeAny< OUString >() );
226 : : }
227 : :
228 [ # # ][ # # ]: 0 : return aResult;
229 : : }
230 : :
231 : : // ================================================================================
232 : :
233 : 0 : Sequence< OUString > CachedDataSequence::getSupportedServiceNames_Static()
234 : : {
235 : 0 : Sequence< OUString > aServices( 4 );
236 [ # # ]: 0 : aServices[ 0 ] = lcl_aServiceName;
237 [ # # ][ # # ]: 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.data.DataSequence" );
238 [ # # ][ # # ]: 0 : aServices[ 2 ] = C2U( "com.sun.star.chart2.data.NumericalDataSequence" );
239 [ # # ][ # # ]: 0 : aServices[ 3 ] = C2U( "com.sun.star.chart2.data.TextualDataSequence" );
240 : 0 : return aServices;
241 : : }
242 : :
243 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XINTERFACE2( CachedDataSequence, CachedDataSequence_Base, OPropertyContainer )
244 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( CachedDataSequence, CachedDataSequence_Base, OPropertyContainer )
[ # # ]
245 : :
246 : : // ____ XPropertySet ____
247 : 0 : Reference< beans::XPropertySetInfo > SAL_CALL CachedDataSequence::getPropertySetInfo()
248 : : throw(uno::RuntimeException)
249 : : {
250 : 0 : return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
251 : : }
252 : :
253 : : // ____ ::comphelper::OPropertySetHelper ____
254 : : // __________________________________________
255 : 0 : ::cppu::IPropertyArrayHelper& CachedDataSequence::getInfoHelper()
256 : : {
257 : 0 : return *getArrayHelper();
258 : : }
259 : :
260 : : // ____ ::comphelper::OPropertyArrayHelper ____
261 : : // ____________________________________________
262 : 0 : ::cppu::IPropertyArrayHelper* CachedDataSequence::createArrayHelper() const
263 : : {
264 [ # # ]: 0 : Sequence< beans::Property > aProps;
265 : : // describes all properties which have been registered in the ctor
266 [ # # ]: 0 : describeProperties( aProps );
267 : :
268 [ # # ][ # # ]: 0 : return new ::cppu::OPropertyArrayHelper( aProps );
269 : : }
270 : :
271 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
272 [ # # ][ # # ]: 30 : APPHELPER_XSERVICEINFO_IMPL( CachedDataSequence, lcl_aServiceName )
[ # # ][ # # ]
[ # # ]
273 : :
274 : : // ================================================================================
275 : :
276 : : // ________ XNumericalDataSequence ________
277 : 0 : Sequence< double > SAL_CALL CachedDataSequence::getNumericalData()
278 : : throw (uno::RuntimeException)
279 : : {
280 [ # # ]: 0 : MutexGuard aGuard( GetMutex() );
281 : :
282 [ # # ]: 0 : if( m_eCurrentDataType == NUMERICAL )
283 [ # # ]: 0 : return m_aNumericalSequence;
284 : : else
285 [ # # ][ # # ]: 0 : return Impl_getNumericalData();
286 : : }
287 : :
288 : : // ________ XTextualDataSequence ________
289 : 0 : Sequence< OUString > SAL_CALL CachedDataSequence::getTextualData()
290 : : throw (uno::RuntimeException)
291 : : {
292 [ # # ]: 0 : MutexGuard aGuard( GetMutex() );
293 : :
294 [ # # ]: 0 : if( m_eCurrentDataType == TEXTUAL )
295 [ # # ]: 0 : return m_aTextualSequence;
296 : : else
297 [ # # ][ # # ]: 0 : return Impl_getTextualData();
298 : : }
299 : :
300 : : // ________ XDataSequence ________
301 : 0 : Sequence< Any > SAL_CALL CachedDataSequence::getData()
302 : : throw (uno::RuntimeException)
303 : : {
304 [ # # ]: 0 : MutexGuard aGuard( GetMutex() );
305 [ # # ][ # # ]: 0 : return Impl_getMixedData();
306 : : }
307 : :
308 : 0 : OUString SAL_CALL CachedDataSequence::getSourceRangeRepresentation()
309 : : throw (uno::RuntimeException)
310 : : {
311 : 0 : return m_sRole;
312 : : }
313 : :
314 : 0 : Sequence< OUString > SAL_CALL CachedDataSequence::generateLabel( chart2::data::LabelOrigin /*eLabelOrigin*/ )
315 : : throw (uno::RuntimeException)
316 : : {
317 : : // return empty label, as we have no range representaions to determine something useful
318 : 0 : return Sequence< OUString >();
319 : : }
320 : :
321 : 0 : ::sal_Int32 SAL_CALL CachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 /*nIndex*/ )
322 : : throw (lang::IndexOutOfBoundsException,
323 : : uno::RuntimeException)
324 : : {
325 : 0 : return 0;
326 : : }
327 : :
328 : 0 : Reference< util::XCloneable > SAL_CALL CachedDataSequence::createClone()
329 : : throw (uno::RuntimeException)
330 : : {
331 [ # # ]: 0 : CachedDataSequence * pNewSeq = new CachedDataSequence( *this );
332 : :
333 [ # # ]: 0 : return Reference< util::XCloneable >( pNewSeq );
334 : : }
335 : :
336 : 0 : void SAL_CALL CachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
337 : : throw (uno::RuntimeException)
338 : : {
339 : : try
340 : : {
341 [ # # ]: 0 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
342 [ # # ][ # # ]: 0 : xBroadcaster->addModifyListener( aListener );
[ # # ]
343 : : }
344 : 0 : catch( const uno::Exception & ex )
345 : : {
346 : : ASSERT_EXCEPTION( ex );
347 : : }
348 : 0 : }
349 : :
350 : 0 : void SAL_CALL CachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
351 : : throw (uno::RuntimeException)
352 : : {
353 : : try
354 : : {
355 [ # # ]: 0 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
356 [ # # ][ # # ]: 0 : xBroadcaster->removeModifyListener( aListener );
[ # # ]
357 : : }
358 : 0 : catch( const uno::Exception & ex )
359 : : {
360 : : ASSERT_EXCEPTION( ex );
361 : : }
362 : 0 : }
363 : :
364 : : // lang::XInitialization:
365 : 0 : void SAL_CALL CachedDataSequence::initialize(const uno::Sequence< uno::Any > & _aArguments) throw (uno::RuntimeException, uno::Exception)
366 : : {
367 [ # # ]: 0 : ::comphelper::SequenceAsHashMap aMap(_aArguments);
368 [ # # ][ # # ]: 0 : m_aNumericalSequence = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSequence")),m_aNumericalSequence);
[ # # ][ # # ]
369 [ # # ]: 0 : if ( m_aNumericalSequence.getLength() )
370 : 0 : m_eCurrentDataType = NUMERICAL;
371 : : else
372 : : {
373 [ # # ][ # # ]: 0 : m_aTextualSequence = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSequence")),m_aTextualSequence);
[ # # ][ # # ]
374 [ # # ]: 0 : if ( m_aTextualSequence.getLength() )
375 : 0 : m_eCurrentDataType = TEXTUAL;
376 : : else
377 : : {
378 [ # # ][ # # ]: 0 : m_aMixedSequence = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSequence")),m_aMixedSequence);
[ # # ][ # # ]
379 [ # # ]: 0 : if ( m_aMixedSequence.getLength() )
380 : 0 : m_eCurrentDataType = MIXED;
381 : : }
382 [ # # ]: 0 : }
383 : 0 : }
384 [ + - ][ + - ]: 48 : } // namespace chart
385 : :
386 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|