LibreOffice Module sw (master)  1
index.hxx
Go to the documentation of this file.
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 INCLUDED_SW_INC_INDEX_HXX
20 #define INCLUDED_SW_INC_INDEX_HXX
21 
22 #include <sal/types.h>
23 #include "swdllapi.h"
24 
25 #include <iostream>
26 
27 class SwIndexReg;
28 struct SwPosition;
29 
30 namespace sw::mark { class IMark; }
31 
34 {
35 private:
36  friend class SwIndexReg;
37 
38  sal_Int32 m_nIndex;
40  // doubly linked list of Indexes registered at m_pIndexReg
43 
46 
47  SwIndex& ChgValue( const SwIndex& rIdx, sal_Int32 nNewValue );
48  void Init(sal_Int32 const nIdx);
49  void Remove();
50 
51 public:
52  explicit SwIndex(SwIndexReg *const pReg, sal_Int32 const nIdx = 0);
53  SwIndex( const SwIndex & );
54  SwIndex( const SwIndex &, short nDiff );
55  ~SwIndex() { Remove(); }
56 
57  SwIndex& operator=( sal_Int32 const );
58  SwIndex& operator=( const SwIndex & );
59 
60  sal_Int32 operator++();
61  sal_Int32 operator--();
62  sal_Int32 operator--(int);
63 
64  sal_Int32 operator+=( sal_Int32 const );
65  sal_Int32 operator-=( sal_Int32 const );
66 
67  bool operator< ( const SwIndex& ) const;
68  bool operator<=( const SwIndex& ) const;
69  bool operator> ( const SwIndex& ) const;
70  bool operator>=( const SwIndex& ) const;
71 
72  bool operator< ( sal_Int32 const nVal ) const { return m_nIndex < nVal; }
73  bool operator<=( sal_Int32 const nVal ) const { return m_nIndex <= nVal; }
74  bool operator> ( sal_Int32 const nVal ) const { return m_nIndex > nVal; }
75  bool operator>=( sal_Int32 const nVal ) const { return m_nIndex >= nVal; }
76  bool operator==( sal_Int32 const nVal ) const { return m_nIndex == nVal; }
77  bool operator!=( sal_Int32 const nVal ) const { return m_nIndex != nVal; }
78 
79  bool operator==( const SwIndex& rSwIndex ) const
80  {
81  return (m_nIndex == rSwIndex.m_nIndex)
82  && (m_pIndexReg == rSwIndex.m_pIndexReg);
83  }
84 
85  bool operator!=( const SwIndex& rSwIndex ) const
86  {
87  return (m_nIndex != rSwIndex.m_nIndex)
88  || (m_pIndexReg != rSwIndex.m_pIndexReg);
89  }
90 
91  sal_Int32 GetIndex() const { return m_nIndex; }
92 
93  // Assignments without creating a temporary object.
94  SwIndex &Assign(SwIndexReg *, sal_Int32);
95 
96  // Returns pointer to IndexArray (for RTTI at SwIndexReg).
97  const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
98  const SwIndex* GetNext() const { return m_pNext; }
99 
100  const sw::mark::IMark* GetMark() const { return m_pMark; }
101  void SetMark(const sw::mark::IMark* pMark);
102 };
103 
104 SW_DLLPUBLIC std::ostream& operator <<(std::ostream& s, const SwIndex& index);
105 
107 {
108  friend class SwIndex;
109  friend bool sw_PosOk(const SwPosition & aPos);
110 
111  const SwIndex * m_pFirst;
112  const SwIndex * m_pLast;
113 
114 protected:
115  virtual void Update( SwIndex const & rPos, const sal_Int32 nChangeLen,
116  const bool bNegative = false, const bool bDelete = false );
117 
118  bool HasAnyIndex() const { return nullptr != m_pFirst; }
119 
120 public:
121  SwIndexReg();
122  virtual ~SwIndexReg();
123 
124  void MoveTo( SwIndexReg& rArr );
125  const SwIndex* GetFirstIndex() const { return m_pFirst; }
126 };
127 
128 #ifndef DBG_UTIL
129 
130 inline sal_Int32 SwIndex::operator++()
131 {
132  return ChgValue( *this, m_nIndex+1 ).m_nIndex;
133 }
134 
135 inline sal_Int32 SwIndex::operator--()
136 {
137  return ChgValue( *this, m_nIndex-1 ).m_nIndex;
138 }
139 
140 inline sal_Int32 SwIndex::operator--(int)
141 {
142  sal_Int32 const nOldIndex = m_nIndex;
143  ChgValue( *this, m_nIndex-1 );
144  return nOldIndex;
145 }
146 
147 inline sal_Int32 SwIndex::operator+=( sal_Int32 const nVal )
148 {
149  return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
150 }
151 
152 inline sal_Int32 SwIndex::operator-=( sal_Int32 const nVal )
153 {
154  return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
155 }
156 
157 inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
158 {
159  return m_nIndex < rIndex.m_nIndex;
160 }
161 
162 inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
163 {
164  return m_nIndex <= rIndex.m_nIndex;
165 }
166 
167 inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
168 {
169  return m_nIndex > rIndex.m_nIndex;
170 }
171 
172 inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
173 {
174  return m_nIndex >= rIndex.m_nIndex;
175 }
176 
177 inline SwIndex& SwIndex::operator= ( sal_Int32 const nVal )
178 {
179  if (m_nIndex != nVal)
180  {
181  ChgValue( *this, nVal );
182  }
183  return *this;
184 }
185 
186 #endif // ifndef DBG_UTIL
187 
188 #endif
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:128
sal_Int32 operator--()
Definition: index.cxx:327
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
Marks a position in the document model.
Definition: pam.hxx:35
void Init()
friend class SwIndexReg
Definition: index.hxx:36
SwIndex * m_pPrev
Definition: index.hxx:42
bool operator<=(const SwIndex &) const
Definition: index.cxx:355
SwIndex * m_pNext
Definition: index.hxx:41
timeval & operator-=(timeval &t1, const timeval &t2)
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
SwIndex & ChgValue(const SwIndex &rIdx, sal_Int32 nNewValue)
Definition: index.cxx:79
sal_Int32 m_nIndex
Definition: index.hxx:38
SotClipboardFormatId & operator++(SotClipboardFormatId &eFormat)
sal_Int32 operator++()
Definition: index.cxx:308
const SwIndex * GetNext() const
Definition: index.hxx:98
bool operator<=(sal_Int32 const nVal) const
Definition: index.hxx:73
SwIndexReg * m_pIndexReg
Definition: index.hxx:39
const SwIndex * m_pLast
Definition: index.hxx:112
bool operator<(const SwIndex &) const
Definition: index.cxx:348
sal_Int32 operator-=(sal_Int32 const )
Definition: index.cxx:341
Marks a character position inside a document model node.
Definition: index.hxx:33
bool operator==(const SwIndex &rSwIndex) const
Definition: index.hxx:79
bool operator!=(sal_Int32 const nVal) const
Definition: index.hxx:77
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
bool operator!=(const SwIndex &rSwIndex) const
Definition: index.hxx:85
#define SAL_WARN_UNUSED
friend class SwIndex
Definition: index.hxx:108
bool operator==(sal_Int32 const nVal) const
Definition: index.hxx:76
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwIndex &index)
Definition: index.cxx:386
sal_Int32 GetIndex() const
Definition: index.hxx:91
bool operator>=(sal_Int32 const nVal) const
Definition: index.hxx:75
SwIndex & operator=(sal_Int32 const )
Definition: index.cxx:376
tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
bool operator>(const SwIndex &) const
Definition: index.cxx:362
const sw::mark::IMark * GetMark() const
Definition: index.hxx:100
const SwIndex * GetFirstIndex() const
Definition: index.hxx:125
bool HasAnyIndex() const
Definition: index.hxx:118
const sw::mark::IMark * m_pMark
Pointer to a mark that owns this position to allow fast lookup of marks of an SwIndexReg.
Definition: index.hxx:45
~SwIndex()
Definition: index.hxx:55
const SwIndexReg * GetIdxReg() const
Definition: index.hxx:97
bool sw_PosOk(const SwPosition &aPos)
Checks if a position is valid.
Definition: crsrsh.cxx:3544
const SwIndex * m_pFirst
Definition: index.hxx:111
bool operator>=(const SwIndex &) const
Definition: index.cxx:369
sal_Int32 operator+=(sal_Int32 const )
Definition: index.cxx:334