Update git submodules
[LibreOffice.git] / ucb / source / sorter / sortresult.hxx
blobb4da01c57c7d222c1d6fb83434b768431b02b4c3
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 .
20 #pragma once
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sdbc/XCloseable.hpp>
26 #include <com/sun/star/sdbc/XResultSet.hpp>
27 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
28 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
29 #include <com/sun/star/sdbc/XRow.hpp>
30 #include <com/sun/star/ucb/XContentAccess.hpp>
31 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
32 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
33 #include <com/sun/star/ucb/ListAction.hpp>
34 #include <comphelper/multiinterfacecontainer3.hxx>
35 #include <comphelper/multiinterfacecontainer4.hxx>
36 #include <comphelper/interfacecontainer3.hxx>
37 #include <comphelper/interfacecontainer4.hxx>
38 #include <cppuhelper/implbase.hxx>
39 #include <rtl/ref.hxx>
40 #include <deque>
41 #include <memory>
44 struct SortInfo;
45 struct SortListData;
46 class SRSPropertySetInfo;
49 class SortedEntryList
51 std::deque < std::unique_ptr<SortListData> > maData;
53 public:
54 SortedEntryList();
55 ~SortedEntryList();
57 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
59 void Clear();
60 void Insert( std::unique_ptr<SortListData> pEntry, sal_Int32 nPos );
61 std::unique_ptr<SortListData> Remove( sal_Int32 nPos );
62 SortListData* GetData( sal_Int32 nPos );
63 void Move( sal_Int32 nOldPos, sal_Int32 nNewPos );
65 sal_Int32 operator [] ( sal_Int32 nPos ) const;
69 class EventList
71 std::deque <css::ucb::ListAction > maData;
73 public:
74 EventList(){}
76 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
78 void AddEvent( sal_IntPtr nType, sal_Int32 nPos );
79 void Insert( const css::ucb::ListAction& rAction ) { maData.push_back( rAction ); }
80 void Clear();
81 css::ucb::ListAction& GetAction( sal_Int32 nIndex ) { return maData[ nIndex ]; }
85 inline constexpr OUString RESULTSET_SERVICE_NAME = u"com.sun.star.ucb.SortedResultSet"_ustr;
88 class SortedResultSet: public cppu::WeakImplHelper <
89 css::lang::XServiceInfo,
90 css::lang::XComponent,
91 css::ucb::XContentAccess,
92 css::sdbc::XResultSet,
93 css::sdbc::XRow,
94 css::sdbc::XCloseable,
95 css::sdbc::XResultSetMetaDataSupplier,
96 css::beans::XPropertySet >
98 comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maDisposeEventListeners;
99 comphelper::OMultiTypeInterfaceContainerHelperVar4<OUString, css::beans::XPropertyChangeListener> maPropChangeListeners;
100 comphelper::OMultiTypeInterfaceContainerHelperVar4<OUString, css::beans::XVetoableChangeListener> maVetoChangeListeners;
102 css::uno::Reference < css::sdbc::XResultSet > mxOriginal;
103 css::uno::Reference < css::sdbc::XResultSet > mxOther;
105 rtl::Reference<SRSPropertySetInfo> mpPropSetInfo;
106 SortInfo* mpSortInfo;
107 std::mutex maMutex;
108 SortedEntryList maS2O; // maps the sorted entries to the original ones
109 std::deque<sal_IntPtr> m_O2S; /// maps the original Entries to the sorted ones
110 std::deque<SortListData*> m_ModList; /// keeps track of modified entries
111 sal_Int32 mnLastSort; // index of the last sorted entry;
112 sal_Int32 mnCurEntry; // index of the current entry
113 sal_Int32 mnCount; // total count of the elements
114 bool mbIsCopy;
117 private:
118 /// @throws css::sdbc::SQLException
119 /// @throws css::uno::RuntimeException
120 sal_Int32 FindPos( SortListData const *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd );
121 /// @throws css::sdbc::SQLException
122 /// @throws css::uno::RuntimeException
123 sal_Int32 Compare( SortListData const *pOne,
124 SortListData const *pTwo );
125 void BuildSortInfo( const css::uno::Reference< css::sdbc::XResultSet >& aResult,
126 const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
127 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
128 /// @throws css::sdbc::SQLException
129 /// @throws css::uno::RuntimeException
130 static sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
131 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
132 sal_Int32 nIndexOne, sal_Int32 nIndexTwo,
133 SortInfo const * pSortInfo );
134 /// @throws css::sdbc::SQLException
135 /// @throws css::uno::RuntimeException
136 sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
137 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
138 sal_Int32 nIndexOne, sal_Int32 nIndexTwo );
139 void PropertyChangedImpl(std::unique_lock<std::mutex>& rGuard, const css::beans::PropertyChangeEvent& rEvt);
141 public:
142 SortedResultSet( css::uno::Reference< css::sdbc::XResultSet > const & aResult );
143 virtual ~SortedResultSet() override;
145 sal_Int32 GetCount() const { return mnCount; }
147 void CopyData( SortedResultSet* pSource );
148 void Initialize( const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
149 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
150 void CheckProperties( sal_Int32 nOldCount, bool bWasFinal );
152 void InsertNew( sal_Int32 nPos, sal_Int32 nCount );
153 void SetChanged( sal_Int32 nPos, sal_Int32 nCount );
154 void Remove( sal_Int32 nPos, sal_Int32 nCount, EventList *pList );
155 void Move( sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset );
157 void ResortModified( EventList* pList );
158 void ResortNew( EventList* pList );
160 // XServiceInfo
161 virtual OUString SAL_CALL getImplementationName() override;
162 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
163 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
165 // XComponent
166 virtual void SAL_CALL
167 dispose() override;
169 virtual void SAL_CALL
170 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
172 virtual void SAL_CALL
173 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
175 // XContentAccess
176 virtual OUString SAL_CALL
177 queryContentIdentifierString() override;
178 virtual css::uno::Reference<
179 css::ucb::XContentIdentifier > SAL_CALL
180 queryContentIdentifier() override;
181 virtual css::uno::Reference<
182 css::ucb::XContent > SAL_CALL
183 queryContent() override;
185 // XResultSet
186 virtual sal_Bool SAL_CALL
187 next() override;
188 virtual sal_Bool SAL_CALL
189 isBeforeFirst() override;
190 virtual sal_Bool SAL_CALL
191 isAfterLast() override;
192 virtual sal_Bool SAL_CALL
193 isFirst() override;
194 virtual sal_Bool SAL_CALL
195 isLast() override;
196 virtual void SAL_CALL
197 beforeFirst() override;
198 virtual void SAL_CALL
199 afterLast() override;
200 virtual sal_Bool SAL_CALL
201 first() override;
202 virtual sal_Bool SAL_CALL
203 last() override;
204 virtual sal_Int32 SAL_CALL
205 getRow() override;
206 virtual sal_Bool SAL_CALL
207 absolute( sal_Int32 row ) override;
208 virtual sal_Bool SAL_CALL
209 relative( sal_Int32 rows ) override;
210 virtual sal_Bool SAL_CALL
211 previous() override;
212 virtual void SAL_CALL
213 refreshRow() override;
214 virtual sal_Bool SAL_CALL
215 rowUpdated() override;
216 virtual sal_Bool SAL_CALL
217 rowInserted() override;
218 virtual sal_Bool SAL_CALL
219 rowDeleted() override;
220 virtual css::uno::Reference<
221 css::uno::XInterface > SAL_CALL
222 getStatement() override;
224 // XRow
225 virtual sal_Bool SAL_CALL
226 wasNull() override;
228 virtual OUString SAL_CALL
229 getString( sal_Int32 columnIndex ) override;
231 virtual sal_Bool SAL_CALL
232 getBoolean( sal_Int32 columnIndex ) override;
234 virtual sal_Int8 SAL_CALL
235 getByte( sal_Int32 columnIndex ) override;
237 virtual sal_Int16 SAL_CALL
238 getShort( sal_Int32 columnIndex ) override;
240 virtual sal_Int32 SAL_CALL
241 getInt( sal_Int32 columnIndex ) override;
243 virtual sal_Int64 SAL_CALL
244 getLong( sal_Int32 columnIndex ) override;
246 virtual float SAL_CALL
247 getFloat( sal_Int32 columnIndex ) override;
249 virtual double SAL_CALL
250 getDouble( sal_Int32 columnIndex ) override;
252 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
253 getBytes( sal_Int32 columnIndex ) override;
255 virtual css::util::Date SAL_CALL
256 getDate( sal_Int32 columnIndex ) override;
258 virtual css::util::Time SAL_CALL
259 getTime( sal_Int32 columnIndex ) override;
261 virtual css::util::DateTime SAL_CALL
262 getTimestamp( sal_Int32 columnIndex ) override;
264 virtual css::uno::Reference<
265 css::io::XInputStream > SAL_CALL
266 getBinaryStream( sal_Int32 columnIndex ) override;
268 virtual css::uno::Reference<
269 css::io::XInputStream > SAL_CALL
270 getCharacterStream( sal_Int32 columnIndex ) override;
272 virtual css::uno::Any SAL_CALL
273 getObject( sal_Int32 columnIndex,
274 const css::uno::Reference<
275 css::container::XNameAccess >& typeMap ) override;
276 virtual css::uno::Reference<
277 css::sdbc::XRef > SAL_CALL
278 getRef( sal_Int32 columnIndex ) override;
279 virtual css::uno::Reference<
280 css::sdbc::XBlob > SAL_CALL
281 getBlob( sal_Int32 columnIndex ) override;
282 virtual css::uno::Reference<
283 css::sdbc::XClob > SAL_CALL
284 getClob( sal_Int32 columnIndex ) override;
285 virtual css::uno::Reference<
286 css::sdbc::XArray > SAL_CALL
287 getArray( sal_Int32 columnIndex ) override;
289 // XCloseable
290 virtual void SAL_CALL
291 close() override;
293 // XResultSetMetaDataSupplier
294 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
295 getMetaData() override;
298 // XPropertySet
299 virtual css::uno::Reference<
300 css::beans::XPropertySetInfo > SAL_CALL
301 getPropertySetInfo() override;
303 virtual void SAL_CALL
304 setPropertyValue( const OUString& PropertyName,
305 const css::uno::Any& Value ) override;
307 virtual css::uno::Any SAL_CALL
308 getPropertyValue( const OUString& PropertyName ) override;
310 virtual void SAL_CALL
311 addPropertyChangeListener( const OUString& PropertyName,
312 const css::uno::Reference<
313 css::beans::XPropertyChangeListener >& Listener ) override;
315 virtual void SAL_CALL
316 removePropertyChangeListener( const OUString& PropertyName,
317 const css::uno::Reference<
318 css::beans::XPropertyChangeListener >& Listener ) override;
320 virtual void SAL_CALL
321 addVetoableChangeListener( const OUString& PropertyName,
322 const css::uno::Reference<
323 css::beans::XVetoableChangeListener >& Listener ) override;
325 virtual void SAL_CALL
326 removeVetoableChangeListener( const OUString& PropertyName,
327 const css::uno::Reference<
328 css::beans::XVetoableChangeListener >& aListener ) override;
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */