Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / CachedDataSequence.hxx
blobe9c1b9d50d25752a2bf339d10d5e3d4f4c7c94cc
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 // helper classes
22 #include <cppuhelper/compbase.hxx>
23 #include <comphelper/uno3.hxx>
24 #include <comphelper/broadcasthelper.hxx>
25 #include <comphelper/propertycontainer.hxx>
26 #include <comphelper/proparrhlp.hxx>
28 // interfaces and types
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/chart2/data/XDataSequence.hpp>
32 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
33 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
34 #include <com/sun/star/util/XCloneable.hpp>
35 #include "ModifyListenerHelper.hxx"
37 namespace com::sun::star::uno { class XComponentContext; }
39 namespace chart
42 namespace impl
44 typedef ::cppu::WeakComponentImplHelper<
45 css::chart2::data::XDataSequence,
46 css::chart2::data::XNumericalDataSequence,
47 css::chart2::data::XTextualDataSequence,
48 css::util::XCloneable,
49 css::util::XModifyBroadcaster,
50 css::lang::XInitialization,
51 css::lang::XServiceInfo >
52 CachedDataSequence_Base;
55 /**
56 * This sequence object does store actual values within, hence "cached".
58 class CachedDataSequence final :
59 public ::comphelper::OMutexAndBroadcastHelper,
60 public ::comphelper::OPropertyContainer,
61 public ::comphelper::OPropertyArrayUsageHelper< CachedDataSequence >,
62 public impl::CachedDataSequence_Base
64 public:
65 /** constructs an empty sequence
67 CachedDataSequence();
69 explicit CachedDataSequence( const css::uno::Reference< css::uno::XComponentContext > & xContext );
71 /** creates a sequence and initializes it with the given string. This is
72 especially useful for labels, which only have one element.
74 explicit CachedDataSequence( const OUString & rSingleText );
76 /// Copy CTOR
77 explicit CachedDataSequence( const CachedDataSequence & rSource );
79 virtual ~CachedDataSequence() override;
81 /// declare XServiceInfo methods
82 virtual OUString SAL_CALL getImplementationName() override;
83 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
84 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
86 /// merge XInterface implementations
87 DECLARE_XINTERFACE()
88 /// merge XTypeProvider implementations
89 DECLARE_XTYPEPROVIDER()
91 private:
92 // ____ XPropertySet ____
93 /// @see css::beans::XPropertySet
94 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
95 /// @see ::comphelper::OPropertySetHelper
96 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
97 /// @see ::comphelper::OPropertyArrayUsageHelper
98 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
100 // ____ XDataSequence ____
101 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override;
102 virtual OUString SAL_CALL getSourceRangeRepresentation() override;
103 virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(
104 css::chart2::data::LabelOrigin nLabelOrigin ) override;
105 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
107 // ____ XNumericalDataSequence ____
108 /// @see css::chart::data::XNumericalDataSequence
109 virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override;
111 // ____ XTextualDataSequence ____
112 /// @see css::chart::data::XTextualDataSequence
113 virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override;
115 // ____ XCloneable ____
116 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
118 // ____ XModifyBroadcaster ____
119 virtual void SAL_CALL addModifyListener(
120 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
121 virtual void SAL_CALL removeModifyListener(
122 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
124 // css::lang::XInitialization:
125 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > & aArguments) override;
127 // <properties>
128 sal_Int32 m_nNumberFormatKey;
129 OUString m_sRole;
130 // </properties>
132 enum DataType
134 NUMERICAL,
135 TEXTUAL,
136 MIXED
139 /** This method registers all properties. It should be called by all
140 constructors.
142 void registerProperties();
144 /** is used by interface method getNumericalData().
146 css::uno::Sequence< double > Impl_getNumericalData() const;
147 /** is used by interface method getTextualData().
149 css::uno::Sequence< OUString > Impl_getTextualData() const;
150 /** is used by interface method getData().
152 css::uno::Sequence< css::uno::Any > Impl_getMixedData() const;
154 enum DataType m_eCurrentDataType;
156 css::uno::Sequence< double > m_aNumericalSequence;
157 css::uno::Sequence< OUString > m_aTextualSequence;
158 css::uno::Sequence< css::uno::Any > m_aMixedSequence;
159 rtl::Reference<ModifyEventForwarder> m_xModifyEventForwarder;
162 } // namespace chart
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */