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