bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / sorter / sortresult.hxx
blobbbef157df5d0e697ea65a1e487a9524ef3fd3ca7
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 <cppuhelper/implbase.hxx>
35 #include <rtl/ref.hxx>
36 #include <deque>
37 #include <memory>
39 namespace comphelper {
40 class OInterfaceContainerHelper2;
44 struct SortInfo;
45 struct SortListData;
46 class SRSPropertySetInfo;
47 class PropertyChangeListeners_Impl;
50 class SortedEntryList
52 std::deque < std::unique_ptr<SortListData> > maData;
54 public:
55 SortedEntryList();
56 ~SortedEntryList();
58 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
60 void Clear();
61 void Insert( std::unique_ptr<SortListData> pEntry, sal_Int32 nPos );
62 std::unique_ptr<SortListData> Remove( sal_Int32 nPos );
63 SortListData* GetData( sal_Int32 nPos );
64 void Move( sal_Int32 nOldPos, sal_Int32 nNewPos );
66 sal_Int32 operator [] ( sal_Int32 nPos ) const;
70 class EventList
72 std::deque <css::ucb::ListAction > maData;
74 public:
75 EventList(){}
77 sal_uInt32 Count() { return static_cast<sal_uInt32>(maData.size()); }
79 void AddEvent( sal_IntPtr nType, sal_Int32 nPos );
80 void Insert( const css::ucb::ListAction& rAction ) { maData.push_back( rAction ); }
81 void Clear();
82 css::ucb::ListAction& GetAction( sal_Int32 nIndex ) { return maData[ nIndex ]; }
86 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
89 class SortedResultSet: public cppu::WeakImplHelper <
90 css::lang::XServiceInfo,
91 css::lang::XComponent,
92 css::ucb::XContentAccess,
93 css::sdbc::XResultSet,
94 css::sdbc::XRow,
95 css::sdbc::XCloseable,
96 css::sdbc::XResultSetMetaDataSupplier,
97 css::beans::XPropertySet >
99 comphelper::OInterfaceContainerHelper2 *mpDisposeEventListeners;
100 std::unique_ptr<PropertyChangeListeners_Impl> mpPropChangeListeners;
101 std::unique_ptr<PropertyChangeListeners_Impl> mpVetoChangeListeners;
103 css::uno::Reference < css::sdbc::XResultSet > mxOriginal;
104 css::uno::Reference < css::sdbc::XResultSet > mxOther;
106 rtl::Reference<SRSPropertySetInfo> mpPropSetInfo;
107 SortInfo* mpSortInfo;
108 osl::Mutex maMutex;
109 SortedEntryList maS2O; // maps the sorted entries to the original ones
110 std::deque<sal_IntPtr> m_O2S; /// maps the original Entries to the sorted ones
111 std::deque<SortListData*> m_ModList; /// keeps track of modified entries
112 sal_Int32 mnLastSort; // index of the last sorted entry;
113 sal_Int32 mnCurEntry; // index of the current entry
114 sal_Int32 mnCount; // total count of the elements
115 bool mbIsCopy;
118 private:
119 /// @throws css::sdbc::SQLException
120 /// @throws css::uno::RuntimeException
121 sal_Int32 FindPos( SortListData const *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd );
122 /// @throws css::sdbc::SQLException
123 /// @throws css::uno::RuntimeException
124 sal_Int32 Compare( SortListData const *pOne,
125 SortListData const *pTwo );
126 void BuildSortInfo( const css::uno::Reference< css::sdbc::XResultSet >& aResult,
127 const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
128 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
129 /// @throws css::sdbc::SQLException
130 /// @throws css::uno::RuntimeException
131 static sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
132 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
133 sal_Int32 nIndexOne, sal_Int32 nIndexTwo,
134 SortInfo const * pSortInfo );
135 /// @throws css::sdbc::SQLException
136 /// @throws css::uno::RuntimeException
137 sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
138 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
139 sal_Int32 nIndexOne, sal_Int32 nIndexTwo );
140 void PropertyChanged( const css::beans::PropertyChangeEvent& rEvt );
142 public:
143 SortedResultSet( css::uno::Reference< css::sdbc::XResultSet > const & aResult );
144 virtual ~SortedResultSet() override;
146 sal_Int32 GetCount() const { return mnCount; }
148 void CopyData( SortedResultSet* pSource );
149 void Initialize( const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
150 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
151 void CheckProperties( sal_Int32 nOldCount, bool bWasFinal );
153 void InsertNew( sal_Int32 nPos, sal_Int32 nCount );
154 void SetChanged( sal_Int32 nPos, sal_Int32 nCount );
155 void Remove( sal_Int32 nPos, sal_Int32 nCount, EventList *pList );
156 void Move( sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset );
158 void ResortModified( EventList* pList );
159 void ResortNew( EventList* pList );
161 // XServiceInfo
162 virtual OUString SAL_CALL getImplementationName() override;
163 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
164 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
166 // XComponent
167 virtual void SAL_CALL
168 dispose() override;
170 virtual void SAL_CALL
171 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
173 virtual void SAL_CALL
174 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
176 // XContentAccess
177 virtual OUString SAL_CALL
178 queryContentIdentifierString() override;
179 virtual css::uno::Reference<
180 css::ucb::XContentIdentifier > SAL_CALL
181 queryContentIdentifier() override;
182 virtual css::uno::Reference<
183 css::ucb::XContent > SAL_CALL
184 queryContent() override;
186 // XResultSet
187 virtual sal_Bool SAL_CALL
188 next() override;
189 virtual sal_Bool SAL_CALL
190 isBeforeFirst() override;
191 virtual sal_Bool SAL_CALL
192 isAfterLast() override;
193 virtual sal_Bool SAL_CALL
194 isFirst() override;
195 virtual sal_Bool SAL_CALL
196 isLast() override;
197 virtual void SAL_CALL
198 beforeFirst() override;
199 virtual void SAL_CALL
200 afterLast() override;
201 virtual sal_Bool SAL_CALL
202 first() override;
203 virtual sal_Bool SAL_CALL
204 last() override;
205 virtual sal_Int32 SAL_CALL
206 getRow() override;
207 virtual sal_Bool SAL_CALL
208 absolute( sal_Int32 row ) override;
209 virtual sal_Bool SAL_CALL
210 relative( sal_Int32 rows ) override;
211 virtual sal_Bool SAL_CALL
212 previous() override;
213 virtual void SAL_CALL
214 refreshRow() override;
215 virtual sal_Bool SAL_CALL
216 rowUpdated() override;
217 virtual sal_Bool SAL_CALL
218 rowInserted() override;
219 virtual sal_Bool SAL_CALL
220 rowDeleted() override;
221 virtual css::uno::Reference<
222 css::uno::XInterface > SAL_CALL
223 getStatement() override;
225 // XRow
226 virtual sal_Bool SAL_CALL
227 wasNull() override;
229 virtual OUString SAL_CALL
230 getString( sal_Int32 columnIndex ) override;
232 virtual sal_Bool SAL_CALL
233 getBoolean( sal_Int32 columnIndex ) override;
235 virtual sal_Int8 SAL_CALL
236 getByte( sal_Int32 columnIndex ) override;
238 virtual sal_Int16 SAL_CALL
239 getShort( sal_Int32 columnIndex ) override;
241 virtual sal_Int32 SAL_CALL
242 getInt( sal_Int32 columnIndex ) override;
244 virtual sal_Int64 SAL_CALL
245 getLong( sal_Int32 columnIndex ) override;
247 virtual float SAL_CALL
248 getFloat( sal_Int32 columnIndex ) override;
250 virtual double SAL_CALL
251 getDouble( sal_Int32 columnIndex ) override;
253 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
254 getBytes( sal_Int32 columnIndex ) override;
256 virtual css::util::Date SAL_CALL
257 getDate( sal_Int32 columnIndex ) override;
259 virtual css::util::Time SAL_CALL
260 getTime( sal_Int32 columnIndex ) override;
262 virtual css::util::DateTime SAL_CALL
263 getTimestamp( sal_Int32 columnIndex ) override;
265 virtual css::uno::Reference<
266 css::io::XInputStream > SAL_CALL
267 getBinaryStream( sal_Int32 columnIndex ) override;
269 virtual css::uno::Reference<
270 css::io::XInputStream > SAL_CALL
271 getCharacterStream( sal_Int32 columnIndex ) override;
273 virtual css::uno::Any SAL_CALL
274 getObject( sal_Int32 columnIndex,
275 const css::uno::Reference<
276 css::container::XNameAccess >& typeMap ) override;
277 virtual css::uno::Reference<
278 css::sdbc::XRef > SAL_CALL
279 getRef( sal_Int32 columnIndex ) override;
280 virtual css::uno::Reference<
281 css::sdbc::XBlob > SAL_CALL
282 getBlob( sal_Int32 columnIndex ) override;
283 virtual css::uno::Reference<
284 css::sdbc::XClob > SAL_CALL
285 getClob( sal_Int32 columnIndex ) override;
286 virtual css::uno::Reference<
287 css::sdbc::XArray > SAL_CALL
288 getArray( sal_Int32 columnIndex ) override;
290 // XCloseable
291 virtual void SAL_CALL
292 close() override;
294 // XResultSetMetaDataSupplier
295 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
296 getMetaData() override;
299 // XPropertySet
300 virtual css::uno::Reference<
301 css::beans::XPropertySetInfo > SAL_CALL
302 getPropertySetInfo() override;
304 virtual void SAL_CALL
305 setPropertyValue( const OUString& PropertyName,
306 const css::uno::Any& Value ) override;
308 virtual css::uno::Any SAL_CALL
309 getPropertyValue( const OUString& PropertyName ) override;
311 virtual void SAL_CALL
312 addPropertyChangeListener( const OUString& PropertyName,
313 const css::uno::Reference<
314 css::beans::XPropertyChangeListener >& Listener ) override;
316 virtual void SAL_CALL
317 removePropertyChangeListener( const OUString& PropertyName,
318 const css::uno::Reference<
319 css::beans::XPropertyChangeListener >& Listener ) override;
321 virtual void SAL_CALL
322 addVetoableChangeListener( const OUString& PropertyName,
323 const css::uno::Reference<
324 css::beans::XVetoableChangeListener >& Listener ) override;
326 virtual void SAL_CALL
327 removeVetoableChangeListener( const OUString& PropertyName,
328 const css::uno::Reference<
329 css::beans::XVetoableChangeListener >& aListener ) override;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */