Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / InternalDataProvider.hxx
bloba5032efcdab8247896603344e54eedd584d6c512
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 .
19 #pragma once
21 #include "InternalData.hxx"
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/chart/XDateCategories.hpp>
25 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
26 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
27 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/util/XCloneable.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/weakref.hxx>
32 #include <rtl/ref.hxx>
34 #include <map>
36 namespace com::sun::star::chart2 { class XChartDocument; }
38 namespace chart
40 class ChartModel;
41 class UncachedDataSequence;
43 namespace impl
46 typedef ::cppu::WeakImplHelper<
47 css::chart2::XInternalDataProvider,
48 css::chart2::data::XRangeXMLConversion,
49 css::chart2::XAnyDescriptionAccess,
50 css::chart::XDateCategories,
51 css::util::XCloneable,
52 css::lang::XInitialization,
53 css::lang::XServiceInfo >
54 InternalDataProvider_Base;
57 /** Data provider that handles data internally. This is used for charts with
58 their own data.
60 <p>The format for single ranges is "categories|label n|n" where n is a
61 non-negative number. Meaning return all categories, the label of sequence n,
62 or the data of sequence n.</p>
64 <p>The format for a complete range is "all". (Do we need more than
65 that?)</p>
67 class InternalDataProvider final :
68 public impl::InternalDataProvider_Base
70 public:
71 explicit InternalDataProvider();
73 // #i120559# allow handing over a default for data orientation
74 // (DataInColumns) that will be used when no data is available
75 explicit InternalDataProvider(
76 const rtl::Reference< ::chart::ChartModel > & xChartDoc,
77 bool bConnectToModel,
78 bool bDefaultDataInColumns );
79 explicit InternalDataProvider( const InternalDataProvider & rOther );
80 virtual ~InternalDataProvider() override;
82 /// declare XServiceInfo methods
83 virtual OUString SAL_CALL getImplementationName() override;
84 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
85 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
87 // ____ XInternalDataProvider ____
88 virtual sal_Bool SAL_CALL hasDataByRangeRepresentation( const OUString& aRange ) override;
89 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
90 getDataByRangeRepresentation( const OUString& aRange ) override;
91 virtual void SAL_CALL setDataByRangeRepresentation(
92 const OUString& aRange,
93 const css::uno::Sequence< css::uno::Any >& aNewData ) override;
94 virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex ) override;
95 virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex ) override;
96 virtual void SAL_CALL appendSequence() override;
97 virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel ) override;
98 virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel ) override;
99 virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex ) override;
100 virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex ) override;
101 virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex ) override;
102 virtual void SAL_CALL registerDataSequenceForChanges(
103 const css::uno::Reference< css::chart2::data::XDataSequence >& xSeq ) override;
105 // ____ XDataProvider (base of XInternalDataProvider) ____
106 virtual sal_Bool SAL_CALL createDataSourcePossible(
107 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
108 virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL createDataSource(
109 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
110 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL detectArguments(
111 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
112 virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
113 const OUString& aRangeRepresentation ) override;
114 virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
115 const OUString& aRangeRepresentation ) override;
117 virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
118 createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation,
119 const OUString& aRoleQualifier ) override;
121 virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
123 // ____ XRangeXMLConversion ____
124 virtual OUString SAL_CALL convertRangeToXML(
125 const OUString& aRangeRepresentation ) override;
126 virtual OUString SAL_CALL convertRangeFromXML(
127 const OUString& aXMLRange ) override;
129 // ____ XDateCategories ____
130 virtual css::uno::Sequence< double > SAL_CALL getDateCategories() override;
131 virtual void SAL_CALL setDateCategories( const css::uno::Sequence< double >& rDates ) override;
133 // ____ XAnyDescriptionAccess ____
134 virtual css::uno::Sequence< css::uno::Sequence< css::uno::Any > > SAL_CALL
135 getAnyRowDescriptions() override;
136 virtual void SAL_CALL setAnyRowDescriptions(
137 const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& aRowDescriptions ) override;
138 virtual css::uno::Sequence< css::uno::Sequence< css::uno::Any > > SAL_CALL
139 getAnyColumnDescriptions() override;
140 virtual void SAL_CALL setAnyColumnDescriptions(
141 const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& aColumnDescriptions ) override;
143 // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____
144 virtual css::uno::Sequence< css::uno::Sequence< OUString > > SAL_CALL
145 getComplexRowDescriptions() override;
146 virtual void SAL_CALL setComplexRowDescriptions(
147 const css::uno::Sequence< css::uno::Sequence< OUString > >& aRowDescriptions ) override;
148 virtual css::uno::Sequence< css::uno::Sequence< OUString > > SAL_CALL
149 getComplexColumnDescriptions() override;
150 virtual void SAL_CALL setComplexColumnDescriptions(
151 const css::uno::Sequence< css::uno::Sequence< OUString > >& aColumnDescriptions ) override;
153 // ____ XChartDataArray (base of XComplexDescriptionAccess) ____
154 virtual css::uno::Sequence< css::uno::Sequence< double > > SAL_CALL getData() override;
155 virtual void SAL_CALL setData(
156 const css::uno::Sequence< css::uno::Sequence< double > >& aData ) override;
157 virtual css::uno::Sequence< OUString > SAL_CALL getRowDescriptions() override;
158 virtual void SAL_CALL setRowDescriptions(
159 const css::uno::Sequence< OUString >& aRowDescriptions ) override;
160 virtual css::uno::Sequence< OUString > SAL_CALL getColumnDescriptions() override;
161 virtual void SAL_CALL setColumnDescriptions(
162 const css::uno::Sequence< OUString >& aColumnDescriptions ) override;
164 // ____ XChartData (base of XChartDataArray) ____
165 virtual void SAL_CALL addChartDataChangeEventListener(
166 const css::uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) override;
167 virtual void SAL_CALL removeChartDataChangeEventListener(
168 const css::uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) override;
169 virtual double SAL_CALL getNotANumber() override;
170 virtual sal_Bool SAL_CALL isNotANumber(
171 double nNumber ) override;
173 // ____ XCloneable ____
174 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
175 // css::lang::XInitialization:
176 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > & aArguments) override;
178 private:
179 void addDataSequenceToMap(
180 const OUString & rRangeRepresentation,
181 const css::uno::Reference< css::chart2::data::XDataSequence > & xSequence );
183 css::uno::Reference< css::chart2::data::XDataSequence >
184 createDataSequenceAndAddToMap( const OUString & rRangeRepresentation,
185 const OUString & rRole );
186 rtl::Reference< UncachedDataSequence >
187 createDataSequenceAndAddToMap( const OUString & rRangeRepresentation );
189 rtl::Reference<UncachedDataSequence>
190 createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole,
191 std::u16string_view rRoleQualifier);
193 void deleteMapReferences( const OUString & rRangeRepresentation );
195 void adaptMapReferences(
196 const OUString & rOldRangeRepresentation,
197 const OUString & rNewRangeRepresentation );
199 void increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
200 void decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
202 typedef std::multimap< OUString,
203 css::uno::WeakReference< css::chart2::data::XDataSequence > >
204 tSequenceMap;
205 typedef std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange;
207 /** cache for all sequences that have been returned.
209 If the range-representation of a sequence changes and it is still
210 referred to by some component (weak reference is valid), the range will
211 be adapted.
213 tSequenceMap m_aSequenceMap;
214 InternalData m_aInternalData;
215 bool m_bDataInColumns;
218 } // namespace chart
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */