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