xref: /aoo41x/main/sc/source/ui/inc/csvsplits.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // ============================================================================
29 
30 #ifndef _SC_CSVSPLITS_HXX
31 #define _SC_CSVSPLITS_HXX
32 
33 #include <sal/types.h>
34 
35 #include <vector>
36 
37 
38 // ============================================================================
39 
40 /** Constant for an invalid vector index. */
41 const sal_uInt32 CSV_VEC_NOTFOUND   = SAL_MAX_UINT32;
42 /** Constant for an invalid ruler position. */
43 const sal_Int32 CSV_POS_INVALID     = -1;
44 
45 
46 // ----------------------------------------------------------------------------
47 
48 /** A vector of column splits that supports inserting, removing and moving splits. */
49 class ScCsvSplits
50 {
51 private:
52     typedef ::std::vector< sal_Int32 >      ScSplitVector;
53     typedef ScSplitVector::iterator         iterator;
54     typedef ScSplitVector::const_iterator   const_iterator;
55 
56     ScSplitVector               maVec;          /// The split containter.
57 
58 public:
59     // *** access by position *** ---------------------------------------------
60 
61     /** Inserts a new split at position nPos into the vector.
62         @return  true = split inserted (nPos was valid and empty). */
63     bool                        Insert( sal_Int32 nPos );
64     /** Removes a split by position.
65         @return  true = split found and removed. */
66     bool                        Remove( sal_Int32 nPos );
67     /** Removes a range of splits in the given position range. */
68     void                        RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd );
69     /** Removes all elements from the vector. */
70     void                        Clear();
71 
72     /** Returns true if at position nPos is a split. */
73     bool                        HasSplit( sal_Int32 nPos ) const;
74 
75     // *** access by index *** ------------------------------------------------
76 
77     /** Searches for a split at position nPos.
78         @return  the vector index of the split. */
79     sal_uInt32                  GetIndex( sal_Int32 nPos ) const;
80     /** Returns index of the first split greater than or equal to nPos. */
81     sal_uInt32                  LowerBound( sal_Int32 nPos ) const;
82     /** Returns index of the last split less than or equal to nPos. */
83     sal_uInt32                  UpperBound( sal_Int32 nPos ) const;
84 
85     /** Returns the number of splits. */
86     inline sal_uInt32           Count() const
87                                     { return maVec.size(); }
88     /** Returns the position of the specified split. */
89     sal_Int32                   GetPos( sal_uInt32 nIndex ) const;
90     /** Returns the position of the specified split. */
91     inline sal_Int32            operator[]( sal_uInt32 nIndex ) const
92                                     { return GetPos( nIndex ); }
93 
94 private:
95     /** Returns the vector index of an iterator. */
96     sal_uInt32                  GetIterIndex( const_iterator aIter ) const;
97 };
98 
99 
100 // ============================================================================
101 
102 #endif
103 
104