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 :
20 : // ============================================================================
21 :
22 : #ifndef _SC_CSVSPLITS_HXX
23 : #define _SC_CSVSPLITS_HXX
24 :
25 : #include <sal/types.h>
26 :
27 : #include <vector>
28 :
29 :
30 : // ============================================================================
31 :
32 : /** Constant for an invalid vector index. */
33 : const sal_uInt32 CSV_VEC_NOTFOUND = SAL_MAX_UINT32;
34 : /** Constant for an invalid ruler position. */
35 : const sal_Int32 CSV_POS_INVALID = -1;
36 :
37 :
38 : // ----------------------------------------------------------------------------
39 :
40 : /** A vector of column splits that supports inserting, removing and moving splits. */
41 0 : class ScCsvSplits
42 : {
43 : private:
44 : typedef ::std::vector< sal_Int32 > ScSplitVector;
45 : typedef ScSplitVector::iterator iterator;
46 : typedef ScSplitVector::const_iterator const_iterator;
47 :
48 : ScSplitVector maVec; /// The split containter.
49 :
50 : public:
51 : // *** access by position *** ---------------------------------------------
52 :
53 : /** Inserts a new split at position nPos into the vector.
54 : @return true = split inserted (nPos was valid and empty). */
55 : bool Insert( sal_Int32 nPos );
56 : /** Removes a split by position.
57 : @return true = split found and removed. */
58 : bool Remove( sal_Int32 nPos );
59 : /** Removes a range of splits in the given position range. */
60 : void RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd );
61 : /** Removes all elements from the vector. */
62 : void Clear();
63 :
64 : /** Returns true if at position nPos is a split. */
65 : bool HasSplit( sal_Int32 nPos ) const;
66 :
67 : // *** access by index *** ------------------------------------------------
68 :
69 : /** Searches for a split at position nPos.
70 : @return the vector index of the split. */
71 : sal_uInt32 GetIndex( sal_Int32 nPos ) const;
72 : /** Returns index of the first split greater than or equal to nPos. */
73 : sal_uInt32 LowerBound( sal_Int32 nPos ) const;
74 : /** Returns index of the last split less than or equal to nPos. */
75 : sal_uInt32 UpperBound( sal_Int32 nPos ) const;
76 :
77 : /** Returns the number of splits. */
78 0 : inline sal_uInt32 Count() const
79 0 : { return maVec.size(); }
80 : /** Returns the position of the specified split. */
81 : sal_Int32 GetPos( sal_uInt32 nIndex ) const;
82 : /** Returns the position of the specified split. */
83 0 : inline sal_Int32 operator[]( sal_uInt32 nIndex ) const
84 0 : { return GetPos( nIndex ); }
85 :
86 : private:
87 : /** Returns the vector index of an iterator. */
88 : sal_uInt32 GetIterIndex( const_iterator aIter ) const;
89 : };
90 :
91 :
92 : // ============================================================================
93 :
94 : #endif
95 :
96 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|