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

Generated by: LCOV version 1.10