LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/ucb/source/sorter - sortresult.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 19 42.1 %
Date: 2013-07-09 Functions: 8 18 44.4 %
Legend: Lines: hit not hit

          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             : #ifndef _SORTRESULT_HXX
      21             : #define _SORTRESULT_HXX
      22             : 
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/lang/XTypeProvider.hpp>
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : #include <com/sun/star/lang/XComponent.hpp>
      28             : #include <com/sun/star/sdbc/XCloseable.hpp>
      29             : #include <com/sun/star/sdbc/XResultSet.hpp>
      30             : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
      31             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      32             : #include <com/sun/star/sdbc/XRow.hpp>
      33             : #include <com/sun/star/ucb/XContentAccess.hpp>
      34             : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
      35             : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
      36             : #include <com/sun/star/ucb/ListAction.hpp>
      37             : #include <cppuhelper/weak.hxx>
      38             : #include <osl/mutex.hxx>
      39             : 
      40             : #include <deque>
      41             : #include <ucbhelper/macros.hxx>
      42             : 
      43             : namespace cppu {
      44             :     class OInterfaceContainerHelper;
      45             : }
      46             : 
      47             : //-----------------------------------------------------------------------------
      48             : struct  SortInfo;
      49             : struct  SortListData;
      50             : class   SRSPropertySetInfo;
      51             : class   PropertyChangeListeners_Impl;
      52             : 
      53             : //-----------------------------------------------------------------------------
      54             : class SortedEntryList
      55             : {
      56             :     std::deque < SortListData* > maData;
      57             : 
      58             : public:
      59          76 :                          SortedEntryList(){}
      60          76 :                         ~SortedEntryList(){ Clear(); }
      61             : 
      62         696 :     sal_uInt32          Count() const { return (sal_uInt32) maData.size(); }
      63             : 
      64             :     void                Clear();
      65             :     void                Insert( SortListData *pEntry, sal_IntPtr nPos );
      66             :     SortListData*       Remove( sal_IntPtr nPos );
      67             :     SortListData*       GetData( sal_IntPtr nPos );
      68             : 
      69             :     sal_IntPtr                operator [] ( sal_IntPtr nPos ) const;
      70             : };
      71             : 
      72             : //-----------------------------------------------------------------------------
      73             : 
      74             : class EventList
      75             : {
      76             :     std::deque < css::ucb::ListAction* > maData;
      77             : 
      78             : public:
      79          76 :                      EventList(){}
      80          76 :                     ~EventList(){ Clear(); }
      81             : 
      82           0 :     sal_uInt32      Count() { return (sal_uInt32) maData.size(); }
      83             : 
      84             :     void            AddEvent( sal_IntPtr nType, sal_IntPtr nPos, sal_IntPtr nCount );
      85           0 :     void            Insert( css::ucb::ListAction *pAction ) { maData.push_back( pAction ); }
      86             :     void            Clear();
      87           0 :     css::ucb::ListAction*     GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ]; }
      88             : };
      89             : 
      90             : //-----------------------------------------------------------------------------
      91             : 
      92             : class SimpleList
      93             : {
      94             :     std::deque < void* > maData;
      95             : 
      96             : public:
      97         152 :                      SimpleList(){}
      98         152 :                     ~SimpleList(){ Clear(); }
      99             : 
     100           0 :     sal_uInt32      Count() { return (sal_uInt32) maData.size(); }
     101         228 :     void            Clear() { maData.clear(); }
     102             : 
     103             :     void            Remove( sal_uInt32 nPos );
     104             :     void            Remove( void* pData );
     105             : 
     106           0 :     void            Append( void* pData )
     107           0 :                         { maData.push_back( pData ); }
     108             :     void            Insert( void* pData, sal_uInt32 nPos );
     109             :     void*           GetObject( sal_uInt32 nPos ) const;
     110             :     void            Replace( void* pData, sal_uInt32 nPos );
     111             : };
     112             : 
     113             : //-----------------------------------------------------------------------------
     114             : 
     115             : #define RESULTSET_SERVICE_NAME  "com.sun.star.ucb.SortedResultSet"
     116             : 
     117             : //-----------------------------------------------------------------------------
     118             : 
     119             : class SortedResultSet:
     120             :                 public cppu::OWeakObject,
     121             :                 public css::lang::XTypeProvider,
     122             :                 public css::lang::XServiceInfo,
     123             :                 public css::lang::XComponent,
     124             :                 public css::ucb::XContentAccess,
     125             :                 public css::sdbc::XResultSet,
     126             :                 public css::sdbc::XRow,
     127             :                 public css::sdbc::XCloseable,
     128             :                 public css::sdbc::XResultSetMetaDataSupplier,
     129             :                 public css::beans::XPropertySet
     130             : {
     131             :     cppu::OInterfaceContainerHelper *mpDisposeEventListeners;
     132             :     PropertyChangeListeners_Impl    *mpPropChangeListeners;
     133             :     PropertyChangeListeners_Impl    *mpVetoChangeListeners;
     134             : 
     135             :     css::uno::Reference < css::sdbc::XResultSet >            mxOriginal;
     136             :     css::uno::Reference < css::sdbc::XResultSet >            mxOther;
     137             : 
     138             :     SRSPropertySetInfo* mpPropSetInfo;
     139             :     SortInfo*           mpSortInfo;
     140             :     osl::Mutex          maMutex;
     141             :     SortedEntryList     maS2O;          // maps the sorted entries to the original ones
     142             :     SimpleList          maO2S;          // maps the original Entries to the sorted ones
     143             :     SimpleList          maModList;      // keeps track of modified entries
     144             :     sal_IntPtr                mnLastSort;     // index of the last sorted entry;
     145             :     sal_IntPtr                mnCurEntry;     // index of the current entry
     146             :     sal_IntPtr                mnCount;        // total count of the elements
     147             :     sal_Bool            mbIsCopy;
     148             : 
     149             : 
     150             : private:
     151             : 
     152             :     sal_IntPtr                FindPos( SortListData *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd )
     153             :                             throw( css::sdbc::SQLException, css::uno::RuntimeException );
     154             :     sal_IntPtr                Compare( SortListData *pOne,
     155             :                                  SortListData *pTwo )
     156             :                             throw( css::sdbc::SQLException, css::uno::RuntimeException );
     157             :     void                BuildSortInfo( css::uno::Reference< css::sdbc::XResultSet > aResult,
     158             :                                        const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
     159             :                                        const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
     160             :     sal_IntPtr                CompareImpl( css::uno::Reference < css::sdbc::XResultSet > xResultOne,
     161             :                                      css::uno::Reference < css::sdbc::XResultSet > xResultTwo,
     162             :                                      sal_IntPtr nIndexOne, sal_IntPtr nIndexTwo,
     163             :                                      SortInfo* pSortInfo )
     164             :                             throw( css::sdbc::SQLException, css::uno::RuntimeException );
     165             :     sal_IntPtr                CompareImpl( css::uno::Reference < css::sdbc::XResultSet > xResultOne,
     166             :                                      css::uno::Reference < css::sdbc::XResultSet > xResultTwo,
     167             :                                      sal_IntPtr nIndexOne, sal_IntPtr nIndexTwo )
     168             :                             throw( css::sdbc::SQLException, css::uno::RuntimeException );
     169             :     void                PropertyChanged( const css::beans::PropertyChangeEvent& rEvt );
     170             : 
     171             : public:
     172             :                         SortedResultSet( css::uno::Reference< css::sdbc::XResultSet > aResult );
     173             :                         ~SortedResultSet();
     174             : 
     175           0 :     const SortedEntryList*      GetS2OList() const { return &maS2O; }
     176           0 :     const SimpleList*           GetO2SList() const { return &maO2S; }
     177           0 :     css::uno::Reference < css::sdbc::XResultSet >    GetResultSet() const { return mxOriginal; }
     178           0 :     SortInfo*                   GetSortInfo() const { return mpSortInfo; }
     179           0 :     sal_IntPtr                        GetCount() const { return mnCount; }
     180             : 
     181             :     void                CopyData( SortedResultSet* pSource );
     182             :     void                Initialize( const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
     183             :                                     const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
     184             :     void                CheckProperties( sal_IntPtr nOldCount, sal_Bool bWasFinal );
     185             : 
     186             :     void                InsertNew( sal_IntPtr nPos, sal_IntPtr nCount );
     187             :     void                SetChanged( sal_IntPtr nPos, sal_IntPtr nCount );
     188             :     void                Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pList );
     189             :     void                Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffset );
     190             : 
     191             :     void                ResortModified( EventList* pList );
     192             :     void                ResortNew( EventList* pList );
     193             : 
     194             :     // XInterface
     195             :     XINTERFACE_DECL()
     196             : 
     197             :     // XTypeProvider
     198             :     XTYPEPROVIDER_DECL()
     199             : 
     200             :     // XServiceInfo
     201             :     XSERVICEINFO_NOFACTORY_DECL()
     202             : 
     203             :     // XComponent
     204             :     virtual void SAL_CALL
     205             :     dispose() throw( css::uno::RuntimeException );
     206             : 
     207             :     virtual void SAL_CALL
     208             :     addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener )
     209             :         throw( css::uno::RuntimeException );
     210             : 
     211             :     virtual void SAL_CALL
     212             :     removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener )
     213             :         throw( css::uno::RuntimeException );
     214             : 
     215             :     // XContentAccess
     216             :     virtual OUString SAL_CALL
     217             :     queryContentIdentifierString()
     218             :         throw( css::uno::RuntimeException );
     219             :     virtual css::uno::Reference<
     220             :                 css::ucb::XContentIdentifier > SAL_CALL
     221             :     queryContentIdentifier()
     222             :         throw( css::uno::RuntimeException );
     223             :     virtual css::uno::Reference<
     224             :                 css::ucb::XContent > SAL_CALL
     225             :     queryContent()
     226             :         throw( css::uno::RuntimeException );
     227             : 
     228             :     // XResultSet
     229             :     virtual sal_Bool SAL_CALL
     230             :     next()
     231             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     232             :     virtual sal_Bool SAL_CALL
     233             :     isBeforeFirst()
     234             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     235             :     virtual sal_Bool SAL_CALL
     236             :     isAfterLast()
     237             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     238             :     virtual sal_Bool SAL_CALL
     239             :     isFirst()
     240             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     241             :     virtual sal_Bool SAL_CALL
     242             :     isLast()
     243             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     244             :     virtual void SAL_CALL
     245             :     beforeFirst()
     246             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     247             :     virtual void SAL_CALL
     248             :     afterLast()
     249             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     250             :     virtual sal_Bool SAL_CALL
     251             :     first()
     252             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     253             :     virtual sal_Bool SAL_CALL
     254             :     last()
     255             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     256             :     virtual sal_Int32 SAL_CALL
     257             :     getRow()
     258             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     259             :     virtual sal_Bool SAL_CALL
     260             :     absolute( sal_Int32 row )
     261             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     262             :     virtual sal_Bool SAL_CALL
     263             :     relative( sal_Int32 rows )
     264             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     265             :     virtual sal_Bool SAL_CALL
     266             :     previous()
     267             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     268             :     virtual void SAL_CALL
     269             :     refreshRow()
     270             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     271             :     virtual sal_Bool SAL_CALL
     272             :     rowUpdated()
     273             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     274             :     virtual sal_Bool SAL_CALL
     275             :     rowInserted()
     276             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     277             :     virtual sal_Bool SAL_CALL
     278             :     rowDeleted()
     279             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     280             :     virtual css::uno::Reference<
     281             :                 css::uno::XInterface > SAL_CALL
     282             :     getStatement()
     283             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     284             : 
     285             :     // XRow
     286             :     virtual sal_Bool SAL_CALL
     287             :     wasNull() throw( css::sdbc::SQLException, css::uno::RuntimeException );
     288             : 
     289             :     virtual OUString SAL_CALL
     290             :     getString( sal_Int32 columnIndex )
     291             :     throw( css::sdbc::SQLException, css::uno::RuntimeException );
     292             : 
     293             :     virtual sal_Bool SAL_CALL
     294             :     getBoolean( sal_Int32 columnIndex )
     295             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     296             : 
     297             :     virtual sal_Int8 SAL_CALL
     298             :     getByte( sal_Int32 columnIndex )
     299             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     300             : 
     301             :     virtual sal_Int16 SAL_CALL
     302             :     getShort( sal_Int32 columnIndex )
     303             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     304             : 
     305             :     virtual sal_Int32 SAL_CALL
     306             :     getInt( sal_Int32 columnIndex )
     307             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     308             : 
     309             :     virtual sal_Int64 SAL_CALL
     310             :     getLong( sal_Int32 columnIndex )
     311             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     312             : 
     313             :     virtual float SAL_CALL
     314             :     getFloat( sal_Int32 columnIndex )
     315             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     316             : 
     317             :     virtual double SAL_CALL
     318             :     getDouble( sal_Int32 columnIndex )
     319             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     320             : 
     321             :     virtual css::uno::Sequence< sal_Int8 > SAL_CALL
     322             :     getBytes( sal_Int32 columnIndex )
     323             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     324             : 
     325             :     virtual css::util::Date SAL_CALL
     326             :     getDate( sal_Int32 columnIndex )
     327             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     328             : 
     329             :     virtual css::util::Time SAL_CALL
     330             :     getTime( sal_Int32 columnIndex )
     331             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     332             : 
     333             :     virtual css::util::DateTime SAL_CALL
     334             :     getTimestamp( sal_Int32 columnIndex )
     335             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     336             : 
     337             :     virtual css::uno::Reference<
     338             :                 css::io::XInputStream > SAL_CALL
     339             :     getBinaryStream( sal_Int32 columnIndex )
     340             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     341             : 
     342             :     virtual css::uno::Reference<
     343             :                 css::io::XInputStream > SAL_CALL
     344             :     getCharacterStream( sal_Int32 columnIndex )
     345             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     346             : 
     347             :     virtual css::uno::Any SAL_CALL
     348             :     getObject( sal_Int32 columnIndex,
     349             :                const css::uno::Reference<
     350             :                    css::container::XNameAccess >& typeMap )
     351             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     352             :     virtual css::uno::Reference<
     353             :                 css::sdbc::XRef > SAL_CALL
     354             :     getRef( sal_Int32 columnIndex )
     355             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     356             :     virtual css::uno::Reference<
     357             :                 css::sdbc::XBlob > SAL_CALL
     358             :     getBlob( sal_Int32 columnIndex )
     359             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     360             :     virtual css::uno::Reference<
     361             :                 css::sdbc::XClob > SAL_CALL
     362             :     getClob( sal_Int32 columnIndex )
     363             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     364             :     virtual css::uno::Reference<
     365             :                 css::sdbc::XArray > SAL_CALL
     366             :     getArray( sal_Int32 columnIndex )
     367             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     368             : 
     369             :     // XCloseable
     370             :     virtual void SAL_CALL
     371             :     close()
     372             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     373             : 
     374             :     // XResultSetMetaDataSupplier
     375             :     virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
     376             :     getMetaData()
     377             :         throw( css::sdbc::SQLException, css::uno::RuntimeException );
     378             : 
     379             : 
     380             :     // XPropertySet
     381             :     virtual css::uno::Reference<
     382             :                 css::beans::XPropertySetInfo > SAL_CALL
     383             :     getPropertySetInfo()
     384             :         throw( css::uno::RuntimeException );
     385             : 
     386             :     virtual void SAL_CALL
     387             :     setPropertyValue( const OUString& PropertyName,
     388             :                       const css::uno::Any& Value )
     389             :         throw( css::beans::UnknownPropertyException,
     390             :                css::beans::PropertyVetoException,
     391             :                css::lang::IllegalArgumentException,
     392             :                css::lang::WrappedTargetException,
     393             :                css::uno::RuntimeException );
     394             : 
     395             :     virtual css::uno::Any SAL_CALL
     396             :     getPropertyValue( const OUString& PropertyName )
     397             :         throw( css::beans::UnknownPropertyException,
     398             :         css::lang::WrappedTargetException,
     399             :         css::uno::RuntimeException );
     400             : 
     401             :     virtual void SAL_CALL
     402             :     addPropertyChangeListener( const OUString& PropertyName,
     403             :                                const css::uno::Reference<
     404             :                                        css::beans::XPropertyChangeListener >& Listener )
     405             :         throw( css::beans::UnknownPropertyException,
     406             :                css::lang::WrappedTargetException,
     407             :                css::uno::RuntimeException );
     408             : 
     409             :     virtual void SAL_CALL
     410             :     removePropertyChangeListener( const OUString& PropertyName,
     411             :                                   const css::uno::Reference<
     412             :                                       css::beans::XPropertyChangeListener >& Listener )
     413             :         throw( css::beans::UnknownPropertyException,
     414             :                css::lang::WrappedTargetException,
     415             :                css::uno::RuntimeException );
     416             : 
     417             :     virtual void SAL_CALL
     418             :     addVetoableChangeListener( const OUString& PropertyName,
     419             :                                const css::uno::Reference<
     420             :                                        css::beans::XVetoableChangeListener >& Listener )
     421             :         throw( css::beans::UnknownPropertyException,
     422             :                css::lang::WrappedTargetException,
     423             :                css::uno::RuntimeException );
     424             : 
     425             :     virtual void SAL_CALL
     426             :     removeVetoableChangeListener( const OUString& PropertyName,
     427             :                                   const css::uno::Reference<
     428             :                                       css::beans::XVetoableChangeListener >& aListener )
     429             :         throw( css::beans::UnknownPropertyException,
     430             :                css::lang::WrappedTargetException,
     431             :                css::uno::RuntimeException );
     432             : };
     433             : 
     434             : #endif
     435             : 
     436             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10