xref: /aoo4110/main/sc/source/ui/inc/csvsplits.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // ============================================================================
25 
26 #ifndef _SC_CSVSPLITS_HXX
27 #define _SC_CSVSPLITS_HXX
28 
29 #include <sal/types.h>
30 
31 #include <vector>
32 
33 
34 // ============================================================================
35 
36 /** Constant for an invalid vector index. */
37 const sal_uInt32 CSV_VEC_NOTFOUND   = SAL_MAX_UINT32;
38 /** Constant for an invalid ruler position. */
39 const sal_Int32 CSV_POS_INVALID     = -1;
40 
41 
42 // ----------------------------------------------------------------------------
43 
44 /** A vector of column splits that supports inserting, removing and moving splits. */
45 class ScCsvSplits
46 {
47 private:
48     typedef ::std::vector< sal_Int32 >      ScSplitVector;
49     typedef ScSplitVector::iterator         iterator;
50     typedef ScSplitVector::const_iterator   const_iterator;
51 
52     ScSplitVector               maVec;          /// The split containter.
53 
54 public:
55     // *** access by position *** ---------------------------------------------
56 
57     /** Inserts a new split at position nPos into the vector.
58         @return  true = split inserted (nPos was valid and empty). */
59     bool                        Insert( sal_Int32 nPos );
60     /** Removes a split by position.
61         @return  true = split found and removed. */
62     bool                        Remove( sal_Int32 nPos );
63     /** Removes a range of splits in the given position range. */
64     void                        RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd );
65     /** Removes all elements from the vector. */
66     void                        Clear();
67 
68     /** Returns true if at position nPos is a split. */
69     bool                        HasSplit( sal_Int32 nPos ) const;
70 
71     // *** access by index *** ------------------------------------------------
72 
73     /** Searches for a split at position nPos.
74         @return  the vector index of the split. */
75     sal_uInt32                  GetIndex( sal_Int32 nPos ) const;
76     /** Returns index of the first split greater than or equal to nPos. */
77     sal_uInt32                  LowerBound( sal_Int32 nPos ) const;
78     /** Returns index of the last split less than or equal to nPos. */
79     sal_uInt32                  UpperBound( sal_Int32 nPos ) const;
80 
81     /** Returns the number of splits. */
Count() const82     inline sal_uInt32           Count() const
83                                     { return maVec.size(); }
84     /** Returns the position of the specified split. */
85     sal_Int32                   GetPos( sal_uInt32 nIndex ) const;
86     /** Returns the position of the specified split. */
operator [](sal_uInt32 nIndex) const87     inline sal_Int32            operator[]( sal_uInt32 nIndex ) const
88                                     { return GetPos( nIndex ); }
89 
90 private:
91     /** Returns the vector index of an iterator. */
92     sal_uInt32                  GetIterIndex( const_iterator aIter ) const;
93 };
94 
95 
96 // ============================================================================
97 
98 #endif
99 
100