2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2010-12-15 09:13:59 +01:00
|
|
|
#ifndef SW_NDINDEX_HXX
|
|
|
|
#define SW_NDINDEX_HXX
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
2010-12-15 09:13:59 +01:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <tools/solar.h>
|
|
|
|
|
2010-12-15 09:13:59 +01:00
|
|
|
#include <node.hxx>
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
class SwNode;
|
|
|
|
class SwNodes;
|
|
|
|
|
2012-02-15 11:36:56 +01:00
|
|
|
/// Marks a node in the document model.
|
2009-01-05 14:06:42 +00:00
|
|
|
class SW_DLLPUBLIC SwNodeIndex
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
friend void SwNodes::RegisterIndex( SwNodeIndex& );
|
|
|
|
friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
|
2011-01-17 15:06:54 +01:00
|
|
|
friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
SwNode* pNd;
|
|
|
|
SwNodeIndex *pNext, *pPrev;
|
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
void Remove();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
// These are not allowed!
|
2011-01-17 15:06:54 +01:00
|
|
|
SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
|
2000-09-18 16:15:01 +00:00
|
|
|
SwNodeIndex( SwNodes& rNds, int nIdx );
|
|
|
|
|
|
|
|
public:
|
2011-01-17 15:06:54 +01:00
|
|
|
SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
|
2000-09-18 16:15:01 +00:00
|
|
|
SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
|
|
|
|
SwNodeIndex( const SwNode&, long nDiff = 0 );
|
|
|
|
~SwNodeIndex() { Remove(); }
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong operator++();
|
|
|
|
inline sal_uLong operator--();
|
|
|
|
inline sal_uLong operator++(int);
|
|
|
|
inline sal_uLong operator--(int);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong operator+=( sal_uLong );
|
|
|
|
inline sal_uLong operator-=( sal_uLong );
|
|
|
|
inline sal_uLong operator+=( const SwNodeIndex& );
|
|
|
|
inline sal_uLong operator-=( const SwNodeIndex& );
|
|
|
|
|
|
|
|
inline sal_Bool operator< ( const SwNodeIndex& ) const;
|
|
|
|
inline sal_Bool operator<=( const SwNodeIndex& ) const;
|
|
|
|
inline sal_Bool operator> ( const SwNodeIndex& ) const;
|
|
|
|
inline sal_Bool operator>=( const SwNodeIndex& ) const;
|
|
|
|
inline sal_Bool operator==( const SwNodeIndex& ) const;
|
|
|
|
inline sal_Bool operator!=( const SwNodeIndex& ) const;
|
|
|
|
|
|
|
|
inline sal_Bool operator< ( sal_uLong nWert ) const;
|
|
|
|
inline sal_Bool operator<=( sal_uLong nWert ) const;
|
|
|
|
inline sal_Bool operator> ( sal_uLong nWert ) const;
|
|
|
|
inline sal_Bool operator>=( sal_uLong nWert ) const;
|
|
|
|
inline sal_Bool operator==( sal_uLong nWert ) const;
|
|
|
|
inline sal_Bool operator!=( sal_uLong nWert ) const;
|
|
|
|
|
|
|
|
inline SwNodeIndex& operator=( sal_uLong );
|
2000-09-18 16:15:01 +00:00
|
|
|
SwNodeIndex& operator=( const SwNodeIndex& );
|
|
|
|
SwNodeIndex& operator=( const SwNode& );
|
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
// Return value of index as sal_uLong.
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong GetIndex() const;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
// Enables assignments without creation of a temporary object.
|
2011-01-17 15:06:54 +01:00
|
|
|
SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
|
2000-09-18 16:15:01 +00:00
|
|
|
SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
|
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
// Gets pointer on NodesArray.
|
2000-09-18 16:15:01 +00:00
|
|
|
inline const SwNodes& GetNodes() const;
|
|
|
|
inline SwNodes& GetNodes();
|
|
|
|
|
|
|
|
SwNode& GetNode() const { return *pNd; }
|
|
|
|
};
|
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
// SwRange
|
|
|
|
|
2009-01-05 14:06:42 +00:00
|
|
|
class SW_DLLPUBLIC SwNodeRange
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SwNodeIndex aStart;
|
|
|
|
SwNodeIndex aEnd;
|
|
|
|
|
|
|
|
SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
|
|
|
|
SwNodeRange( const SwNodeRange &rRange );
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
|
2000-09-18 16:15:01 +00:00
|
|
|
SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
|
|
|
|
const SwNodeIndex& rE, long nEndDiff = 0 );
|
|
|
|
SwNodeRange( const SwNode& rS, long nSttDiff,
|
|
|
|
const SwNode& rE, long nEndDiff = 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-21 02:20:33 +01:00
|
|
|
// For inlines node.hxx is needed which in turn needs this one.
|
|
|
|
// Therefore all inlines accessing pNd are implemented here.
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::GetIndex() const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex();
|
|
|
|
}
|
|
|
|
inline const SwNodes& SwNodeIndex::GetNodes() const
|
|
|
|
{
|
|
|
|
return pNd->GetNodes();
|
|
|
|
}
|
|
|
|
inline SwNodes& SwNodeIndex::GetNodes()
|
|
|
|
{
|
|
|
|
return pNd->GetNodes();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() < nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() <= nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() > nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() >= nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() == nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() != nWert;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() < rIndex.GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() <= rIndex.GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() > rIndex.GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd->GetIndex() >= rIndex.GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd == rIdx.pNd;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return pNd != rIdx.pNd;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator++()
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator--()
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator++(int)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nOldIndex = pNd->GetIndex();
|
2000-09-18 16:15:01 +00:00
|
|
|
pNd = GetNodes()[ nOldIndex + 1 ];
|
|
|
|
return nOldIndex;
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator--(int)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nOldIndex = pNd->GetIndex();
|
2000-09-18 16:15:01 +00:00
|
|
|
pNd = GetNodes()[ nOldIndex - 1 ];
|
|
|
|
return nOldIndex;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
pNd = GetNodes()[ nWert ];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|