LCOV - code coverage report
Current view: top level - include/tools - multisel.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 15 86.7 %
Date: 2015-06-13 12:38:46 Functions: 11 12 91.7 %
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             : #ifndef INCLUDED_TOOLS_MULTISEL_HXX
      20             : #define INCLUDED_TOOLS_MULTISEL_HXX
      21             : 
      22             : #include <tools/toolsdllapi.h>
      23             : #include <tools/gen.hxx>
      24             : #include <rtl/ustring.hxx>
      25             : 
      26             : #include <vector>
      27             : #include <set>
      28             : 
      29             : typedef ::std::vector< Range* > ImpSelList;
      30             : 
      31             : #define SFX_ENDOFSELECTION      ULONG_MAX
      32             : 
      33             : class TOOLS_DLLPUBLIC MultiSelection
      34             : {
      35             : private:
      36             :     ImpSelList      aSels;      // array of SV-selections
      37             :     Range           aTotRange;  // total range of indexes
      38             :     sal_uIntPtr     nCurSubSel; // index in aSels of current selected index
      39             :     long            nCurIndex;  // current selected entry
      40             :     sal_uIntPtr     nSelCount;  // number of selected indexes
      41             :     bool            bInverseCur;// inverse cursor
      42             :     bool            bCurValid;  // are nCurIndex and nCurSubSel valid
      43             :     bool            bSelectNew; // auto-select newly inserted indexes
      44             : 
      45             :     TOOLS_DLLPRIVATE void           ImplClear();
      46             :     TOOLS_DLLPRIVATE size_t         ImplFindSubSelection( long nIndex ) const;
      47             :     TOOLS_DLLPRIVATE bool           ImplMergeSubSelections( size_t nPos1, size_t nPos2 );
      48             :     TOOLS_DLLPRIVATE long           ImplFwdUnselected();
      49             : 
      50             : public:
      51             :                     MultiSelection();
      52             :                     MultiSelection( const MultiSelection& rOrig );
      53             :                     MultiSelection( const Range& rRange );
      54             :                     ~MultiSelection();
      55             : 
      56             :     MultiSelection& operator= ( const MultiSelection& rOrig );
      57             :     bool            operator== ( MultiSelection& rOrig );
      58             :     bool            operator!= ( MultiSelection& rOrig )
      59             :                         { return !operator==( rOrig ); }
      60             :     bool            operator !() const
      61             :                         { return nSelCount == 0; }
      62             : 
      63             :     void            SelectAll( bool bSelect = true );
      64             :     bool            Select( long nIndex, bool bSelect = true );
      65             :     void            Select( const Range& rIndexRange, bool bSelect = true );
      66             :     bool            IsSelected( long nIndex ) const;
      67           0 :     bool            IsAllSelected() const
      68           0 :                         { return nSelCount == sal_uIntPtr(aTotRange.Len()); }
      69         237 :     long            GetSelectCount() const { return nSelCount; }
      70             : 
      71             :     void            SetTotalRange( const Range& rTotRange );
      72             :     void            Insert( long nIndex, long nCount = 1 );
      73             :     void            Remove( long nIndex );
      74             : 
      75          43 :     const Range&    GetTotalRange() const { return aTotRange; }
      76             :     bool            IsCurValid() const { return bCurValid; }
      77             :     long            GetCurSelected() const { return nCurIndex; }
      78             :     long            FirstSelected( bool bInverse = false );
      79             :     long            LastSelected();
      80             :     long            NextSelected();
      81             : 
      82      207899 :     size_t          GetRangeCount() const { return aSels.size(); }
      83         739 :     const Range&    GetRange( size_t nRange ) const { return *aSels[nRange]; }
      84             : };
      85             : 
      86          84 : class TOOLS_DLLPUBLIC StringRangeEnumerator
      87             : {
      88             :     struct Range
      89             :     {
      90             :         sal_Int32   nFirst;
      91             :         sal_Int32   nLast;
      92             : 
      93             :         Range() : nFirst( -1 ), nLast( -1 ) {}
      94          84 :         Range( sal_Int32 i_nFirst, sal_Int32 i_nLast ) : nFirst( i_nFirst ), nLast( i_nLast ) {}
      95             :     };
      96             :     std::vector< StringRangeEnumerator::Range >            maSequence;
      97             :     sal_Int32                                              mnCount;
      98             :     sal_Int32                                              mnMin;
      99             :     sal_Int32                                              mnMax;
     100             :     sal_Int32                                              mnOffset;
     101             :     bool                                                   mbValidInput;
     102             : 
     103             :     bool setRange( const OUString& i_rNewRange, bool i_bStrict = false );
     104             :     bool insertRange( sal_Int32 nFirst, sal_Int32 nLast, bool bSequence, bool bMayAdjust );
     105             :     bool insertJoinedRanges( const std::vector< sal_Int32 >& rNumbers, bool i_bStrict );
     106             :     bool checkValue( sal_Int32, const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const;
     107             : public:
     108             :     class TOOLS_DLLPUBLIC Iterator
     109             :     {
     110             :         const StringRangeEnumerator*      pEnumerator;
     111             :         const std::set< sal_Int32 >*      pPossibleValues;
     112             :         sal_Int32                         nRangeIndex;
     113             :         sal_Int32                         nCurrent;
     114             : 
     115             :         friend class StringRangeEnumerator;
     116         169 :         Iterator( const StringRangeEnumerator* i_pEnum,
     117             :                   const std::set< sal_Int32 >* i_pPossibleValues,
     118             :                   sal_Int32 i_nRange,
     119             :                   sal_Int32 i_nCurrent )
     120             :         : pEnumerator( i_pEnum ), pPossibleValues( i_pPossibleValues )
     121         169 :         , nRangeIndex( i_nRange ), nCurrent( i_nCurrent ) {}
     122             : 
     123             :     public:
     124             :         Iterator() : pEnumerator( NULL ), pPossibleValues( NULL ), nRangeIndex( -1 ), nCurrent( -1 ) {}
     125             :         Iterator& operator++();
     126         179 :         sal_Int32 operator*() const { return nCurrent;}
     127             :         bool operator==(const Iterator&) const;
     128         262 :         bool operator!=(const Iterator& i_rComp) const
     129         262 :         { return ! (*this == i_rComp); }
     130             :     };
     131             : 
     132             :     friend class StringRangeEnumerator::Iterator;
     133             : 
     134             :     StringRangeEnumerator( const OUString& i_rInput,
     135             :                            sal_Int32 i_nMinNumber,
     136             :                            sal_Int32 i_nMaxNumber,
     137             :                            sal_Int32 i_nLogicalOffset = -1
     138             :                            );
     139             : 
     140          10 :     sal_Int32 size() const { return mnCount; }
     141             :     Iterator begin( const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const;
     142             :     Iterator end( const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const;
     143             : 
     144           1 :     bool isValidInput() const { return mbValidInput; }
     145             :     bool hasValue( sal_Int32 nValue, const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const;
     146             : 
     147             :     /**
     148             :     i_rPageRange:     the string to be changed into a sequence of numbers
     149             :                       valid format example "5-3,9,9,7-8" ; instead of ',' ';' or ' ' are allowed as well
     150             :     o_rPageVector:    the output sequence of numbers
     151             :     i_nLogicalOffset: an offset to be applied to each number in the string before inserting it in the resulting sequence
     152             :                       example: a user enters page numbers from 1 to n (since that is logical)
     153             :                                of course usable page numbers in code would start from 0 and end at n-1
     154             :                                so the logical offset would be -1
     155             :     i_nMinNumber:     the minimum allowed number
     156             :     i_nMaxNumber:     the maximum allowed number
     157             : 
     158             :     @returns: true if the input string was valid, o_rPageVector will contain the resulting sequence
     159             :               false if the input string was invalid, o_rPageVector will contain
     160             :                     the sequence that parser is able to extract
     161             : 
     162             :     behavior:
     163             :     - only non-negative sequence numbers are allowed
     164             :     - only non-negative values in the input string are allowed
     165             :     - the string "-3" means the sequence i_nMinNumber to 3
     166             :     - the string "3-" means the sequence 3 to i_nMaxNumber
     167             :     - the string "-" means the sequence i_nMinNumber to i_nMaxNumber
     168             :     - single number that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be ignored
     169             :     - range that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be adjusted
     170             :     */
     171             :     static bool getRangesFromString( const OUString& i_rPageRange,
     172             :                                      std::vector< sal_Int32 >& o_rPageVector,
     173             :                                      sal_Int32 i_nMinNumber,
     174             :                                      sal_Int32 i_nMaxNumber,
     175             :                                      sal_Int32 i_nLogicalOffset = -1,
     176             :                                      std::set< sal_Int32 >* i_pPossibleValues = NULL
     177             :                                     );
     178             : };
     179             : 
     180             : #endif
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11